From 14fd9d3ee2fab3394a3bdd5b3a4dafa7d2db8f82 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Sun, 1 Sep 2024 14:02:27 +0100 Subject: [PATCH] Fix gmake action mixing up compilers from different toolsets. Due to Make behavior, specifically its default values to the CC and CXX implicit rules, we could end up in a scenario where the gcc and clang compilers would be used in the same project. Be more explicit into using either the `cc` or `c++` system default compilers when no toolset is specified, and `gcc` and `g++` compilers when the `gcc` toolset is specified. --- modules/gmake/tests/cpp/test_tools.lua | 9 +++++++++ modules/gmake2/tests/test_gmake2_tools.lua | 9 +++++++++ src/tools/gcc.lua | 2 +- tests/tools/test_gcc.lua | 15 ++++++++++++--- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/modules/gmake/tests/cpp/test_tools.lua b/modules/gmake/tests/cpp/test_tools.lua index 6b5a083191..69e376674a 100644 --- a/modules/gmake/tests/cpp/test_tools.lua +++ b/modules/gmake/tests/cpp/test_tools.lua @@ -30,6 +30,15 @@ function suite.usesCorrectTools() make.cppTools(cfg, p.tools.gcc) test.capture [[ + ifeq ($(origin CC), default) + CC = gcc + endif + ifeq ($(origin CXX), default) + CXX = g++ + endif + ifeq ($(origin AR), default) + AR = ar + endif RESCOMP = windres ]] end diff --git a/modules/gmake2/tests/test_gmake2_tools.lua b/modules/gmake2/tests/test_gmake2_tools.lua index 9474176d32..01460a69a7 100644 --- a/modules/gmake2/tests/test_gmake2_tools.lua +++ b/modules/gmake2/tests/test_gmake2_tools.lua @@ -31,6 +31,15 @@ function suite.usesCorrectTools() gmake2.cpp.tools(cfg, p.tools.gcc) test.capture [[ +ifeq ($(origin CC), default) + CC = gcc +endif +ifeq ($(origin CXX), default) + CXX = g++ +endif +ifeq ($(origin AR), default) + AR = ar +endif RESCOMP = windres ]] end diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index e4aa12c2bb..9bac20ef2b 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -684,5 +684,5 @@ if ((cfg.gccprefix or version ~= "") and gcc.tools[tool]) or tool == "rc" then return (cfg.gccprefix or "") .. gcc.tools[tool] .. version end - return nil + return gcc.tools[tool] end diff --git a/tests/tools/test_gcc.lua b/tests/tools/test_gcc.lua index fcc085511d..0a875b6277 100644 --- a/tests/tools/test_gcc.lua +++ b/tests/tools/test_gcc.lua @@ -33,9 +33,18 @@ function suite.tools_onDefaults() prepare() - test.isnil(gcc.gettoolname(cfg, "cc")) - test.isnil(gcc.gettoolname(cfg, "cxx")) - test.isnil(gcc.gettoolname(cfg, "ar")) + test.isequal("gcc", gcc.gettoolname(cfg, "cc")) + test.isequal("g++", gcc.gettoolname(cfg, "cxx")) + test.isequal("ar", gcc.gettoolname(cfg, "ar")) + test.isequal("windres", gcc.gettoolname(cfg, "rc")) + end + + function suite.tools_withGcc() + toolset "gcc" + prepare() + test.isequal("gcc", gcc.gettoolname(cfg, "cc")) + test.isequal("g++", gcc.gettoolname(cfg, "cxx")) + test.isequal("ar", gcc.gettoolname(cfg, "ar")) test.isequal("windres", gcc.gettoolname(cfg, "rc")) end