[Pbuilder-maint] Bug#430765: please add ccache support
Steinar H. Gunderson
sesse at debian.org
Wed Jun 27 08:34:11 UTC 2007
Package: pbuilder
Version: 0.170
Severity: wishlist
Tags: patch
Hi,
As discussed on the boat under DebConf, here's a patch to enable ccache
support in pbuilder. I've only tested it lightly, but it seems to work
well.
-- System Information:
Debian Release: lenny/sid
APT prefers oldstable
APT policy: (500, 'oldstable'), (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: i386 (i686)
Kernel: Linux 2.6.22-rc4 (SMP w/2 CPU cores; PREEMPT)
Locale: LANG=nb_NO.UTF-8, LC_CTYPE=nb_NO.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages pbuilder depends on:
ii cdebootstrap 0.4.3 Bootstrap a Debian system
ii coreutils 5.97-5.3 The GNU core utilities
ii debianutils 2.21.1 Miscellaneous utilities specific t
ii debootstrap 1.0.0 Bootstrap a basic Debian system
ii gcc 4:4.1.2-3 The GNU C compiler
ii wget 1.10.2-3 retrieves files from the web
Versions of packages pbuilder recommends:
ii cowdancer 0.36 Copy-on-write directory tree utili
ii devscripts 2.10.5 Scripts to make the life of a Debi
ii fakeroot 1.7.1 Gives a fake root environment
ii sudo 1.6.8p12-5 Provide limited super user privile
-- no debconf information
-------------- next part --------------
diff -Nru /tmp/MNKC25Sy4K/pbuilder-0.170/debian/dirs /tmp/iIhIKpSUZF/pbuilder-0.171/debian/dirs
--- /tmp/MNKC25Sy4K/pbuilder-0.170/debian/dirs 2007-01-07 06:53:01.000000000 +0100
+++ /tmp/iIhIKpSUZF/pbuilder-0.171/debian/dirs 2007-06-27 01:17:22.000000000 +0200
@@ -4,4 +4,5 @@
var/cache/pbuilder
var/cache/pbuilder/result
var/cache/pbuilder/aptcache
+var/cache/pbuilder/ccache
diff -Nru /tmp/MNKC25Sy4K/pbuilder-0.170/Documentation/pbuilder-doc.xml /tmp/iIhIKpSUZF/pbuilder-0.171/Documentation/pbuilder-doc.xml
--- /tmp/MNKC25Sy4K/pbuilder-0.170/Documentation/pbuilder-doc.xml 2007-06-25 14:09:46.000000000 +0200
+++ /tmp/iIhIKpSUZF/pbuilder-0.171/Documentation/pbuilder-doc.xml 2007-06-27 10:24:41.000000000 +0200
@@ -1496,6 +1496,23 @@
<command>ccapabilities</command> of this vserver.
</para>
</sect1>
+ <sect1 id="ccache">
+ <title>Using pbuilder with ccache</title>
+ <para>
+ It is possible to use the C compiler cache <command>ccache</command>
+ together with <command>pbuilder</command> to speed up repeated builds of
+ the same package (or packages that compile the same files multiple times
+ for some reason). Using <command>ccache</command> can speed up repeated
+ building of large packages dramatically, at the cost of some disk space
+ and bookkeeping.
+ </para>
+ <para>
+ To use <command>pbuilder</command> with <command>ccache</command>, you
+ will need to give the command <command>--use-ccache</command> both
+ when creating the initial chroot and when building. Optionally, you
+ can set <command>USE_CCACHE="yes"</command> in your pbuilderrc file.
+ </para>
+ </sect1>
</chapter>
<chapter id="refs">
<title>Reference materials</title>
@@ -1536,6 +1553,10 @@
<entry>Default location <command>pbuilder</command> will use as apt cache, to store deb packages required during <command>pbuilder</command> build.</entry>
</row>
<row>
+ <entry><filename>/var/cache/pbuilder/ccache</filename></entry>
+ <entry>Default location <command>pbuilder</command> will use as ccache location, if ccache is enabled</entry>
+ </row>
+ <row>
<entry><filename>/var/cache/pbuilder/result</filename></entry>
<entry>Default location <command>pbuilder</command> puts the deb files and other files created after build</entry>
</row>
@@ -1614,6 +1635,13 @@
</entry>
</row>
<row>
+ <entry><filename>/var/cache/pbuilder/ccache</filename></entry>
+ <entry>
+ <command>pbuilder</command> copies the content of this directory to and from
+ the ccache directory of outside chroot, if ccache is enabled.
+ </entry>
+ </row>
+ <row>
<entry><filename>/tmp/XXXX</filename></entry>
<entry><command>pbuilder-user-mode-linux</command> uses
a script in <filename>/tmp</filename> to bootstrap into
diff -Nru /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilder-buildpackage /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilder-buildpackage
--- /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilder-buildpackage 2007-05-28 13:37:29.000000000 +0200
+++ /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilder-buildpackage 2007-06-27 10:03:22.000000000 +0200
@@ -43,6 +43,10 @@
BUILDUSERNAME=root
fi
+if [ "${USE_CCACHE}" = "yes" ]; then
+ echo "I: using ccache in build, cache is in ${CCACHE_LOCATION}."
+fi
+
# created files should have these UID/GIDs outside of chroot.
BUILDRESULTUID="${BUILDRESULTUID:-${SUDO_UID:-0}}"
@@ -111,14 +117,33 @@
exit 1;
fi
+if [ "${USE_CCACHE}" = "yes" ]; then
+ recover_ccache
+
+ if echo "chown -R $BUILDUSERNAME:$BUILDUSERNAME /var/cache/pbuilder/ccache" | $CHROOTEXEC /bin/bash; then
+ : # success
+ else
+ echo "E: pbuilder: Failed chowning to $BUILDUSERNAME:$BUILDUSERNAME" >&2
+ exit 1;
+ fi
+fi
+
echo " -> Building the package"
executehooks "A"
-if [ -z "$DEBEMAIL" ]; then
- DPKG_COMMANDLINE="cd tmp/buildd/*/; dpkg-buildpackage -us -uc $DEBBUILDOPTS"
+if [ "${USE_CCACHE}" = "yes" ]; then
+ if [ -z "$DEBEMAIL" ]; then
+ DPKG_COMMANDLINE="cd tmp/buildd/*/; PATH=/usr/lib/ccache:\"\$PATH\" CCACHE_DIR=/var/cache/pbuilder/ccache dpkg-buildpackage -us -uc $DEBBUILDOPTS"
+ else
+ DPKG_COMMANDLINE="cd tmp/buildd/*/; PATH=/usr/lib/ccache:\"\$PATH\" CCACHE_DIR=/var/cache/pbuilder/ccache dpkg-buildpackage -us -uc \"-m$DEBEMAIL\" $DEBBUILDOPTS"
+ fi
else
- DPKG_COMMANDLINE="cd tmp/buildd/*/; dpkg-buildpackage -us -uc \"-m$DEBEMAIL\" $DEBBUILDOPTS"
+ if [ -z "$DEBEMAIL" ]; then
+ DPKG_COMMANDLINE="cd tmp/buildd/*/; dpkg-buildpackage -us -uc $DEBBUILDOPTS"
+ else
+ DPKG_COMMANDLINE="cd tmp/buildd/*/; dpkg-buildpackage -us -uc \"-m$DEBEMAIL\" $DEBBUILDOPTS"
+ fi
fi
(
@@ -152,6 +177,11 @@
trap umountproc_cleanbuildplace_trap exit sighup
executehooks "B"
save_aptcache
+
+if [ "${USE_CCACHE}" = "yes" ]; then
+ save_ccache
+fi
+
trap cleanbuildplace_trap exit sighup
umountproc
diff -Nru /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilder-checkparams /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilder-checkparams
--- /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilder-checkparams 2007-05-17 13:33:25.000000000 +0200
+++ /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilder-checkparams 2007-06-27 01:25:02.000000000 +0200
@@ -31,6 +31,7 @@
BINARY_ARCH="no"
PBUILDER_BUILD_LOGFILE=
PRESERVE_BUILDPLACE="no"
+CCACHE_LOCATION="/var/cache/pbuilder/ccache"
unset EXTRA_CONFIGFILE || true
PBUILDER_DEBUGMODE=
SAVE_AFTER_LOGIN=
@@ -184,6 +185,15 @@
DEBOOTSTRAP="$2";
shift; shift;
;;
+ --use-ccache)
+ # Use this option to enable ccache in the chroot
+ USE_CCACHE="yes";
+ shift;
+ ;;
+ --ccache-location)
+ CCACHE_LOCATION="$2";
+ shift; shift;
+ ;;
--save-after-login|--save-after-exec)
SAVE_AFTER_LOGIN=yes;
shift;
diff -Nru /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilder-createbuildenv /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilder-createbuildenv
--- /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilder-createbuildenv 2007-05-27 12:52:01.000000000 +0200
+++ /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilder-createbuildenv 2007-06-27 02:25:54.000000000 +0200
@@ -28,6 +28,11 @@
fi
echo "Distribution is $DISTRIBUTION."
+if [ "${USE_CCACHE}" = "yes" ]; then
+ echo "Will install ccache into chroot."
+ EXTRAPACKAGES="$EXTRAPACKAGES ccache"
+fi
+
if [ "${PBUILDER_DEBUGMODE}" = "yes" ]; then
TRAP="echo ignoring trap "
else
@@ -91,6 +96,10 @@
$CHROOTEXEC /usr/bin/apt-get -y --force-yes install build-essential dpkg-dev apt $EXTRAPACKAGES
save_aptcache
+if [ "${USE_CCACHE}" = "yes" ]; then
+ mkdir -p "$BUILDPLACE/var/cache/pbuilder/ccache"
+fi
+
executehooks "E"
unloadhooks
umountproc
diff -Nru /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilder-modules /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilder-modules
--- /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilder-modules 2007-05-27 07:18:59.000000000 +0200
+++ /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilder-modules 2007-06-27 10:18:41.000000000 +0200
@@ -75,6 +75,8 @@
--debootstrapopts [debootstrap options]
--save-after-login/--save-after-exec
--debootstrap [debootstrap|cdebootstrap]
+ --use-ccache
+ --ccache-location [path]
pdebuild-specific pbuilder-options:
--pbuilderroot [command to obtain root privilege for pbuilder]
@@ -411,6 +413,46 @@
fi
}
+function recover_ccache() {
+ local doit
+ # recover the ccache archive
+ if [ -n "${USE_CCACHE}" ]; then
+ if [ "$CCACHEHARDLINK" = "yes" ]; then
+ doit=ln
+ else
+ doit=cp
+ fi
+ echo "Obtaining the compiler cache contents"
+
+ rm -rf "$BUILDPLACE/var/cache/pbuilder/ccache/"*
+
+ # copy over everything
+ cp --preserve=timestamps -R "${CCACHE_LOCATION}/"* "$BUILDPLACE"/var/cache/pbuilder/ccache/
+ fi
+}
+
+function save_ccache() {
+ # save the current ccache archive, cleaning out the old one
+ local doit
+ if [ -n "${CCACHE_LOCATION}" ]; then
+ echo "Copying back the compiler cache contents"
+ mkdir -p "${CCACHE_LOCATION}" ;
+ if [ "${CCACHE_HARDLINK}" = "yes" ]; then
+ doit=ln
+ else
+ doit=cp
+ fi
+
+ # sanity check before deleting
+ if [ -n "${CCACHE_LOCATION}/stats" ]; then
+ rm -rf "${CCACHE_LOCATION}"/*
+ fi
+
+ # copy over everything
+ cp --preserve=timestamps -R "$BUILDPLACE"/var/cache/pbuilder/ccache/* "${CCACHE_LOCATION}/"
+ fi
+}
+
function create_basetgz() {
# create base.tgz
(
diff -Nru /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilderrc /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilderrc
--- /tmp/MNKC25Sy4K/pbuilder-0.170/pbuilderrc 2007-06-25 14:09:46.000000000 +0200
+++ /tmp/iIhIKpSUZF/pbuilder-0.171/pbuilderrc 2007-06-27 02:13:48.000000000 +0200
@@ -78,3 +78,8 @@
# default PKGNAME_LOGFILE
PKGNAME_LOGFILE=""
+
+# speed up builds by using the compiler cache (optional)
+USE_CCACHE="no"
+CCACHE_LOCATION="/var/cache/pbuilder/ccache"
+CCACHE_HARDLINK="yes"
More information about the Pbuilder-maint
mailing list