From cd6c65fe2d96e8342f85f8467dee9b76618a144d Mon Sep 17 00:00:00 2001 From: Martin Messer Date: Wed, 15 Jun 2022 11:10:47 +0200 Subject: [PATCH] checkpointedBuild: consider removing files and make buildartifacts the only output of the prepare step --- pkgs/build-support/build-incremental.nix | 43 ++++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/pkgs/build-support/build-incremental.nix b/pkgs/build-support/build-incremental.nix index 6cdf07f0b801..9c779befb20e 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 + ''; }); }