diff --git a/elements/base/environment.d/10-ccache.bash b/elements/base/environment.d/10-ccache.bash new file mode 100644 index 00000000..2d3d5f2d --- /dev/null +++ b/elements/base/environment.d/10-ccache.bash @@ -0,0 +1,5 @@ +# Put ccache in path for known compilers +if ! [[ "$PATH" =~ "/usr/lib/ccache" ]] ; then + export PATH=/usr/lib/ccache:$PATH +fi +export CCACHE_DIR=/tmp/ccache diff --git a/elements/base/install.d/00-ccache b/elements/base/install.d/00-ccache new file mode 100755 index 00000000..1aa5e415 --- /dev/null +++ b/elements/base/install.d/00-ccache @@ -0,0 +1,2 @@ +#!/bin/bash +install-packages ccache diff --git a/lib/img-defaults b/lib/img-defaults index 31419515..8054a539 100644 --- a/lib/img-defaults +++ b/lib/img-defaults @@ -20,3 +20,4 @@ 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 ca95c44e..951892cb 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -20,6 +20,7 @@ function unmount_image () { sudo umount -f $TMP_BUILD_DIR/mnt/proc || true sudo umount -f $TMP_BUILD_DIR/mnt/dev || true sudo umount -f $TMP_BUILD_DIR/mnt/tmp/in_target.d || true + sudo umount -f $TMP_BUILD_DIR/mnt/tmp/ccache || true # give it a second (ok really 5) to umount XXX - why? should instead track # the mount data / lsof etc. sleep 5 @@ -73,11 +74,16 @@ 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 run_in_target dib-run-parts /tmp/in_target.d/$1.d check_break after-$1 run_in_target bash sudo umount -f $TMP_MOUNT_PATH/tmp/in_target.d sudo rmdir $TMP_MOUNT_PATH/tmp/in_target.d + sudo umount -f $TMP_MOUNT_PATH/tmp/ccache || true + sudo rmdir $TMP_MOUNT_PATH/tmp/ccache fi } diff --git a/sudoers.d/img-build-sudoers b/sudoers.d/img-build-sudoers index a679ba44..2bafc25e 100644 --- a/sudoers.d/img-build-sudoers +++ b/sudoers.d/img-build-sudoers @@ -20,6 +20,7 @@ ALL ALL=(root) NOPASSWD: /bin/mkdir -p /tmp/*/mnt/* ALL ALL=(root) NOPASSWD: /bin/mkdir /tmp/*/mnt/* ALL ALL=(root) NOPASSWD: /bin/mount --bind /dev /tmp/*/mnt/dev ALL ALL=(root) NOPASSWD: /bin/mount --bind /tmp/*/hooks /tmp/*/mnt/tmp/in_target.d +ALL ALL=(root) NOPASSWD: /bin/mount --bind */.cache/image-create/ccache /tmp/*/mnt/tmp/ccache ALL ALL=(root) NOPASSWD: /bin/mount -o remount\,ro\,bind /tmp/*/hooks /tmp/*/mnt/tmp/in_target.d ALL ALL=(root) NOPASSWD: /bin/mount -t proc none /tmp/*/mnt/proc ALL ALL=(root) NOPASSWD: /bin/mount -t sysfs none /tmp/*/mnt/sys