2022-06-27 12:03:10 +00:00
|
|
|
{ hello, incrementalBuildTools, runCommandNoCC, texinfo, stdenv, rsync }:
|
2022-04-07 14:28:20 +00:00
|
|
|
let
|
2022-06-27 12:03:10 +00:00
|
|
|
baseHelloArtifacts = incrementalBuildTools.prepareIncrementalBuild hello;
|
2022-04-07 14:28:20 +00:00
|
|
|
patchedHello = hello.overrideAttrs (old: {
|
|
|
|
buildInputs = [ texinfo ];
|
|
|
|
src = runCommandNoCC "patch-hello-src" { } ''
|
|
|
|
mkdir -p $out
|
|
|
|
cd $out
|
|
|
|
tar xf ${hello.src} --strip-components=1
|
|
|
|
patch -p1 < ${./hello.patch}
|
|
|
|
'';
|
|
|
|
});
|
2022-06-27 12:03:10 +00:00
|
|
|
incrementalBuiltHello = incrementalBuildTools.mkIncrementalBuild patchedHello baseHelloArtifacts;
|
2022-04-07 14:28:20 +00:00
|
|
|
|
|
|
|
incrementalBuiltHelloWithCheck = incrementalBuiltHello.overrideAttrs (old: {
|
|
|
|
doCheck = true;
|
|
|
|
checkPhase = ''
|
|
|
|
echo "checking if unchanged source file is not recompiled"
|
2022-06-20 09:17:09 +00:00
|
|
|
[ "$(stat --format="%Y" lib/exitfail.o)" = "$(stat --format="%Y" ${baseHelloArtifacts}/outputs/lib/exitfail.o)" ]
|
2022-04-07 14:28:20 +00:00
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
2022-06-27 12:03:10 +00:00
|
|
|
baseHelloRemoveFileArtifacts = incrementalBuildTools.prepareIncrementalBuild (hello.overrideAttrs (old: {
|
2022-04-07 14:28:20 +00:00
|
|
|
patches = [ ./hello-additionalFile.patch ];
|
|
|
|
}));
|
|
|
|
|
|
|
|
preparedHelloRemoveFileSrc = runCommandNoCC "patch-hello-src" { } ''
|
|
|
|
mkdir -p $out
|
|
|
|
cd $out
|
|
|
|
tar xf ${hello.src} --strip-components=1
|
|
|
|
patch -p1 < ${./hello-additionalFile.patch}
|
|
|
|
'';
|
|
|
|
|
|
|
|
patchedHelloRemoveFile = hello.overrideAttrs (old: {
|
|
|
|
buildInputs = [ texinfo ];
|
|
|
|
src = runCommandNoCC "patch-hello-src" { } ''
|
|
|
|
mkdir -p $out
|
|
|
|
cd $out
|
|
|
|
${rsync}/bin/rsync -cutU --chown=$USER:$USER --chmod=+w -r ${preparedHelloRemoveFileSrc}/* .
|
|
|
|
patch -p1 < ${./hello-removeFile.patch}
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
|
2022-06-27 12:03:10 +00:00
|
|
|
incrementalBuiltHelloWithRemovedFile = incrementalBuildTools.mkIncrementalBuild patchedHelloRemoveFile baseHelloRemoveFileArtifacts;
|
2022-04-07 14:28:20 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
name = "patched-hello-returns-correct-output";
|
|
|
|
buildCommand = ''
|
|
|
|
touch $out
|
|
|
|
|
|
|
|
echo "testing output of hello binary"
|
|
|
|
[ "$(${incrementalBuiltHelloWithCheck}/bin/hello)" = "Hello, incremental world!" ]
|
|
|
|
echo "testing output of hello with removed file"
|
|
|
|
[ "$(${incrementalBuiltHelloWithRemovedFile}/bin/hello)" = "Hello, incremental world!" ]
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
|