diff --git a/elements/base/README.md b/elements/base/README.md index b88a603f..e1746c29 100644 --- a/elements/base/README.md +++ b/elements/base/README.md @@ -10,3 +10,8 @@ Notes: This may be as simple as having language-pack-XX installed in the pre-install stage + * This element ensures /tmp/ccache will be available in the chroot + during the root, extra-data, pre-install, install and post-install + stages. /tmp/ccache is unavailable during block-device, finalise + and cleanup stages as it will have been automatically unmounted + by then. diff --git a/elements/base/cleanup.d/01-ccache b/elements/base/cleanup.d/01-ccache new file mode 100755 index 00000000..fd23437a --- /dev/null +++ b/elements/base/cleanup.d/01-ccache @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +# As this is run in cleanup, it's already been automatically unmounted, +# so all we need to do here is remove the directory +sudo rmdir $TMP_MOUNT_PATH/tmp/ccache || true diff --git a/elements/base/finalise.d/02-remove-ccache b/elements/base/finalise.d/02-remove-ccache deleted file mode 100755 index b550f726..00000000 --- a/elements/base/finalise.d/02-remove-ccache +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e - -rmdir /tmp/ccache || true diff --git a/elements/base/root.d/01-ccache b/elements/base/root.d/01-ccache new file mode 100755 index 00000000..2bad4646 --- /dev/null +++ b/elements/base/root.d/01-ccache @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +# Don't do anything if already mounted (if disk-image-create is invoked with +# no elements specified, this hook actually fires twice, once during +# `run_d root` for the base element, then again when `run_d root` is called +# after automatically pulling in the Ubuntu element) +grep " $TMP_MOUNT_PATH/tmp/ccache" /proc/mounts && exit + +DIB_CCACHE_DIR=${DIB_CCACHE_DIR:-$HOME/.cache/image-create/ccache} +mkdir -p $DIB_CCACHE_DIR + +sudo mkdir -p $TMP_MOUNT_PATH/tmp/ccache +sudo mount --bind $DIB_CCACHE_DIR $TMP_MOUNT_PATH/tmp/ccache diff --git a/lib/common-functions b/lib/common-functions index 19df7c4e..712f2c87 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -241,8 +241,10 @@ function create_base () { export TMP_MOUNT_PATH=$TMP_BUILD_DIR/mnt # Copy data in to the root. TARGET_ROOT=$TMP_MOUNT_PATH run_d root - if [ -z "$(ls $TMP_MOUNT_PATH | grep -v lost+found)" ] ; then - # Nothing copied in, use Ubuntu. + if [ -z "$(ls $TMP_MOUNT_PATH | grep -v '^lost+found\|tmp$')" ] ; then + # Nothing copied in, use Ubuntu. Note the test above allows + # root.d elements to put things in /tmp, and still have the + # automatic Ubuntu behaviour. echo "Adding ubuntu element as / had no contents" IMAGE_ELEMENT=$($SCRIPT_HOME/element-info --expand-dependencies $IMAGE_ELEMENT ubuntu) generate_hooks diff --git a/lib/img-defaults b/lib/img-defaults index 8054a539..31419515 100644 --- a/lib/img-defaults +++ b/lib/img-defaults @@ -20,4 +20,3 @@ FS_TYPE=${FS_TYPE:-ext4} # Used to set the file extension only at this stage. IMAGE_TYPE=${IMAGE_TYPE:-qcow2} IMAGE_NAME=${IMAGE_NAME:-image} -DIB_CCACHE_DIR=${DIB_CCACHE_DIR:-~/.cache/image-create/ccache} diff --git a/lib/img-functions b/lib/img-functions index cfb3f548..7d0f51e9 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -75,9 +75,6 @@ function run_d_in_target () { sudo mkdir $TMP_MOUNT_PATH/tmp/in_target.d sudo mount --bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d sudo mount -o remount,ro,bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d - sudo mkdir -p $TMP_MOUNT_PATH/tmp/ccache - mkdir -p $DIB_CCACHE_DIR - sudo mount --bind $DIB_CCACHE_DIR $TMP_MOUNT_PATH/tmp/ccache check_break before-$1 run_in_target bash trap "check_break after-error run_in_target bash" ERR run_in_target dib-run-parts /tmp/in_target.d/$1.d