about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorMartin Messer <martin.messer@cyberus-technology.de>2022-04-07 16:28:20 +0200
committerMartin Messer <martin.messer@cyberus-technology.de>2023-12-07 16:38:48 +0100
commit17e88c2890068e944c61dbaf7493ae12417b8944 (patch)
tree8a6c526ab1391a63dc10a29d59d7539344ae9594 /pkgs
parent1cd6b7fdc37cdc7a4a31c87aa31e4ebf5ed930c8 (diff)
checkpointedBuild: add checkpointed build test based on pkgs hello
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/test/default.nix2
-rw-r--r--pkgs/test/incrementalBuild/default.nix57
-rw-r--r--pkgs/test/incrementalBuild/hello-additionalFile.patch62
-rw-r--r--pkgs/test/incrementalBuild/hello-removeFile.patch62
-rw-r--r--pkgs/test/incrementalBuild/hello.patch26
5 files changed, 209 insertions, 0 deletions
diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix
index 29dc4b5192ec9..8ca6c4faf56eb 100644
--- a/pkgs/test/default.nix
+++ b/pkgs/test/default.nix
@@ -113,6 +113,8 @@ with pkgs;
 
   install-shell-files = callPackage ./install-shell-files {};
 
+  incremental-build = callPackage ./incrementalBuild {};
+
   kernel-config = callPackage ./kernel.nix {};
 
   ld-library-path = callPackage ./ld-library-path {};
