checkpointBuildTools: minor refactor
Add some minor improvements of the package, and use temp files for the source difference patch, such that it is more reliable. This follows from the suggestions of @infinisil. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
parent
df62c3c87f
commit
5f3aad00ff
1 changed files with 24 additions and 8 deletions
|
@ -1,4 +1,16 @@
|
|||
{ pkgs }:
|
||||
{ lib
|
||||
, buildPackages
|
||||
}:
|
||||
|
||||
let
|
||||
# rudimentary support for cross-compiling
|
||||
# see: https://github.com/NixOS/nixpkgs/pull/279487#discussion_r1444449726
|
||||
inherit (buildPackages)
|
||||
mktemp
|
||||
rsync
|
||||
;
|
||||
in
|
||||
|
||||
rec {
|
||||
/* Prepare a derivation for local builds.
|
||||
*
|
||||
|
@ -51,23 +63,27 @@ rec {
|
|||
* checkpointArtifacts = prepareCheckpointBuild drv
|
||||
* in mkCheckpointBuild drv checkpointArtifacts
|
||||
*/
|
||||
mkCheckpointBuild = drv: previousBuildArtifacts: drv.overrideAttrs (old: {
|
||||
mkCheckpointBuild = drv: checkpointArtifacts: drv.overrideAttrs (old: {
|
||||
# The actual checkpoint build phase.
|
||||
# We compare the changed sources from a previous build with the current and create a patch
|
||||
# Afterwards we clean the build directory to copy the previous output files (Including the sources)
|
||||
# The source difference patch is applied to get the latest changes again to allow short build times.
|
||||
preBuild = (old.preBuild or "") + ''
|
||||
set +e
|
||||
diff -ur ${previousBuildArtifacts}/sources ./ > sourceDifference.patch
|
||||
sourceDifferencePatchFile=$(${mktemp}/bin/mktemp)
|
||||
diff -ur ${checkpointArtifacts}/sources ./ > "$sourceDifferencePatchFile"
|
||||
set -e
|
||||
shopt -s extglob dotglob
|
||||
rm -r !("sourceDifference.patch")
|
||||
${pkgs.rsync}/bin/rsync -cutU --chown=$USER:$USER --chmod=+w -r ${previousBuildArtifacts}/outputs/* .
|
||||
patch -p 1 -i sourceDifference.patch
|
||||
shopt -s dotglob
|
||||
rm -r *
|
||||
${rsync}/bin/rsync \
|
||||
--checksum --times --atimes --chown=$USER:$USER --chmod=+w \
|
||||
-r ${checkpointArtifacts}/outputs/ .
|
||||
patch -p 1 -i "$sourceDifferencePatchFile"
|
||||
rm "$sourceDifferencePatchFile"
|
||||
'';
|
||||
});
|
||||
|
||||
mkCheckpointedBuild = pkgs.lib.warn
|
||||
mkCheckpointedBuild = lib.warn
|
||||
"`mkCheckpointedBuild` is deprecated, use `mkCheckpointBuild` instead!"
|
||||
mkCheckpointBuild;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue