From 92ebfa13833065a23cd3479eefc2624b46ec45dd Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Sat, 10 Nov 2018 14:30:48 -0600 Subject: [PATCH] wafHook: init The waf build system is python-based and hosted locally in each package in the executable file named "waf". Unlike CMake, it cannot generate makefiles so we end up having to override the configure, build, and install phases. I've tried to keep these as close to what's in setup.sh as possible. If there is no waf file in the root directory, then we just copy the one hosted in Nixpkgs. Otherwise the only thing you have to add to a package using Waf is "wafHook" into nativeBuildInputs. wafFlags controls the flags specifically passed to waf while configureFlags, buildFlags, and installFlags are still used as in the generic builder. --- .../tools/build-managers/waf/setup-hook.sh | 62 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 4 ++ 2 files changed, 66 insertions(+) create mode 100644 pkgs/development/tools/build-managers/waf/setup-hook.sh diff --git a/pkgs/development/tools/build-managers/waf/setup-hook.sh b/pkgs/development/tools/build-managers/waf/setup-hook.sh new file mode 100644 index 000000000000..b8a448df8ef8 --- /dev/null +++ b/pkgs/development/tools/build-managers/waf/setup-hook.sh @@ -0,0 +1,62 @@ +wafConfigurePhase() { + runHook preConfigure + + if ! [ -f ./waf ]; then + cp @waf@ waf + fi + + if [[ -z "${dontAddPrefix:-}" && -n "$prefix" ]]; then + configureFlags="${prefixKey:---prefix=}$prefix $configureFlags" + fi + + local flagsArray=( + $configureFlags ${configureFlagsArray[@]} + ${configureTargets:-configure} + ) + echoCmd 'configure flags' "${flagsArray[@]}" + python waf "${flagsArray[@]}" + + runHook postConfigure +} + +wafBuildPhase () { + runHook preBuild + + # set to empty if unset + : ${wafFlags=} + + local flagsArray=( + ${enableParallelBuilding:+-j ${NIX_BUILD_CORES}} + $wafFlags ${wafFlagsArray[@]} + $buildFlags ${buildFlagsArray[@]} + ${buildTargets:-build} + ) + + echoCmd 'build flags' "${flagsArray[@]}" + python waf "${flagsArray[@]}" + + runHook postBuild +} + +wafInstallPhase() { + runHook preInstall + + if [ -n "$prefix" ]; then + mkdir -p "$prefix" + fi + + local flagsArray=( + $wafFlags ${wafFlagsArray[@]} + $installFlags ${installFlagsArray[@]} + ${installTargets:-install} + ) + + echoCmd 'install flags' "${flagsArray[@]}" + python waf "${flagsArray[@]}" + + runHook postInstall +} + +configurePhase=wafConfigurePhase +buildPhase=wafBuildPhase +installPhase=wafInstallPhase diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ce3766699236..638d76af7608 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6203,6 +6203,10 @@ with pkgs; volumeicon = callPackage ../tools/audio/volumeicon { }; waf = callPackage ../development/tools/build-managers/waf { python = python3; }; + wafHook = makeSetupHook { + deps = [ python ]; + substitutions = { inherit waf; }; + } ../development/tools/build-managers/waf/setup-hook.sh; wakelan = callPackage ../tools/networking/wakelan { };