about summary refs log tree commit diff
path: root/pkgs/test/incrementalBuild/default.nix
blob: cff1efee9a126677c1c74aac3ccf03f31287c490 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ hello, buildIncremental, runCommandNoCC, texinfo, stdenv, rsync }:
let
  baseHello = buildIncremental.prepareIncrementalBuild hello;
  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}
    '';
  });
  incrementalBuiltHello = buildIncremental.mkIncrementalBuild patchedHello baseHello.incrementalBuildArtifacts;

  incrementalBuiltHelloWithCheck = incrementalBuiltHello.overrideAttrs (old: {
    doCheck = true;
    checkPhase = ''
      echo "checking if unchanged source file is not recompiled"
        [ "$(stat --format="%Y" lib/exitfail.o)" = "$(stat --format="%Y" ${baseHello.incrementalBuildArtifacts}/lib/exitfail.o)" ]
    '';
  });

  baseHelloRemoveFile = buildIncremental.prepareIncrementalBuild (hello.overrideAttrs (old: {
    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}
    '';
  });

  incrementalBuiltHelloWithRemovedFile = buildIncremental.mkIncrementalBuild patchedHelloRemoveFile baseHelloRemoveFile.incrementalBuildArtifacts;
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!" ]
  '';
}