diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2024-01-10 00:02:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 00:02:18 +0000 |
commit | 122355be994486ec9dbb4e1e87c9206bec11b521 (patch) | |
tree | b580ef31b35c9392f5037d1e7f770b283b9b65fc /pkgs/build-support | |
parent | fcff3d7883a38ef71832899085ba365658c96867 (diff) | |
parent | e1bd5ec7242dee687899fcc3117d6e7552bbc9ec (diff) | |
download | nixlib-122355be994486ec9dbb4e1e87c9206bec11b521.tar nixlib-122355be994486ec9dbb4e1e87c9206bec11b521.tar.gz nixlib-122355be994486ec9dbb4e1e87c9206bec11b521.tar.bz2 nixlib-122355be994486ec9dbb4e1e87c9206bec11b521.tar.lz nixlib-122355be994486ec9dbb4e1e87c9206bec11b521.tar.xz nixlib-122355be994486ec9dbb4e1e87c9206bec11b521.tar.zst nixlib-122355be994486ec9dbb4e1e87c9206bec11b521.zip |
Merge master into staging-next
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/checkpoint-build.nix | 79 |
1 files changed, 50 insertions, 29 deletions
diff --git a/pkgs/build-support/checkpoint-build.nix b/pkgs/build-support/checkpoint-build.nix index e08dde353e89..c9bee45005a1 100644 --- a/pkgs/build-support/checkpoint-build.nix +++ b/pkgs/build-support/checkpoint-build.nix @@ -1,40 +1,53 @@ -{ 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. * - * This function prepares checkpoint builds by provinding, - * containing the build output and the sources for cross checking. + * This function prepares checkpoint builds by storing + * the build output and the sources for cross checking. * The build output can be used later to allow checkpoint builds * by passing the derivation output to the `mkCheckpointBuild` function. * - * To build a project with checkpoints follow these steps: - * - run prepareIncrementalBuild on the desired derivation - * e.G `incrementalBuildArtifacts = (pkgs.checkpointBuildTools.prepareCheckpointBuild 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; - * } - * - use `mkCheckpointedBuild changedVBox buildOutput` + * To build a project with checkpoints, follow these steps: + * - run `prepareCheckpointBuild` on the desired derivation, e.g. + * checkpointArtifacts = prepareCheckpointBuild 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; + * }; + * - use `mkCheckpointBuild changedVBox checkpointArtifacts` * - enjoy shorter build times */ prepareCheckpointBuild = drv: drv.overrideAttrs (old: { outputs = [ "out" ]; name = drv.name + "-checkpointArtifacts"; # To determine differences between the state of the build directory - # from an earlier build and a later one we store the state of the build + # from an earlier build and a later one we store the state of the build # directory before build, but after patch phases. # This way, the same derivation can be used multiple times and only changes are detected. - # Additionally Removed files are handled correctly in later builds. + # Additionally, removed files are handled correctly in later builds. preBuild = (old.preBuild or "") + '' mkdir -p $out/sources cp -r ./* $out/sources/ ''; - # After the build the build directory is copied again + # After the build, the build directory is copied again # to get the output files. - # We copy the complete build folder, to take care for - # Build tools, building in the source directory, instead of - # having a build root directory, e.G the Linux kernel. + # We copy the complete build folder, to take care of + # build tools that build in the source directory, instead of + # having a separate build directory such as the Linux kernel. installPhase = '' runHook preCheckpointInstall mkdir -p $out/outputs @@ -44,26 +57,34 @@ rec { }); /* Build a derivation based on the checkpoint output generated by - * the `prepareCheckpointBuild function. + * the `prepareCheckpointBuild` function. * * Usage: * let - * checkpointArtifacts = prepareCheckpointBuild drv - * in mkCheckpointedBuild drv checkpointArtifacts + * checkpointArtifacts = prepareCheckpointBuild drv; + * in mkCheckpointBuild drv checkpointArtifacts */ - mkCheckpointedBuild = 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. + # We compare the changed sources from a previous build with the current and create a patch. + # Afterwards we clean the build directory and copy the previous output files (including the sources). + # The source difference patch is then 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 = lib.warn + "`mkCheckpointedBuild` is deprecated, use `mkCheckpointBuild` instead!" + mkCheckpointBuild; } |