From 1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sun, 11 Nov 2018 20:49:51 -0600 Subject: [PATCH] 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. --- .../tools/build-managers/scons/common.nix | 2 + .../tools/build-managers/scons/setup-hook.sh | 84 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 pkgs/development/tools/build-managers/scons/setup-hook.sh 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