From 5f3aad00ffc0a769a1ccc5b3b521221aa5e5d809 Mon Sep 17 00:00:00 2001 From: Bryan Lai Date: Sun, 7 Jan 2024 21:27:30 +0800 Subject: [PATCH] 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 --- pkgs/build-support/checkpoint-build.nix | 32 ++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/pkgs/build-support/checkpoint-build.nix b/pkgs/build-support/checkpoint-build.nix index 5876202b0bd0..3537eddfbcbc 100644 --- a/pkgs/build-support/checkpoint-build.nix +++ b/pkgs/build-support/checkpoint-build.nix @@ -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; }