diff options
author | Martin Messer <martin.messer@cyberus-technology.de> | 2022-06-15 11:10:47 +0200 |
---|---|---|
committer | Martin Messer <martin.messer@cyberus-technology.de> | 2023-12-07 16:38:48 +0100 |
commit | cd6c65fe2d96e8342f85f8467dee9b76618a144d (patch) | |
tree | 5153ad3c31c7b07addf47243987f3b3e1363e12d /pkgs/build-support | |
parent | 17e88c2890068e944c61dbaf7493ae12417b8944 (diff) |
checkpointedBuild: consider removing files and make buildartifacts the only output of the prepare step
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/build-incremental.nix | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/pkgs/build-support/build-incremental.nix b/pkgs/build-support/build-incremental.nix index 6cdf07f0b8011..9c779befb20ef 100644 --- a/pkgs/build-support/build-incremental.nix +++ b/pkgs/build-support/build-incremental.nix @@ -2,14 +2,14 @@ rec { /* Prepare a derivation for local builds. * - * This function adds an additional output for a derivation, - * containing the build output. + * This function prepares incremental builds by provinding, + * containing the build output and the sources for cross checking. * The build output can be used later to allow incremental builds - * by passing the `buildOut` output to the `mkIncrementalBuild` function. + * by passing the derivation output to the `mkIncrementalBuild` function. * * To build a project incrementaly follow these steps: * - run prepareIncrementalBuild on the desired derivation - * e.G `incrementalBuildArtifacts = (pkgs.buildIncremental.prepareIncrementalBuild pkgs.virtualbox).incrementalBuildArtifacts;` + * e.G `incrementalBuildArtifacts = (pkgs.buildIncremental.prepareIncrementalBuild pkgs.virtualbox);` * - change something you want in the sources of the package( e.G using source override) * changedVBox = pkgs.virtuabox.overrideAttrs (old: { * src = path/to/vbox/sources; @@ -18,12 +18,16 @@ rec { * - enjoy shorter build times */ prepareIncrementalBuild = drv: drv.overrideAttrs (old: { - outputs = (old.outputs or [ "out" ]) ++ [ "incrementalBuildArtifacts" ]; - installPhase = pkgs.lib.optionalString (!(builtins.hasAttr "outputs" old)) '' - mkdir -p $out - '' + (old.installPhase or "") + '' - mkdir -p $incrementalBuildArtifacts - cp -r ./* $incrementalBuildArtifacts/ + outputs = [ "out" ]; + name = drv.name + "-incrementalBuildArtifacts"; + preBuild = (old.preBuild or "") + '' + mkdir -p $out/sources + cp -r ./* $out/sources/ + ''; + + installPhase = '' + mkdir -p $out/outputs + cp -r ./* $out/outputs/ ''; }); @@ -32,16 +36,19 @@ rec { * * Usage: * let - * incrementalBuildArtifacts = (prepareIncrementalBuild drv).incrementalBuildArtifacts + * incrementalBuildArtifacts = prepareIncrementalBuild drv * in mkIncrementalBuild drv incrementalBuildArtifacts */ mkIncrementalBuild = drv: previousBuildArtifacts: drv.overrideAttrs (old: { - prePatch = '' - for file in $(diff -r ./ ${previousBuildArtifacts} --brief | grep "Files" |sed 's/^Only in \([^:]*\): /\1\//' | sed 's/^Files \(.*\) and .* differ/\1/') - do - touch $file - done - ${pkgs.rsync}/bin/rsync -cutU --chown=$USER:$USER --chmod=+w -r ${previousBuildArtifacts}/* . - '' + (old.prePatch or ""); + preBuild = (old.preBuild or "") + '' + set +e + diff -ur ${previousBuildArtifacts}/sources ./ > sourceDifference.patch + set -e + shopt -s extglob + rm -r !("sourceDifference.patch") + ls -al . + ${pkgs.rsync}/bin/rsync -cutU --chown=$USER:$USER --chmod=+w -r ${previousBuildArtifacts}/outputs/* . + patch -p 1 -i sourceDifference.patch + ''; }); } |