changeset 1817:92d542aa6ceb

Teach system-image.sh to handle its own dependencies, rebuilding kernel and repackaging cpio/squashfs as appropraite, and _not_ doing so when unneeded.
author Rob Landley <rob@landley.net>
date Sun, 22 Nov 2015 14:54:16 -0600
parents fb05f99ffcce
children 78bdf7e5f5b3
files build.sh sources/functions.sh system-image.sh
diffstat 3 files changed, 49 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/build.sh	Sat Nov 21 16:44:39 2015 -0600
+++ b/build.sh	Sun Nov 22 14:54:16 2015 -0600
@@ -81,6 +81,7 @@
   done
 }
 
+# If $AFTER set, skip stages until we match $AFTER to implement $2="start here"
 do_stage()
 {
   STAGE="$1"
@@ -95,10 +96,12 @@
 }
 
 # The first two stages (download.sh and host-tools.sh) are architecture
-# independent.  In order to allow multiple builds in parallel, re-running
+# independent. In order to allow multiple builds in parallel, re-running
 # them after they've already completed must be a safe NOP.
 
-# Download source code.
+# Download source code. If tarballs already there, verify sha1sums and
+# delete/redownload if they don't match (to handle interrupted partial
+# download).
 
 do_stage download
 
@@ -116,7 +119,7 @@
 then
   # If we need to build cross compiler, assume root filesystem is stale.
 
-  zap root-filesystem cross-compiler native-compiler system-image
+  zap root-filesystem cross-compiler native-compiler
 
   do_stage simple-cross-compiler "$ARCH"
 fi
@@ -128,7 +131,7 @@
 if [ -z "$MY_CROSS_PATH" ] && [ ! -z "$CROSS_COMPILER_HOST" ] &&
   not_already cross-compiler
 then
-  zap root-filesystem native-compiler system-image
+  zap root-filesystem native-compiler
 
   # Build the host compiler if necessary
 
@@ -149,9 +152,6 @@
 
 if not_already root-filesystem
 then
-  zap system-image
-  [ "$SYSIMAGE_TYPE" == rootfs ] && zap system-image
-
   do_stage root-filesystem "$ARCH"
 fi
 
@@ -163,14 +163,10 @@
 if [ -z "$MY_CROSS_PATH" ] && ! grep -q ELF2FLT sources/targets/"$ARCH" &&
   not_already native-compiler
 then
-  zap system-image
-
   do_stage native-compiler "$ARCH"
 fi
 
-# Package it all up into something qemu can boot.
+# Package it all up into something qemu can boot. Like host-tools.sh,
+# this is always called and handles its own dependencies internally.
 
-if not_already system-image
-then
-  do_stage system-image "$ARCH"
-fi
+do_stage system-image "$ARCH"
--- a/sources/functions.sh	Sat Nov 21 16:44:39 2015 -0600
+++ b/sources/functions.sh	Sun Nov 22 14:54:16 2015 -0600
@@ -73,7 +73,7 @@
 
   STAGE_DIR="$BUILD/${STAGE_NAME}-${ARCH_NAME}"
 
-  blank_tempdir "$STAGE_DIR"
+  [ -z "$KEEP_STAGEDIR" ] && blank_tempdir "$STAGE_DIR"
   NO_CLEANUP=${NO_CLEANUP/temp//} blank_tempdir "$WORK"
 
   export PATH="$(cc_path "$ARCH")$PATH"
--- a/system-image.sh	Sat Nov 21 16:44:39 2015 -0600
+++ b/system-image.sh	Sun Nov 22 14:54:16 2015 -0600
@@ -1,14 +1,31 @@
 #!/bin/bash
 
-# Combine a filesystem image and kernel with emulator launch scripts.
-
-# Package a root filesystem directory into a filesystem image file
+# Combine filesystem images, kernel, and emulator launch scripts
+# into something you can boot and run.
 
 source sources/include.sh || exit 1
 
-# Parse sources/targets/$1
+# We do our own dependency checking (like host-tool.sh) so don't delete stage
+# dir when parsing sources/targets/$1
 
-load_target "$1"
+KEEP_STAGEDIR=1 load_target "$1"
+
+# Is $1 newer than cross compiler and all listed prerequisites ($2...)?
+
+is_newer()
+{
+  X="$1"
+  shift
+  [ ! -e "$X" ] && return 0
+  [ "$(which "${CC_PREFIX}cc")" -nt "$X" ] && return 0
+  while [ ! -z "$1" ]
+  do
+    [ ! -z "$(find "$X" -newer "$X" 2>/dev/null)" ] && return 0
+    shift
+  done
+
+  return 1
+}
 
 # Provide qemu's common command line options between architectures.
 
@@ -65,17 +82,27 @@
 
 # Package root-filesystem into cpio file for initramfs
 
-SYSIMAGE_TYPE=cpio image_filesystem "$BUILD/root-filesystem-$ARCH" \
-  "$STAGE_DIR/rootfs" &&
-if [ -d "$BUILD/native-compiler-$ARCH" ]
+if is_newer "$STAGE_DIR/rootfs.cpio.gz" "$BUILD/root-filesystem-$ARCH"
+then
+  SYSIMAGE_TYPE=cpio image_filesystem "$BUILD/root-filesystem-$ARCH" \
+    "$STAGE_DIR/temp" &&
+    mv -f "$STAGE_DIR"/{temp,rootfs}.cpio.gz || dienow
+  [ "$SYSIMAGE_TYPE" == rootfs ] && rm -f "$STAGE_DIR/linux"
+fi
+
+# Package native-compiler into squashfs for /dev/hda mount
+
+if is_newer "$STAGE_DIR/toolchain.sqf" "$BUILD/native-compiler-$ARCH"
 then
   SYSIMAGE_TYPE=squashfs image_filesystem "$BUILD/native-compiler-$ARCH" \
-    "$STAGE_DIR/toolchain" || dienow
+    "$STAGE_DIR/temp" &&
+    mv -f "$STAGE_DIR"/{temp,toolchain}.sqf || dienow
 fi
 
 # Build linux kernel for the target
 
-if [ -z "$NO_CLEANUP" ] || [ ! -e "$STAGE_DIR/linux" ]
+if is_newer "$STAGE_DIR/linux" "$BUILD/root-filesystem-$ARCH" \
+  $(package_cache linux)
 then
   setupfor linux
   getconfig linux > mini.conf
@@ -88,6 +115,7 @@
   cp "$KERNEL_PATH" "$STAGE_DIR/linux"
   cleanup
 fi
+
 # Tar it up.
 
 ARCH="$ARCH_NAME" create_stage_tarball