summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2018-11-11 20:49:51 -0600
committerMatthew Bauer <mjbauer95@gmail.com>2018-11-13 19:13:50 -0600
commit1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6 (patch)
treee6e36a2f3cb88b030f3fffb33b42b15014463045
parentf2a20b6e520989bc2c01d362c31fa94cbf6bee52 (diff)
downloadnixpkgs-1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6.tar
nixpkgs-1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6.tar.gz
nixpkgs-1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6.tar.bz2
nixpkgs-1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6.tar.lz
nixpkgs-1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6.tar.xz
nixpkgs-1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6.tar.zst
nixpkgs-1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6.zip
scons: add setup hook
The scons build system is python-based and has a binary named scons. Unlike CMake, it cannot generate makefiles so we end up having to override the build, install, and check phases. I have added the setupHook to the scons package so that integration requires no unique steps - just putting scons in nativeBuildInputs should be enough. sconsFlags controls the flags specifically passed to scons while buildFlags, installFlags, and checkFlags should still be usable. Some packages use different names for the prefix flag. In those cases you will have to set "prefixKey" to something like "PREFIX=" as there are multiple names for the "prefix" used in scons.
-rw-r--r--pkgs/development/tools/build-managers/scons/common.nix2
-rw-r--r--pkgs/development/tools/build-managers/scons/setup-hook.sh84
2 files changed, 86 insertions, 0 deletions
diff --git a/pkgs/development/tools/build-managers/scons/common.nix b/pkgs/development/tools/build-managers/scons/common.nix
index 4b0242a3956..740d04d853f 100644
--- a/pkgs/development/tools/build-managers/scons/common.nix
+++ b/pkgs/development/tools/build-managers/scons/common.nix
@@ -14,6 +14,8 @@ in python2Packages.buildPythonApplication {
   # Fix a regression in 3.0.0 (causes build errors for some packages)
   patches = stdenv.lib.optional (version == "3.0.0") ./print-statements.patch;
 
+  setupHook = ./setup-hook.sh;
+
   meta = with stdenv.lib; {
     homepage = http://scons.org/;
     description = "An improved, cross-platform substitute for Make";
diff --git a/pkgs/development/tools/build-managers/scons/setup-hook.sh b/pkgs/development/tools/build-managers/scons/setup-hook.sh
new file mode 100644
index 00000000000..bb5591c4620
--- /dev/null
+++ b/pkgs/development/tools/build-managers/scons/setup-hook.sh
@@ -0,0 +1,84 @@
+sconsBuildPhase() {
+    runHook preBuild
+
+    if [ -n "$prefix" ]; then
+        mkdir -p "$prefix"
+    fi
+
+    if [ -z "${dontAddPrefix:-}" ] && [ -n "$prefix" ]; then
+        buildFlags="${prefixKey:-prefix=}$prefix $buildFlags"
+    fi
+
+    local flagsArray=(
+      ${enableParallelBuilding:+-j${NIX_BUILD_CORES}}
+      $sconsFlags ${sconsFlagsArray[@]}
+      $buildFlags ${buildFlagsArray[@]}
+    )
+
+    echoCmd 'build flags' "${flagsArray[@]}"
+    scons "${flagsArray[@]}"
+
+    runHook postBuild
+}
+
+sconsInstallPhase() {
+    runHook preInstall
+
+    if [ -n "$prefix" ]; then
+        mkdir -p "$prefix"
+    fi
+
+    if [ -z "${dontAddPrefix:-}" ] && [ -n "$prefix" ]; then
+        installFlags="${prefixKey:-prefix=}$prefix $installFlags"
+    fi
+
+    local flagsArray=(
+        $sconsFlags ${sconsFlagsArray[@]}
+        $installFlags ${installFlagsArray[@]}
+        ${installTargets:-install}
+    )
+
+    echoCmd 'install flags' "${flagsArray[@]}"
+    scons "${flagsArray[@]}"
+
+    runHook postInstall
+}
+
+sconsCheckPhase() {
+    runHook preCheck
+
+    if [ -z "${checkTarget:-}" ]; then
+        if scons -n check >/dev/null 2>&1; then
+            checkTarget=check
+        elif scons -n test >/dev/null 2>&1; then
+            checkTarget=test
+        fi
+    fi
+
+    if [ -z "${checkTarget:-}" ]; then
+        echo "no check/test target found, doing nothing"
+    else
+        local flagsArray=(
+            ${enableParallelChecking:+-j${NIX_BUILD_CORES}}
+            $sconsFlags ${sconsFlagsArray[@]}
+            ${checkFlagsArray[@]}
+        )
+
+        echoCmd 'check flags' "${flagsArray[@]}"
+        scons "${flagsArray[@]}"
+    fi
+
+    runHook postCheck
+}
+
+if [ -z "$buildPhase" ]; then
+    buildPhase=sconsBuildPhase
+fi
+
+if [ -z "$installPhase" ]; then
+    installPhase=sconsInstallPhase
+fi
+
+if [ -z "$checkPhase" ]; then
+    checkPhase=sconsCheckPhase
+fi