From 2852e84aa9c1521b9164150f22e103a3c6d88c49 Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Fri, 25 Oct 2024 17:49:41 -0700 Subject: [PATCH] Remove Phobos 3 dub.sdl and replace it with the build_v3.d build script. (#9069) * Remove Phobos 3 dub.sdl and replace it with the build_v3.d buid script. * Add environment bang to the build script. * Fix the Phobos v3 build script so that unit tests work on POSIX. --------- Co-authored-by: Jonathan M Davis --- .gitignore | 7 +++ build_v3.d | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++ dub.sdl | 20 -------- 3 files changed, 147 insertions(+), 20 deletions(-) create mode 100755 build_v3.d delete mode 100644 dub.sdl diff --git a/.gitignore b/.gitignore index 35ba21fcb..23c73906d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,10 @@ libphobos_* source/ tools/ucd* + +# Build specific exclusions +*.o +*.a +*.obj +*.exe +unittest \ No newline at end of file diff --git a/build_v3.d b/build_v3.d new file mode 100755 index 000000000..83c9be57b --- /dev/null +++ b/build_v3.d @@ -0,0 +1,140 @@ +#!/usr/bin/env rdmd +/** +Phobos V3 Build Script + +Usage: + ./build_v3.d [debug,release,unittest] +*/ + +import std.conv; +import std.datetime; +import std.file; +import std.path; +import std.process; +import std.stdio; +import std.string; + +int main(string[] args) +{ + int result = 0; + + bool buildUnittest = false; + bool buildRelease = false; + if (args.length > 1) + { + buildUnittest = args[1] == "unittest"; + buildRelease = args[1] == "release"; + } + + string argFilePath = buildNormalizedPath(getcwd(), "phobosbuildargs.txt"); + auto dFiles = dirEntries(buildNormalizedPath(getcwd(), "phobos"), "*.d", SpanMode.breadth); + auto argFile = File(argFilePath, "w"); + + version(Windows) + { + string unittestExecutable = buildNormalizedPath(getcwd(), "unittest.exe"); + } + else + { + string unittestExecutable = buildNormalizedPath(getcwd(), "unittest"); + } + + scope(exit) + { + argFile.close(); + remove(argFilePath); + + if (exists(unittestExecutable)) remove(unittestExecutable); + } + + result = runCommand("dmd --version", getcwd()); + if (result != 0) + { + writeln("Compiler Failure."); + return result; + } + + writeln("Source files:"); + //Add source file list to args file. + foreach(dFile; dFiles) + { + if (dFile.isDir()) continue; + argFile.writeln(dFile.name); + writeln(dFile.name); + } + + //Add appropriate DMD arguments to the args file. + argFile.writeln("-od=./lib"); + if (buildUnittest) + { + argFile.writeln("-main"); + argFile.writeln("-unittest"); + argFile.writeln("-debug"); + + version(Windows) + { + argFile.writeln("-of=unittest.exe"); + } + else + { + argFile.writeln("-of=unittest"); + } + } + else if (buildRelease) + { + argFile.writeln("-release -O"); + argFile.writeln("-lib"); + argFile.writeln("-of=libphobos3"); + } + else + { + argFile.writeln("-debug"); + argFile.writeln("-lib"); + argFile.writeln("-of=libphobos3-debug"); + } + + argFile.flush(); + argFile.close(); + + //Run the build. + result = runCommand("dmd @\"" ~ argFilePath ~ "\"", getcwd()); + if (result != 0) + { + writeln("Build failed."); + return result; + } + else + { + writeln("Build successful."); + writeln(); + } + + //Run unittests if built. + if (buildUnittest) + { + writeln("Running tests..."); + result = runCommand(unittestExecutable, getcwd()); + + if (result != 0) + { + writeln("Tests failed."); + return result; + } + else + { + writeln("Tests successful."); + } + } + + return result; +} + +private int runCommand(string command, string workDir) +{ + auto pid = pipeShell(command, Redirect.all, null, Config.none, workDir); + int result = wait(pid.pid); + foreach (line; pid.stdout.byLine) writeln(line); + foreach (line; pid.stderr.byLine) writeln(line); + writeln(); + return result; +} diff --git a/dub.sdl b/dub.sdl deleted file mode 100644 index 516e59682..000000000 --- a/dub.sdl +++ /dev/null @@ -1,20 +0,0 @@ -name "phobos" -license "BSL-1.0" -description "D Standard Library" -authors "DLang Community" -copyright "Copyright © 1999-2024, The D Language Foundation" - -configuration "library" { - targetType "staticLibrary" - sourcePaths "phobos" - targetPath "generated-lib" - #excludedSourceFiles "unittest.d" "test/**" "std/**" "tools/**" "etc/**" -} - -configuration "unittest" { - dflags "-main" - targetType "executable" - sourcePaths "phobos" - targetPath "generated-lib" - #excludedSourceFiles "unittest.d" "test/**" "std/**" "tools/**" "etc/**" -}