diff --git a/pkgs/test/incrementalBuild/default.nix b/pkgs/test/incrementalBuild/default.nix
new file mode 100644
index 0000000000000..cff1efee9a126
--- /dev/null
+++ b/pkgs/test/incrementalBuild/default.nix
@@ -0,0 +1,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!" ]
+  '';
+}
+
diff --git a/pkgs/test/incrementalBuild/hello-additionalFile.patch b/pkgs/test/incrementalBuild/hello-additionalFile.patch
new file mode 100644
index 0000000000000..31fbe034909eb
--- /dev/null
+++ b/pkgs/test/incrementalBuild/hello-additionalFile.patch
@@ -0,0 +1,62 @@
+diff --git a/Makefile.in b/Makefile.in
+index 0805eda..77b000c 100644
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -227,7 +227,7 @@ am_lib_libhello_a_OBJECTS = lib/c-ctype.$(OBJEXT) \
+ 	lib/quotearg.$(OBJEXT) lib/strnlen1.$(OBJEXT) \
+ 	lib/unistd.$(OBJEXT) lib/wctype-h.$(OBJEXT) \
+ 	lib/xmalloc.$(OBJEXT) lib/xalloc-die.$(OBJEXT) \
+-	lib/xstrndup.$(OBJEXT)
++	lib/xstrndup.$(OBJEXT) src/additionalFile.$(OBJEXT)
+ lib_libhello_a_OBJECTS = $(am_lib_libhello_a_OBJECTS)
+ am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(infodir)" \
+ 	"$(DESTDIR)$(man1dir)"
+@@ -1380,7 +1380,7 @@ lib_libhello_a_SOURCES = lib/c-ctype.h lib/c-ctype.c lib/c-strcase.h \
+ 	lib/gettext.h lib/localcharset.h lib/localcharset.c \
+ 	lib/progname.h lib/progname.c lib/quotearg.c lib/strnlen1.h \
+ 	lib/strnlen1.c lib/unistd.c lib/wctype-h.c lib/xmalloc.c \
+-	lib/xalloc-die.c lib/xstrndup.h lib/xstrndup.c
++	lib/xalloc-die.c lib/xstrndup.h lib/xstrndup.c src/additionalFile.c
+ lib_libhello_a_LIBADD = $(gl_LIBOBJS)
+ lib_libhello_a_DEPENDENCIES = $(gl_LIBOBJS)
+ EXTRA_lib_libhello_a_SOURCES = lib/stripslash.c lib/error.c \
+diff --git a/src/additionalFile.c b/src/additionalFile.c
+new file mode 100644
+index 0000000..34d683d
+--- /dev/null
++++ b/src/additionalFile.c
+@@ -0,0 +1,6 @@
++#include "config.h"
++#include "system.h"
++
++int somefunc() {
++    return 0;
++}
+diff --git a/src/hello.c b/src/hello.c
+index 453962f..df67de2 100644
+--- a/src/hello.c
++++ b/src/hello.c
+@@ -57,7 +57,11 @@ main (int argc, char *argv[])
+ #endif
+ 
+   /* Having initialized gettext, get the default message. */
+-  greeting_msg = _("Hello, world!");
++  if (somefunc() == 0) {
++    greeting_msg = _("Hello, world!");
++  } else {
++    greeting_msg = _("Hello, incremental world!");
++  }
+ 
+   /* Even exiting has subtleties.  On exit, if any writes failed, change
+      the exit status.  The /dev/full device on GNU/Linux can be used for
+diff --git a/src/system.h b/src/system.h
+index d1acac2..935b955 100644
+--- a/src/system.h
++++ b/src/system.h
+@@ -42,4 +42,6 @@
+ /* Check for errors on write.  */
+ # include "closeout.h"
+ 
++int somefunc();
++
+ #endif /* HELLO_SYSTEM_H */
diff --git a/pkgs/test/incrementalBuild/hello-removeFile.patch b/pkgs/test/incrementalBuild/hello-removeFile.patch
new file mode 100644
index 0000000000000..99ecf1e298bbb
--- /dev/null
+++ b/pkgs/test/incrementalBuild/hello-removeFile.patch
@@ -0,0 +1,62 @@
+diff --git a/Makefile.in b/Makefile.in
+index 77b000c..0805eda 100644
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -227,7 +227,7 @@ am_lib_libhello_a_OBJECTS = lib/c-ctype.$(OBJEXT) \
+ 	lib/quotearg.$(OBJEXT) lib/strnlen1.$(OBJEXT) \
+ 	lib/unistd.$(OBJEXT) lib/wctype-h.$(OBJEXT) \
+ 	lib/xmalloc.$(OBJEXT) lib/xalloc-die.$(OBJEXT) \
+-	lib/xstrndup.$(OBJEXT) src/additionalFile.$(OBJEXT)
++	lib/xstrndup.$(OBJEXT)
+ lib_libhello_a_OBJECTS = $(am_lib_libhello_a_OBJECTS)
+ am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(infodir)" \
+ 	"$(DESTDIR)$(man1dir)"
+@@ -1380,7 +1380,7 @@ lib_libhello_a_SOURCES = lib/c-ctype.h lib/c-ctype.c lib/c-strcase.h \
+ 	lib/gettext.h lib/localcharset.h lib/localcharset.c \
+ 	lib/progname.h lib/progname.c lib/quotearg.c lib/strnlen1.h \
+ 	lib/strnlen1.c lib/unistd.c lib/wctype-h.c lib/xmalloc.c \
+-	lib/xalloc-die.c lib/xstrndup.h lib/xstrndup.c src/additionalFile.c
++	lib/xalloc-die.c lib/xstrndup.h lib/xstrndup.c
+ lib_libhello_a_LIBADD = $(gl_LIBOBJS)
+ lib_libhello_a_DEPENDENCIES = $(gl_LIBOBJS)
+ EXTRA_lib_libhello_a_SOURCES = lib/stripslash.c lib/error.c \
+diff --git a/src/additionalFile.c b/src/additionalFile.c
+deleted file mode 100644
+index 34d683d..0000000
+--- a/src/additionalFile.c
++++ /dev/null
+@@ -1,6 +0,0 @@
+-#include "config.h"
+-#include "system.h"
+-
+-int somefunc() {
+-    return 0;
+-}
+diff --git a/src/hello.c b/src/hello.c
+index df67de2..768285a 100644
+--- a/src/hello.c
++++ b/src/hello.c
+@@ -36,6 +36,10 @@ static const struct option longopts[] = {
+ static void print_help (void);
+ static void print_version (void);
+ 
++int somefunc() {
++    return 1;
++}
++
+ int
+ main (int argc, char *argv[])
+ {
+diff --git a/tests/hello-1 b/tests/hello-1
+index e15fa95..3b7a815 100755
+--- a/tests/hello-1
++++ b/tests/hello-1
+@@ -21,7 +21,7 @@ export LANGUAGE LC_ALL LC_MESSAGES LANG
+ 
+ tmpfiles="hello-test1.ok"
+ cat <<EOF > hello-test1.ok
+-Hello, world!
++Hello, incremental world!
+ EOF
+ 
+ tmpfiles="$tmpfiles hello-test1.out"
diff --git a/pkgs/test/incrementalBuild/hello.patch b/pkgs/test/incrementalBuild/hello.patch
new file mode 100644
index 0000000000000..3d0d50c2f20e4
--- /dev/null
+++ b/pkgs/test/incrementalBuild/hello.patch
@@ -0,0 +1,26 @@
+diff --git a/src/hello.c b/src/hello.c
+index 182303c..453962f 100644
+--- a/src/hello.c
++++ b/src/hello.c
+@@ -57,7 +57,7 @@ main (int argc, char *argv[])
+ #endif
+ 
+   /* Having initialized gettext, get the default message. */
+-  greeting_msg = _("Hello, world!");
++  greeting_msg = _("Hello, incremental world!");
+ 
+   /* Even exiting has subtleties.  On exit, if any writes failed, change
+      the exit status.  The /dev/full device on GNU/Linux can be used for
+diff --git a/tests/hello-1 b/tests/hello-1
+index 3b7a815..e15fa95 100755
+--- a/tests/hello-1
++++ b/tests/hello-1
+@@ -21,7 +21,7 @@ export LANGUAGE LC_ALL LC_MESSAGES LANG
+ 
+ tmpfiles="hello-test1.ok"
+ cat <<EOF > hello-test1.ok
+-Hello, world!
++Hello, incremental world!
+ EOF
+ 
+ tmpfiles="$tmpfiles hello-test1.out"