Skip to content

Commit 9a70afe

Browse files
authored
Fix gmake action mixing up compilers from different toolsets. (#2240)
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.
1 parent 2ea527a commit 9a70afe

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

modules/gmake/tests/cpp/test_tools.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
function suite.usesCorrectTools()
3131
make.cppTools(cfg, p.tools.gcc)
3232
test.capture [[
33+
ifeq ($(origin CC), default)
34+
CC = gcc
35+
endif
36+
ifeq ($(origin CXX), default)
37+
CXX = g++
38+
endif
39+
ifeq ($(origin AR), default)
40+
AR = ar
41+
endif
3342
RESCOMP = windres
3443
]]
3544
end

modules/gmake2/tests/test_gmake2_tools.lua

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,34 @@
2828
-- Make sure that the correct tools are used.
2929
--
3030

31-
function suite.usesCorrectTools()
31+
function suite.usesCorrectTools_gcc()
3232
gmake2.cpp.tools(cfg, p.tools.gcc)
3333
test.capture [[
34+
ifeq ($(origin CC), default)
35+
CC = gcc
36+
endif
37+
ifeq ($(origin CXX), default)
38+
CXX = g++
39+
endif
40+
ifeq ($(origin AR), default)
41+
AR = ar
42+
endif
43+
RESCOMP = windres
44+
]]
45+
end
46+
47+
function suite.usesCorrectTools_clang()
48+
gmake2.cpp.tools(cfg, p.tools.clang)
49+
test.capture [[
50+
ifeq ($(origin CC), default)
51+
CC = clang
52+
endif
53+
ifeq ($(origin CXX), default)
54+
CXX = clang++
55+
endif
56+
ifeq ($(origin AR), default)
57+
AR = ar
58+
endif
3459
RESCOMP = windres
3560
]]
3661
end

src/tools/gcc.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,5 @@
681681
else
682682
version = ""
683683
end
684-
if ((cfg.gccprefix or version ~= "") and gcc.tools[tool]) or tool == "rc" then
685-
return (cfg.gccprefix or "") .. gcc.tools[tool] .. version
686-
end
687-
return nil
684+
return (cfg.gccprefix or "") .. gcc.tools[tool] .. version
688685
end

tests/tools/test_gcc.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@
3333

3434
function suite.tools_onDefaults()
3535
prepare()
36-
test.isnil(gcc.gettoolname(cfg, "cc"))
37-
test.isnil(gcc.gettoolname(cfg, "cxx"))
38-
test.isnil(gcc.gettoolname(cfg, "ar"))
36+
test.isequal("gcc", gcc.gettoolname(cfg, "cc"))
37+
test.isequal("g++", gcc.gettoolname(cfg, "cxx"))
38+
test.isequal("ar", gcc.gettoolname(cfg, "ar"))
39+
test.isequal("windres", gcc.gettoolname(cfg, "rc"))
40+
end
41+
42+
function suite.tools_withGcc()
43+
toolset "gcc"
44+
prepare()
45+
test.isequal("gcc", gcc.gettoolname(cfg, "cc"))
46+
test.isequal("g++", gcc.gettoolname(cfg, "cxx"))
47+
test.isequal("ar", gcc.gettoolname(cfg, "ar"))
3948
test.isequal("windres", gcc.gettoolname(cfg, "rc"))
4049
end
4150

0 commit comments

Comments
 (0)