ccache and cowbuilder

Install ccache on your host, and setup cache folder to 1GiB maximum size:

sudo apt-get install ccache
sudo mkdir /var/cache/ccache
sudo CCACHE_DIR=/var/cache/ccache ccache -M 1G

Prepare hook to install ccache and fixup permissions:

# cat /tmp/ccache/D01ccache
#!/bin/bash

apt-get install ccache

chown -R pbuilder /var/cache/ccache

Prepare config file

# cat /tmp/ccache/env
export CCACHE_DIR=/var/cache/ccache
export PATH=/usr/lib/ccache:$PATH

Build a source package

sudo cowbuilder --build dtach_0.8-2.1.dsc --basepath
/tmp/jessie.amd64.cow --hookdir /tmp/ccache --buildplace /tmp
--bindmounts /var/cache/ccache --configfile /tmp/ccache/env

The --bindmounts option will provide the host’s ccache to cowbuilder, --hookdir installs ccache inside and --configfile actually enables ccache.

Use CCACHE_DIR=/var/cache/ccache ccache -s to checkout cache usage, e.g.

cache directory                     /var/cache/ccache
primary config                      /var/cache/ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
cache hit (direct)                  3492
cache hit (preprocessed)             227
cache miss                          2483
cache hit rate                     59.96 %
called for link                      466
called for preprocessing             114
compile failed                        23
preprocessor error                    36
bad compiler arguments                 6
autoconf compile/link                 85
no input file                         73
cleanups performed                     0
files in cache                      4835
cache size                         567.8 MB
max cache size                       1.0 GB