From 6fbacaa5b2d7c4522925bea5776890139b68a8ea Mon Sep 17 00:00:00 2001 From: MoonlightSentinel Date: Fri, 4 Feb 2022 23:32:54 +0100 Subject: [PATCH 1/2] dshell: Flush output's before invoking subsequent programs Ensures that Phobos / LibC buffering doesn't mess with the output ordering as the executed program will flush when exiting --- test/tools/d_do_test.d | 4 +++- test/tools/dshell_prebuilt/dshell_prebuilt.d | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/tools/d_do_test.d b/test/tools/d_do_test.d index 737155618c1e..a2ccb1f90d89 100755 --- a/test/tools/d_do_test.d +++ b/test/tools/d_do_test.d @@ -2072,6 +2072,7 @@ static this() testScriptPath, ]; outfile.writeln("[COMPILE_TEST] ", escapeShellCommand(compile)); + outfile.flush(); // Note that spawnprocess closes the file, so it will need to be re-opened // below when we run the test auto compileProc = std.process.spawnProcess(compile, stdin, outfile, outfile, null, keepFilesOpen); @@ -2088,7 +2089,8 @@ static this() // { const runTest = [testScriptExe]; - outfile.writeln("[RUN_TEST] ", escapeShellCommand(runTest)); + outfile.writeln("\n[RUN_TEST] ", escapeShellCommand(runTest)); + outfile.flush(); auto runTestProc = std.process.spawnProcess(runTest, stdin, outfile, outfile, null, keepFilesOpen); const exitCode = wait(runTestProc); diff --git a/test/tools/dshell_prebuilt/dshell_prebuilt.d b/test/tools/dshell_prebuilt/dshell_prebuilt.d index 56c0a52acdaf..cc9b4211f248 100644 --- a/test/tools/dshell_prebuilt/dshell_prebuilt.d +++ b/test/tools/dshell_prebuilt/dshell_prebuilt.d @@ -169,8 +169,11 @@ auto tryRun(scope const(char[])[] args, File stdout = std.stdio.stdout, { std.stdio.stdout.write(" > ", stdout.name); } + // "Commit" all output from the tester std.stdio.stdout.writeln(); std.stdio.stdout.flush(); + std.stdio.stderr.writeln(); + std.stdio.stderr.flush(); auto proc = spawnProcess(args, stdin, stdout, stderr, env); return wait(proc); } From b1470acab83b9d7aca287629d7e1010d7e606f5c Mon Sep 17 00:00:00 2001 From: MoonlightSentinel Date: Fri, 4 Feb 2022 19:47:04 +0100 Subject: [PATCH 2/2] Adapt default `sc.ini` to MsCoff by default The old configuration still used OPTLINk for `-m32` which obviously doesn't support MsCoff files. Also added a test file that builds and executes a small program using the configurations in `ini` and `build.d` (as allmost all other tests run with `-conf=`). --- ini/windows/bin/sc.ini | 7 +- src/build.d | 3 + test/dshell/defaults.d | 78 ++++++++++++++++++++ test/dshell/extra-files/defaults/hello.d | 9 +++ test/tools/dshell_prebuilt/dshell_prebuilt.d | 1 + 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 test/dshell/defaults.d create mode 100644 test/dshell/extra-files/defaults/hello.d diff --git a/ini/windows/bin/sc.ini b/ini/windows/bin/sc.ini index c9dfda153d3c..54668fff7155 100644 --- a/ini/windows/bin/sc.ini +++ b/ini/windows/bin/sc.ini @@ -7,15 +7,16 @@ version=7.51 Build 020 DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import" ; optlink only reads from the Environment section so we need this redundancy -; from the Environment32 section (bugzilla 11302) +; from the Environment32omf section (bugzilla 11302) LIB="%@P%\..\lib" - [Environment32] +LIB=%@P%\..\lib32mscoff + +[Environment32omf] LIB="%@P%\..\lib" LINKCMD=%@P%\optlink.exe - [Environment64] LIB=%@P%\..\lib64 diff --git a/src/build.d b/src/build.d index 9fa152d8beb0..009ba37e6331 100755 --- a/src/build.d +++ b/src/build.d @@ -309,6 +309,9 @@ alias dmdConf = makeRule!((builder, rule) { DFLAGS="-I%@P%\..\..\..\..\..\druntime\import" "-I%@P%\..\..\..\..\..\phobos" LIB="%@P%\..\..\..\..\..\phobos" +[Environment32] +DFLAGS=%DFLAGS% -L/OPT:NOICF + [Environment64] DFLAGS=%DFLAGS% -L/OPT:NOICF diff --git a/test/dshell/defaults.d b/test/dshell/defaults.d new file mode 100644 index 000000000000..4dec8963bca9 --- /dev/null +++ b/test/dshell/defaults.d @@ -0,0 +1,78 @@ +/// Verifies that DMD using default settings work as expected +/// when using the default configuration + some example programs +module defaults; + +import std.algorithm; +import std.file; +import std.path; +import std.stdio; + +import dshell; + +int main(const string[] args) +{ + // dshellPrebuiltInit("dshell", "defaults"); + + try + { + testConfigurations(); + return 0; + } + catch (Throwable t) + { + writeln(t.msg); + return 1; + } +} + +void testConfigurations() +{ + // Compilation targets + const string[] targets = [ MODEL ]; + + // Configuration file + version (Windows) + const string config = `bin\sc.ini`; + else version (OSX) + const string config = `bin/dmd.conf`; + else + const string config = `bin` ~ MODEL ~ `/dmd.conf`; + + // Static configuration file for the final release + string configPath = buildNormalizedPath(dirName(__FILE_FULL_PATH__), "..", "..", "ini", OS, config); + + // Flag sets to test + string[] extraFlags = [ + // Minimal configuration generated by build.d + "", + // Predefined, full configuration located in ini + "-conf=" ~ configPath + ]; + + version (Windows) if (MODEL == "32omf") + { + // 32-OMF tries to use `optlink.exe` located next to `sc.ini` + // and also doesn't like the LIB setup, so skip it for now + extraFlags = [""]; + } + + foreach (const target; targets) + { + foreach (const flags; extraFlags) + { + run( + `$DMD ` ~ flags ~ ` -g -m` ~ target + ~ ` -I$EXTRA_FILES/defaults ` + ~ DFLAGS + ~ ` $EXTRA_FILES/defaults/hello.d ` + ~ ` -of=$OUTPUT_BASE/hello$EXE `, + ); + + auto pipe = std.process.pipe(); + run(`$OUTPUT_BASE/hello$EXE`, pipe.writeEnd, stderr); + const output = cast(string) pipe.readEnd.byChunk(4096).join(); + stdout.writeln(output); + assert(output.canFind("Hello, World from D!")); + } + } +} diff --git a/test/dshell/extra-files/defaults/hello.d b/test/dshell/extra-files/defaults/hello.d new file mode 100644 index 000000000000..9a027728b46a --- /dev/null +++ b/test/dshell/extra-files/defaults/hello.d @@ -0,0 +1,9 @@ +// A common yet underrated D program +module defaults.hello; + +import std.stdio; + +void main() +{ + writeln("Hello, World from D!"); +} diff --git a/test/tools/dshell_prebuilt/dshell_prebuilt.d b/test/tools/dshell_prebuilt/dshell_prebuilt.d index cc9b4211f248..a14ef7ba8a23 100644 --- a/test/tools/dshell_prebuilt/dshell_prebuilt.d +++ b/test/tools/dshell_prebuilt/dshell_prebuilt.d @@ -39,6 +39,7 @@ struct Vars return result; } static string opDispatch(string name)() { return get(name); } + static void opDispatch(string name)(string value) { set(name, value); } } private alias requiredEnvVars = AliasSeq!(