diskimage-builder/diskimage_builder/elements/base/root.d/01-ccache

20 lines
611 B
Text
Raw Normal View History

Move /tmp/ccache setup to base element Commit c7d80dd (Cleanup mount points automatically) removed the unmount of $TMP_MOUNT_PATH/tmp/ccache in run_d_in_target() and moved the "rm /tmp/ccache" to elements/base/finalise.d/02-remove-ccache. There are two problems with this: 1) Not unmounting at the end of run_d_in_target() results in tmp/ccache being bind mounted muliple times on top of itself (three times, if you just run `disk-image-create base`). It is eventually unmounted, but somehow the auto unmount code is confused, and tries to unmount it one more time than it was mounted, which results in an error like "umount: /tmp/image.THQkZxQa/mnt/tmp/ccache: not mounted". This doesn't actually break anything, but it's a little messy. 2) "rm /tmp/ccache" in elements/base/finalise.d/02-remove-ccache never succeeds in removing /tmp/ccache, because that hook is invoked by run_d_in_target(), *while* /tmp/ccache is mounted. This present commit solves the above by moving the ccache setup glue out of img-functions and into the base element's root.d. This has the following implications: 1) lib/img-functions is a little cleaner. 2) /tmp/ccache is available in the chroot during the root, extra-data, pre-install, install and post-install stages. It is not available during block-device, finalise and cleanup stages as it will have been automatically unmounted by then. 3) /tmp/ccache won't be setup if you're building an image that doesn't include the base element. Change-Id: Ief4c0a6f4ec622db6c6f652776215684178d8943
2013-10-08 12:53:16 +00:00
#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
Move /tmp/ccache setup to base element Commit c7d80dd (Cleanup mount points automatically) removed the unmount of $TMP_MOUNT_PATH/tmp/ccache in run_d_in_target() and moved the "rm /tmp/ccache" to elements/base/finalise.d/02-remove-ccache. There are two problems with this: 1) Not unmounting at the end of run_d_in_target() results in tmp/ccache being bind mounted muliple times on top of itself (three times, if you just run `disk-image-create base`). It is eventually unmounted, but somehow the auto unmount code is confused, and tries to unmount it one more time than it was mounted, which results in an error like "umount: /tmp/image.THQkZxQa/mnt/tmp/ccache: not mounted". This doesn't actually break anything, but it's a little messy. 2) "rm /tmp/ccache" in elements/base/finalise.d/02-remove-ccache never succeeds in removing /tmp/ccache, because that hook is invoked by run_d_in_target(), *while* /tmp/ccache is mounted. This present commit solves the above by moving the ccache setup glue out of img-functions and into the base element's root.d. This has the following implications: 1) lib/img-functions is a little cleaner. 2) /tmp/ccache is available in the chroot during the root, extra-data, pre-install, install and post-install stages. It is not available during block-device, finalise and cleanup stages as it will have been automatically unmounted by then. 3) /tmp/ccache won't be setup if you're building an image that doesn't include the base element. Change-Id: Ief4c0a6f4ec622db6c6f652776215684178d8943
2013-10-08 12:53:16 +00:00
# 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:-$DIB_IMAGE_CACHE/ccache}
Move /tmp/ccache setup to base element Commit c7d80dd (Cleanup mount points automatically) removed the unmount of $TMP_MOUNT_PATH/tmp/ccache in run_d_in_target() and moved the "rm /tmp/ccache" to elements/base/finalise.d/02-remove-ccache. There are two problems with this: 1) Not unmounting at the end of run_d_in_target() results in tmp/ccache being bind mounted muliple times on top of itself (three times, if you just run `disk-image-create base`). It is eventually unmounted, but somehow the auto unmount code is confused, and tries to unmount it one more time than it was mounted, which results in an error like "umount: /tmp/image.THQkZxQa/mnt/tmp/ccache: not mounted". This doesn't actually break anything, but it's a little messy. 2) "rm /tmp/ccache" in elements/base/finalise.d/02-remove-ccache never succeeds in removing /tmp/ccache, because that hook is invoked by run_d_in_target(), *while* /tmp/ccache is mounted. This present commit solves the above by moving the ccache setup glue out of img-functions and into the base element's root.d. This has the following implications: 1) lib/img-functions is a little cleaner. 2) /tmp/ccache is available in the chroot during the root, extra-data, pre-install, install and post-install stages. It is not available during block-device, finalise and cleanup stages as it will have been automatically unmounted by then. 3) /tmp/ccache won't be setup if you're building an image that doesn't include the base element. Change-Id: Ief4c0a6f4ec622db6c6f652776215684178d8943
2013-10-08 12:53:16 +00:00
mkdir -p $DIB_CCACHE_DIR
sudo mkdir -p $TMP_MOUNT_PATH/tmp/ccache
sudo mount --bind $DIB_CCACHE_DIR $TMP_MOUNT_PATH/tmp/ccache