mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-12 01:11:29 +00:00
mk-sbuild: Add support to configure ccache for each schroot
ccache can help greatly in speeding up recompilations in sbuild, but it is a bit annoying to configure at each schroot creation. So, add --cache option (and relative CCACHE config parameter) to configure ccache for sbuild schroots. By default we use a shared ccache directory, but each schroot can use a customized one if needed (with local parameters) by using --cache-dir (or CCACHE_DIR). Default ccache max-size is 4G, but can be configured with --ccache-size (or CCACHE_SIZE), the size value is applied to each ccache path, so can be shared by multiple schroots or applied to a single one.
This commit is contained in:
parent
4e5e6efdb1
commit
2ac69a89e3
@ -87,6 +87,21 @@ aufs) mounts.
|
|||||||
Specify a \fBSCHROOT_TYPE\fR. Supported values are "\fBdirectory\fR"
|
Specify a \fBSCHROOT_TYPE\fR. Supported values are "\fBdirectory\fR"
|
||||||
(default if \fB\-\-vg\fR not specified), "\fBlvm-snapshot\fR" (default
|
(default if \fB\-\-vg\fR not specified), "\fBlvm-snapshot\fR" (default
|
||||||
if \fB\-\-vg\fR specified), "\fBbtrfs-snapshot\fR", and "\fBfile\fR".
|
if \fB\-\-vg\fR specified), "\fBbtrfs-snapshot\fR", and "\fBfile\fR".
|
||||||
|
.TP
|
||||||
|
.B \-\-ccache
|
||||||
|
Enable usage of \fBccache\fR by default. See \fBccache\fR (1) for
|
||||||
|
more details.
|
||||||
|
.TP
|
||||||
|
.B \-\-ccache-dir=\fIPATH
|
||||||
|
Use \fBPATH\fR as schroot ccache directory. This directory can be
|
||||||
|
safely shared by multiple schroots, but they will all use the same
|
||||||
|
\fBCCACHE_MAXSIZE\fR.
|
||||||
|
Defaults to /var/cache/ccache-sbuild.
|
||||||
|
See \fBccache\fR (1) for more details.
|
||||||
|
.TP
|
||||||
|
.B \-\-ccache-size=\fISIZE
|
||||||
|
Sets \fBSIZE\fR as the schroot \fBCCACHE_DIR\fR max-size used by ccache.
|
||||||
|
See \fBccache\fR (1) for more details.
|
||||||
|
|
||||||
.SH ENVIRONMENT VARIABLES
|
.SH ENVIRONMENT VARIABLES
|
||||||
.TP
|
.TP
|
||||||
@ -148,6 +163,18 @@ Use \fBSOURCE_CHROOTS_TGZ\fR as home of schroot source tarballs.
|
|||||||
.B CHROOT_SNAPSHOT_DIR
|
.B CHROOT_SNAPSHOT_DIR
|
||||||
Use \fBCHROOT_SNAPSHOT_DIR\fR as home of mounted btrfs snapshots.
|
Use \fBCHROOT_SNAPSHOT_DIR\fR as home of mounted btrfs snapshots.
|
||||||
(default \fB/var/lib/schroot/snapshots\fR)
|
(default \fB/var/lib/schroot/snapshots\fR)
|
||||||
|
.TP
|
||||||
|
.B CCACHE
|
||||||
|
Enable \fBccache\fR (1) by default.
|
||||||
|
(defaults to \fB0\fR)
|
||||||
|
.TP
|
||||||
|
.B CCACHE_DIR
|
||||||
|
Use \fBCCACHE_DIR\fR as the \fBccache\fR (1) directory.
|
||||||
|
(default \fB/var/cache/ccache-sbuild\fR)
|
||||||
|
.TP
|
||||||
|
.B CCACHE_SIZE
|
||||||
|
Use \fBCCACHE_SIZE\fR as the \fBccache\fR (1) max-size.
|
||||||
|
(defaults to \fB4G\fR)
|
||||||
|
|
||||||
|
|
||||||
.SH FILES
|
.SH FILES
|
||||||
|
79
mk-sbuild
Normal file → Executable file
79
mk-sbuild
Normal file → Executable file
@ -40,6 +40,8 @@ SOURCE_CHROOTS_DIR="/var/lib/schroot/chroots"
|
|||||||
SOURCE_CHROOTS_TGZ="/var/lib/schroot/tarballs"
|
SOURCE_CHROOTS_TGZ="/var/lib/schroot/tarballs"
|
||||||
CHROOT_SNAPSHOT_DIR="/var/lib/schroot/snapshots"
|
CHROOT_SNAPSHOT_DIR="/var/lib/schroot/snapshots"
|
||||||
SCHROOT_PROFILE="sbuild"
|
SCHROOT_PROFILE="sbuild"
|
||||||
|
CCACHE_DIR="/var/cache/ccache-sbuild"
|
||||||
|
CCACHE_SIZE="4G"
|
||||||
|
|
||||||
function usage()
|
function usage()
|
||||||
{
|
{
|
||||||
@ -64,6 +66,11 @@ function usage()
|
|||||||
echo " --debootstrap-no-check-gpg Disables checking gpg signatures of retrieved Release files"
|
echo " --debootstrap-no-check-gpg Disables checking gpg signatures of retrieved Release files"
|
||||||
echo " --skip-eatmydata Don't install and use eatmydata"
|
echo " --skip-eatmydata Don't install and use eatmydata"
|
||||||
echo " --eatmydata Install and use eatmydata (default)"
|
echo " --eatmydata Install and use eatmydata (default)"
|
||||||
|
echo " --ccache Install configure and use ccache as default"
|
||||||
|
echo " --ccache-dir=PATH Sets the CCACHE_DIR to PATH"
|
||||||
|
echo " (can be shared between all schroots, defaults to ${CCACHE_DIR})"
|
||||||
|
echo " --ccache-size=SIZE Sets the ccache max-size to SIZE"
|
||||||
|
echo " (shared by each CCACHE_DIR, defaults to ${CCACHE_SIZE})"
|
||||||
echo " --distro=DISTRO Install specific distro:"
|
echo " --distro=DISTRO Install specific distro:"
|
||||||
echo " 'ubuntu' or 'debian' "
|
echo " 'ubuntu' or 'debian' "
|
||||||
echo " (defaults to determining from release name)"
|
echo " (defaults to determining from release name)"
|
||||||
@ -91,6 +98,11 @@ function usage()
|
|||||||
echo " DEBOOTSTRAP_KEYRING GPG keyring (same as --debootstrap-keyring)"
|
echo " DEBOOTSTRAP_KEYRING GPG keyring (same as --debootstrap-keyring)"
|
||||||
echo " DEBOOTSTRAP_NO_CHECK_GPG Disable GPG verification (same as --debootstrap-no-check-gpg)"
|
echo " DEBOOTSTRAP_NO_CHECK_GPG Disable GPG verification (same as --debootstrap-no-check-gpg)"
|
||||||
echo " EATMYDATA Enable or disable eatmydata usage, see --eatmydata and --skip-eatmydata"
|
echo " EATMYDATA Enable or disable eatmydata usage, see --eatmydata and --skip-eatmydata"
|
||||||
|
echo " CCACHE Enable --ccache"
|
||||||
|
echo " CCACHE_DIR Path for ccache (can be shared between all schroots, "
|
||||||
|
echo " same as --ccache-dir, default ${CCACHE_DIR})"
|
||||||
|
echo " CCACHE_SIZE Sets the ccache max-size (shared by each CCACHE_DIR, "
|
||||||
|
echo " same as --ccache-size, default ${CCACHE_SIZE})"
|
||||||
echo " TEMPLATE_SOURCES A template for sources.list"
|
echo " TEMPLATE_SOURCES A template for sources.list"
|
||||||
echo " TEMPLATE_SCHROOTCONF A template for schroot.conf stanza"
|
echo " TEMPLATE_SCHROOTCONF A template for schroot.conf stanza"
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
@ -110,6 +122,7 @@ supported_options=(
|
|||||||
skip-security
|
skip-security
|
||||||
skip-proposed
|
skip-proposed
|
||||||
skip-eatmydata
|
skip-eatmydata
|
||||||
|
ccache
|
||||||
arch:
|
arch:
|
||||||
name:
|
name:
|
||||||
source-template:
|
source-template:
|
||||||
@ -125,16 +138,20 @@ supported_options=(
|
|||||||
vg:
|
vg:
|
||||||
type:
|
type:
|
||||||
target:
|
target:
|
||||||
|
ccache-dir:
|
||||||
|
ccache-size:
|
||||||
)
|
)
|
||||||
OPTS=$(getopt -o 'h' --long "$(IFS=, && echo "${supported_options[*]}")" -- "$@")
|
OPTS=$(getopt -o 'h' --long "$(IFS=, && echo "${supported_options[*]}")" -- "$@")
|
||||||
eval set -- "$OPTS"
|
eval set -- "$OPTS"
|
||||||
|
|
||||||
VG=""
|
VG=""
|
||||||
DISTRO=""
|
DISTRO=""
|
||||||
|
COMMAND_PREFIX=""
|
||||||
name=""
|
name=""
|
||||||
proxy="_unset_"
|
proxy="_unset_"
|
||||||
DEBOOTSTRAP_NO_CHECK_GPG=0
|
DEBOOTSTRAP_NO_CHECK_GPG=0
|
||||||
EATMYDATA=1
|
EATMYDATA=1
|
||||||
|
CCACHE=0
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -215,6 +232,10 @@ while :; do
|
|||||||
EATMYDATA=0
|
EATMYDATA=0
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--ccache)
|
||||||
|
CCACHE=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--distro)
|
--distro)
|
||||||
DISTRO="$2"
|
DISTRO="$2"
|
||||||
shift 2
|
shift 2
|
||||||
@ -231,6 +252,14 @@ while :; do
|
|||||||
TARGET_ARCH="$2"
|
TARGET_ARCH="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--ccache-dir)
|
||||||
|
CCACHE_DIR="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--ccache-size)
|
||||||
|
CCACHE_SIZE="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
@ -427,6 +456,51 @@ if [ $EATMYDATA -eq 1 ]; then
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $CCACHE -eq 1 ]; then
|
||||||
|
if [ -z "$CCACHE_DIR" ] || [[ "$(dirname "$CCACHE_DIR")" == '/' ]]; then
|
||||||
|
echo "Invalid ccache dir: ${CCACHE_DIR}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# We can safely use a global cache path, in such case changing size applies
|
||||||
|
# to all the schroots
|
||||||
|
setup_script="$CCACHE_DIR"/mk-sbuild-setup
|
||||||
|
if [ -d "$CCACHE_DIR" ]; then
|
||||||
|
echo "Reusing $CCACHE_DIR as CCACHE_DIR, will be configured to use max-size=${CCACHE_SIZE}"
|
||||||
|
rm -f "$setup_script"
|
||||||
|
else
|
||||||
|
echo "Configuring $CCACHE_DIR as CCACHE_DIR with max-size=${CCACHE_SIZE}"
|
||||||
|
sudo install --group=sbuild --mode=2775 -d "$CCACHE_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -x "$setup_script" ]; then
|
||||||
|
cat <<END | sudo tee "$setup_script" 1>/dev/null
|
||||||
|
#!/bin/sh
|
||||||
|
export CCACHE_DIR="$CCACHE_DIR"
|
||||||
|
export CCACHE_MAXSIZE="${CCACHE_SIZE}"
|
||||||
|
export CCACHE_UMASK=002
|
||||||
|
export CCACHE_COMPRESS=1
|
||||||
|
unset CCACHE_HARDLINK
|
||||||
|
export CCACHE_NOHARDLINK=1
|
||||||
|
export PATH="/usr/lib/ccache:\$PATH"
|
||||||
|
exec "\$@"
|
||||||
|
END
|
||||||
|
sudo chmod a+rx "$setup_script"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! sudo grep -qs "$CCACHE_DIR" /etc/schroot/sbuild/fstab; then
|
||||||
|
# This acts on host configuration, but there is no other way to handle
|
||||||
|
# this, however it won't affect anything
|
||||||
|
cat <<END | sudo tee -a /etc/schroot/sbuild/fstab 1>/dev/null
|
||||||
|
${CCACHE_DIR} ${CCACHE_DIR} none rw,bind 0 0
|
||||||
|
END
|
||||||
|
fi
|
||||||
|
|
||||||
|
DEBOOTSTRAP_INCLUDE="${DEBOOTSTRAP_INCLUDE:+$DEBOOTSTRAP_INCLUDE,}ccache"
|
||||||
|
BUILD_PKGS="$BUILD_PKGS ccache"
|
||||||
|
COMMAND_PREFIX="${COMMAND_PREFIX:+$COMMAND_PREFIX,}$setup_script"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$SCHROOT_TYPE" ]; then
|
if [ -z "$SCHROOT_TYPE" ]; then
|
||||||
# To build the LV, we need to know which volume group to use
|
# To build the LV, we need to know which volume group to use
|
||||||
if [ -n "$VG" ]; then
|
if [ -n "$VG" ]; then
|
||||||
@ -810,6 +884,11 @@ root-groups=$ADMIN_GROUPS
|
|||||||
type=SCHROOT_TYPE
|
type=SCHROOT_TYPE
|
||||||
profile=$SCHROOT_PROFILE
|
profile=$SCHROOT_PROFILE
|
||||||
EOM
|
EOM
|
||||||
|
if [ -n "$COMMAND_PREFIX" ]; then
|
||||||
|
cat >> "$TEMP_SCHROOTCONF" <<EOM
|
||||||
|
command-prefix=${COMMAND_PREFIX}
|
||||||
|
EOM
|
||||||
|
fi
|
||||||
case "$SCHROOT_TYPE" in
|
case "$SCHROOT_TYPE" in
|
||||||
"lvm-snapshot")
|
"lvm-snapshot")
|
||||||
cat >> "$TEMP_SCHROOTCONF" <<EOM
|
cat >> "$TEMP_SCHROOTCONF" <<EOM
|
||||||
|
Loading…
x
Reference in New Issue
Block a user