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.
This commit is contained in:
Matthew Bauer 2018-11-11 20:49:51 -06:00
parent f2a20b6e52
commit 1ba9fd335d
2 changed files with 86 additions and 0 deletions

View File

@ -14,6 +14,8 @@ in python2Packages.buildPythonApplication {
# Fix a regression in 3.0.0 (causes build errors for some packages) # Fix a regression in 3.0.0 (causes build errors for some packages)
patches = stdenv.lib.optional (version == "3.0.0") ./print-statements.patch; patches = stdenv.lib.optional (version == "3.0.0") ./print-statements.patch;
setupHook = ./setup-hook.sh;
meta = with stdenv.lib; { meta = with stdenv.lib; {
homepage = http://scons.org/; homepage = http://scons.org/;
description = "An improved, cross-platform substitute for Make"; description = "An improved, cross-platform substitute for Make";

View File

@ -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