Skip to content

Commit 2a02566

Browse files
authored
Make distinction between CC and CXX in the testsuite (#4637)
Clang makes a distinction between clang and clang++. In particular, clang++ will give a warning when it is passed .c source files; and the extra output warning text means that dmd testsuite output checking fails. The warning can be silenced (-Wno-deprecated) but then other tests will fail because #ifdef __cplusplus will be true, leading to header file import issues. Cherry-pick from dlang/dmd#16434 + extra LDC-specific changes
1 parent 49b3343 commit 2a02566

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

tests/dmd/dshell/cpp_header_gen.d

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import dshell;
44

55
int main()
66
{
7-
if (!CC.length)
7+
if (!CXX.length)
88
{
9-
writeln("CPP header generation test was skipped because $CC is empty!");
9+
writeln("CPP header generation test was skipped because $CXX is empty!");
1010
return DISABLED;
1111
}
1212
// DMC cannot compile the generated headers ...
1313
version (Windows)
1414
{
1515
import std.algorithm : canFind;
16-
if (CC.canFind("dmc"))
16+
if (CXX.canFind("dmc"))
1717
{
1818
writeln("CPP header generation test was skipped because DMC is not supported!");
1919
return DISABLED;
@@ -46,11 +46,11 @@ int main()
4646
else enum X86_Any = false;
4747

4848
version (Windows)
49-
run([CC, "/c", "/Fo" ~ Vars.CPP_OBJ, "/I" ~ OUTPUT_BASE, "/I" ~ EXTRA_FILES ~"/../../../../../dmd/root", Vars.SOURCE_DIR ~ "/app.cpp"]);
49+
run([CXX, "/c", "/Fo" ~ Vars.CPP_OBJ, "/I" ~ OUTPUT_BASE, "/I" ~ EXTRA_FILES ~"/../../../../../dmd/root", Vars.SOURCE_DIR ~ "/app.cpp"]);
5050
else static if (X86_Any)
51-
run("$CC -std=c++11 -m$MODEL -c -o $CPP_OBJ -I$OUTPUT_BASE -I$EXTRA_FILES/../../../../../dmd/root $SOURCE_DIR/app.cpp");
51+
run("$CXX -std=c++11 -m$MODEL -c -o $CPP_OBJ -I$OUTPUT_BASE -I$EXTRA_FILES/../../../../../dmd/root $SOURCE_DIR/app.cpp");
5252
else
53-
run("$CC -std=c++11 -c -o $CPP_OBJ -I$OUTPUT_BASE -I$EXTRA_FILES/../../../../../dmd/root $SOURCE_DIR/app.cpp");
53+
run("$CXX -std=c++11 -c -o $CPP_OBJ -I$OUTPUT_BASE -I$EXTRA_FILES/../../../../../dmd/root $SOURCE_DIR/app.cpp");
5454
run("$DMD -m$MODEL -of=$HEADER_EXE $LIB $CPP_OBJ");
5555
run("$HEADER_EXE");
5656

tests/dmd/dshell/dll_cxx.d

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import std.stdio;
44

55
int main()
66
{
7-
// Only run this test, if CC has been set.
8-
if (Vars.CC.empty)
7+
// Only run this test, if CXX has been set.
8+
if (Vars.CXX.empty)
99
return DISABLED;
1010

1111
version (Windows)
@@ -20,20 +20,20 @@ int main()
2020
Vars.set(`EXE_NAME`, `$OUTPUT_BASE${SEP}testdll$EXE`);
2121
Vars.set(`DLL`, `$OUTPUT_BASE${SEP}mydll$SOEXT`);
2222

23-
string[] dllCmd = [Vars.CC];
23+
string[] dllCmd = [Vars.CXX];
2424
string mainExtra;
2525
version (Windows)
2626
{
2727
Vars.set(`DLL_LIB`, `$OUTPUT_BASE${SEP}mydll.lib`);
2828
if (Vars.MODEL == "32omf")
2929
{
30-
// CC should be dmc for win32omf.
30+
// CXX should be dmc for win32omf.
3131
dllCmd ~= [`-mn`, `-L/implib:` ~ Vars.DLL_LIB, `-WD`, `-o` ~ Vars.DLL, `kernel32.lib`, `user32.lib`];
3232
mainExtra = `$DLL_LIB`;
3333
}
3434
else
3535
{
36-
// CC should be cl for win32mscoff.
36+
// CXX should be cl for win32mscoff.
3737
dllCmd ~= [`/LD`, `/nologo`, `/Fe` ~ Vars.DLL];
3838
mainExtra = `$DLL_LIB`;
3939
}

tests/dmd/tools/d_do_test.d

+32-12
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ void usage()
6262
~ " ARGS: set to execute all combinations of\n"
6363
~ " REQUIRED_ARGS: arguments always passed to the compiler\n"
6464
~ " DMD: compiler to use, ex: ../src/dmd (required)\n"
65-
~ " CC: C++ compiler to use, ex: dmc, g++\n"
65+
~ " CC: C compiler to use, ex: dmc, cc\n"
66+
~ " CXX: C++ compiler to use, ex: dmc, g++\n"
6667
~ " OS: windows, linux, freebsd, osx, netbsd, dragonflybsd\n"
6768
~ " RESULTS_DIR: base directory for test results\n"
6869
~ " MODEL: 32 or 64 (required)\n"
@@ -95,7 +96,7 @@ struct TestArgs
9596
bool link; /// `LINK`: force linking for `fail_compilation` & `compilable` tests
9697
bool clearDflags; /// `DFLAGS`: whether DFLAGS should be cleared before invoking dmd
9798
string executeArgs; /// `EXECUTE_ARGS`: arguments passed to the compiled executable (for `runnable[_cxx]`)
98-
string cxxflags; /// `CXXFLAGS`: arguments passed to $CC when compiling `EXTRA_CPP_SOURCES`
99+
string cxxflags; /// `CXXFLAGS`: arguments passed to $CXX when compiling `EXTRA_CPP_SOURCES`
99100
string[] sources; /// `EXTRA_SOURCES`: additional D sources (+ main source file)
100101
string[] compiledImports; /// `COMPILED_IMPORTS`: files compiled alongside the main source
101102
string[] cppSources; /// `EXTRA_CPP_SOURCES`: additional C++ sources
@@ -132,7 +133,8 @@ struct EnvData
132133
string exe; /// `EXE`: executable file extension (none or `.exe`)
133134
string os; /// `OS`: host operating system (`linux`, `windows`, ...)
134135
string compiler; /// `HOST_DMD`: host D compiler
135-
string ccompiler; /// `CC`: host C++ compiler
136+
string ccompiler; /// `CC`: host C compiler
137+
string cxxcompiler; /// `CXX`: host C++ compiler
136138
string model; /// `MODEL`: target model (`32` or `64`)
137139
string required_args; /// `REQUIRED_ARGS`: flags added to the tests `REQUIRED_ARGS` parameter
138140
string cxxCompatFlags; /// Additional flags passed to $(compiler) when `EXTRA_CPP_SOURCES` is present
@@ -174,6 +176,7 @@ immutable(EnvData) processEnvironment()
174176
envData.dmd = replace(envGetRequired("DMD"), "/", envData.sep);
175177
envData.compiler = "dmd"; //should be replaced for other compilers
176178
envData.ccompiler = environment.get("CC");
179+
envData.cxxcompiler = environment.get("CXX");
177180
envData.model = envGetRequired("MODEL");
178181
if (envData.os == "windows" && envData.model == "32")
179182
{
@@ -198,7 +201,7 @@ immutable(EnvData) processEnvironment()
198201
if (envData.ccompiler.empty)
199202
{
200203
if (envData.os != "windows")
201-
envData.ccompiler = "c++";
204+
envData.ccompiler = "cc";
202205
else if (envData.model == "32omf")
203206
envData.ccompiler = "dmc";
204207
else if (envData.model == "64")
@@ -207,7 +210,23 @@ immutable(EnvData) processEnvironment()
207210
envData.ccompiler = "cl";
208211
else
209212
{
210-
writeln("Unknown $OS$MODEL combination: ", envData.os, envData.model);
213+
writeln("Can't determine C compiler (CC). Unknown $OS$MODEL combination: ", envData.os, envData.model);
214+
throw new SilentQuit();
215+
}
216+
}
217+
if (envData.cxxcompiler.empty)
218+
{
219+
if (envData.os != "windows")
220+
envData.cxxcompiler = "c++";
221+
else if (envData.model == "32omf")
222+
envData.cxxcompiler = "dmc";
223+
else if (envData.model == "64")
224+
envData.cxxcompiler = "cl";
225+
else if (envData.model == "32mscoff")
226+
envData.cxxcompiler = "cl";
227+
else
228+
{
229+
writeln("Can't determine C++ compiler (CXX). Unknown $OS$MODEL combination: ", envData.os, envData.model);
211230
throw new SilentQuit();
212231
}
213232
}
@@ -1160,14 +1179,15 @@ unittest
11601179
* Returns: false if a compilation error occurred
11611180
*/
11621181
bool collectExtraSources (in string input_dir, in string output_dir, in string[] extraSources,
1163-
ref string[] sources, in EnvData envData, in string compiler,
1164-
const(char)[] cxxflags, ref File logfile, /*LDC*/ in bool objC = false)
1182+
ref string[] sources, in EnvData envData, in string ccompiler,
1183+
in string cxxcompiler, const(char)[] cxxflags, ref File logfile, /*LDC*/ in bool objC = false)
11651184
{
11661185
foreach (cur; extraSources)
11671186
{
11681187
auto curSrc = input_dir ~ envData.sep ~"extra-files" ~ envData.sep ~ cur;
11691188
auto curObj = output_dir ~ envData.sep ~ cur ~ envData.obj;
1170-
string command = quoteSpaces(compiler);
1189+
bool is_cpp_file = cur.extension() == ".cpp";
1190+
string command = quoteSpaces(is_cpp_file ? cxxcompiler : ccompiler);
11711191
if (envData.model == "32omf") // dmc.exe
11721192
{
11731193
command ~= " -c "~curSrc~" -o"~curObj;
@@ -1779,10 +1799,10 @@ int tryMain(string[] args)
17791799

17801800
if (
17811801
//prepare cpp extra sources
1782-
!collectExtraSources(input_dir, output_dir, testArgs.cppSources, testArgs.sources, envData, envData.ccompiler, testArgs.cxxflags, f) ||
1802+
!collectExtraSources(input_dir, output_dir, testArgs.cppSources, testArgs.sources, envData, envData.ccompiler, envData.cxxcompiler, testArgs.cxxflags, f) ||
17831803

17841804
//prepare objc extra sources
1785-
!collectExtraSources(input_dir, output_dir, testArgs.objcSources, testArgs.sources, envData, "clang", null, f, /*LDC, objC=*/true)
1805+
!collectExtraSources(input_dir, output_dir, testArgs.objcSources, testArgs.sources, envData, "clang", "clang++", null, f, /*LDC, objC=*/true)
17861806
)
17871807
{
17881808
writeln();
@@ -2245,9 +2265,9 @@ static this()
22452265
const runTest = [testScriptExe];
22462266
outfile.writeln("\n[RUN_TEST] ", escapeShellCommand(runTest));
22472267
outfile.flush();
2248-
// LDC: propagate C(++) compiler from envData as CC env var (required by cpp_header_gen test)
2268+
// LDC: propagate C(++) compiler from envData as CC/CXX env var (required by cpp_header_gen test)
22492269
version (LDC)
2250-
const string[string] runEnv = ["CC": envData.ccompiler];
2270+
const string[string] runEnv = ["CC": envData.ccompiler, "CXX": envData.cxxcompiler];
22512271
else
22522272
const string[string] runEnv = null;
22532273
auto runTestProc = std.process.spawnProcess(runTest, stdin, outfile, outfile, runEnv, keepFilesOpen);

tests/dmd/tools/dshell_prebuilt/dshell_prebuilt.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private alias requiredEnvVars = AliasSeq!(
5151
"BUILD_SHARED_LIBS" // LDC - passed through from CMake
5252
);
5353
private alias optionalEnvVars = AliasSeq!(
54-
"CC", "PIC_FLAG"
54+
"CC", "CXX", "PIC_FLAG"
5555
);
5656
private alias allVars = AliasSeq!(
5757
requiredEnvVars,

0 commit comments

Comments
 (0)