[Libguestfs] [supermin PATCH 4/4] build: set kernel/initrd/root as outputs (RHBZ#1813809)

Pino Toscano ptoscano at redhat.com
Fri Apr 3 10:20:58 UTC 2020


Return the kernel, initrd, and root files as outputs for this mode when
the output format is ext2, so --if-newer will check whether they exist
or they are old.

Add a simple test to verify this behaviour.
---
 src/mode_build.ml           |  7 ++++-
 tests/Makefile.am           |  3 +-
 tests/test-if-newer-ext2.sh | 57 +++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100755 tests/test-if-newer-ext2.sh

diff --git a/src/mode_build.ml b/src/mode_build.ml
index 4a58460..ed47366 100644
--- a/src/mode_build.ml
+++ b/src/mode_build.ml
@@ -468,4 +468,9 @@ and get_outputs
      packager_config, tmpdir, use_installed, size,
      include_packagelist)
     inputs =
-  []
+  match format with
+  | Chroot ->
+    (* The content for chroot depends on the packages. *)
+    []
+  | Ext2 ->
+    [kernel_filename; appliance_filename; initrd_filename]
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 42d1b82..070f6d9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,7 +28,8 @@ TESTS = \
 	test-execstack.sh \
 	test-build-bash.sh \
 	test-binaries-exist.sh \
-	test-harder.sh
+	test-harder.sh \
+	test-if-newer-ext2.sh
 
 if NETWORK_TESTS
 TESTS += \
diff --git a/tests/test-if-newer-ext2.sh b/tests/test-if-newer-ext2.sh
new file mode 100755
index 0000000..4f49bda
--- /dev/null
+++ b/tests/test-if-newer-ext2.sh
@@ -0,0 +1,57 @@
+#!/bin/bash -
+# supermin
+# (C) Copyright 2009-2020 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+set -e
+
+# XXX Hack for Arch.
+if [ -f /etc/arch-release ]; then
+    export SUPERMIN_KERNEL=/boot/vmlinuz-linux
+fi
+
+tmpdir=`mktemp -d`
+
+d1=$tmpdir/d1
+d2=$tmpdir/d2
+
+# We assume 'bash' is a package everywhere.
+../src/supermin -v --prepare --use-installed bash -o $d1
+
+run_supermin ()
+{
+  ../src/supermin -v --build -f ext2 --if-newer $d1 -o $d2
+}
+
+# Build the appliance the first time, which will work.
+run_supermin
+
+# No changes, hence nothing to do.
+run_supermin | grep 'if-newer: output does not need rebuilding'
+
+# Try removing any of the files, and check that supermin will detect that.
+ext2_files="kernel initrd root"
+for ext2_file in $ext2_files
+do
+  rm $d2/$ext2_file
+  run_supermin
+  for ext2_file in $ext2_files
+  do
+    test -e $d2/$ext2_file
+  done
+done
+
+rm -rf $tmpdir ||:
-- 
2.25.1




More information about the Libguestfs mailing list