From c2a9b677a2279ffdb6fb1a771897b3b0654e9dfc 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 and do not rely on using the system default compilers, and use the gcc and g++ compilers explicitly. --- modules/gmake/tests/cpp/test_tools.lua | 9 +++++++++ modules/gmake2/tests/test_gmake2_tools.lua | 9 +++++++++ src/tools/gcc.lua | 5 +---- tests/tools/test_gcc.lua | 15 ++++++++++++--- 4 files changed, 31 insertions(+), 7 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..789830c816 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -681,8 +681,5 @@ else version = "" end - 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 (cfg.gccprefix or "") .. gcc.tools[tool] .. version 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