git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commit1ba9fd335d90bca03b3868d3bf10c3d9a9de29c6 authorMatthew Bauer <mjbauer95@gmail.com> dateSun 11 Nov 2018, 20:49 (8 years ago) parentf2a20b6
2 files changed+86
pkgs/development/tools/build-managers/scons/common.nix+2 pkgs/development/tools/build-managers/scons/setup-hook.sh+84
pkgs/development/tools/build-managers/scons/common.nix+2
@@ -14,6 +14,8 @@ in python2Packages.buildPythonApplication {
1414 # Fix a regression in 3.0.0 (causes build errors for some packages)
1515 patches = stdenv.lib.optional (version == "3.0.0") ./print-statements.patch;
1616
17+ setupHook = ./setup-hook.sh;
18+
1719 meta = with stdenv.lib; {
1820 homepage = http://scons.org/;
1921 description = "An improved, cross-platform substitute for Make";
pkgs/development/tools/build-managers/scons/setup-hook.shnew file+84
@@ -0,0 +1,84 @@
1+sconsBuildPhase() {
2+ runHook preBuild
3+
4+ if [ -n "$prefix" ]; then
5+ mkdir -p "$prefix"
6+ fi
7+
8+ if [ -z "${dontAddPrefix:-}" ] && [ -n "$prefix" ]; then
9+ buildFlags="${prefixKey:-prefix=}$prefix $buildFlags"
10+ fi
11+
12+ local flagsArray=(
13+ ${enableParallelBuilding:+-j${NIX_BUILD_CORES}}
14+ $sconsFlags ${sconsFlagsArray[@]}
15+ $buildFlags ${buildFlagsArray[@]}
16+ )
17+
18+ echoCmd 'build flags' "${flagsArray[@]}"
19+ scons "${flagsArray[@]}"
20+
21+ runHook postBuild
22+}
23+
24+sconsInstallPhase() {
25+ runHook preInstall
26+
27+ if [ -n "$prefix" ]; then
28+ mkdir -p "$prefix"
29+ fi
30+
31+ if [ -z "${dontAddPrefix:-}" ] && [ -n "$prefix" ]; then
32+ installFlags="${prefixKey:-prefix=}$prefix $installFlags"
33+ fi
34+
35+ local flagsArray=(
36+ $sconsFlags ${sconsFlagsArray[@]}
37+ $installFlags ${installFlagsArray[@]}
38+ ${installTargets:-install}
39+ )
40+
41+ echoCmd 'install flags' "${flagsArray[@]}"
42+ scons "${flagsArray[@]}"
43+
44+ runHook postInstall
45+}
46+
47+sconsCheckPhase() {
48+ runHook preCheck
49+
50+ if [ -z "${checkTarget:-}" ]; then
51+ if scons -n check >/dev/null 2>&1; then
52+ checkTarget=check
53+ elif scons -n test >/dev/null 2>&1; then
54+ checkTarget=test
55+ fi
56+ fi
57+
58+ if [ -z "${checkTarget:-}" ]; then
59+ echo "no check/test target found, doing nothing"
60+ else
61+ local flagsArray=(
62+ ${enableParallelChecking:+-j${NIX_BUILD_CORES}}
63+ $sconsFlags ${sconsFlagsArray[@]}
64+ ${checkFlagsArray[@]}
65+ )
66+
67+ echoCmd 'check flags' "${flagsArray[@]}"
68+ scons "${flagsArray[@]}"
69+ fi
70+
71+ runHook postCheck
72+}
73+
74+if [ -z "$buildPhase" ]; then
75+ buildPhase=sconsBuildPhase
76+fi
77+
78+if [ -z "$installPhase" ]; then
79+ installPhase=sconsInstallPhase
80+fi
81+
82+if [ -z "$checkPhase" ]; then
83+ checkPhase=sconsCheckPhase
84+fi