Skip to content

Commit

Permalink
Fix gmake action mixing up compilers from different toolsets.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tritao committed Sep 2, 2024
1 parent db072b4 commit c2a9b67
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
9 changes: 9 additions & 0 deletions modules/gmake/tests/cpp/test_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions modules/gmake2/tests/test_gmake2_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 12 additions & 3 deletions tests/tools/test_gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c2a9b67

Please sign in to comment.