Use ccache to cache all compiles between builds.

Many python extensions are built from source each time an image is
built. Repeating these is wasteful, so ccache is employed to eliminate
that waste. A cache dir outside the chroot is used to speed up
subsequent image builds.

Change-Id: Ib73563ddbe5f3be7454bfc54ab91cedb559a1304
This commit is contained in:
Clint Byrum 2013-07-09 15:03:58 -07:00
parent 3464064a87
commit f6cc6bb185
5 changed files with 15 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,2 @@
#!/bin/bash
install-packages ccache

View File

@ -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}

View File

@ -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
}

View File

@ -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