1#
2# Usage:
3# - Enable ccache
4#   Add the following line to a conffile such as conf/local.conf:
5#   INHERIT += "ccache"
6#
7# - Disable ccache for a recipe
8#   Add the following line to the recipe if it can't be built with ccache:
9#   CCACHE_DISABLE = '1'
10#
11# - Share ccache files between different builds
12#   Set CCACHE_TOP_DIR to a shared dir
13#   CCACHE_TOP_DIR = /path/to/shared_ccache/
14#
15# - TO debug ccahe
16#   export CCACHE_DEBUG = "1"
17#   export CCACHE_LOGFILE = "${CCACHE_DIR}/logfile.log"
18#   And also set PARALLEL_MAKE = "-j 1" to get make the log in order
19#
20
21# Set it to a shared location for different builds, so that cache files can
22# be shared between different builds.
23CCACHE_TOP_DIR ?= "${TMPDIR}/ccache"
24
25# ccahe removes CCACHE_BASEDIR from file path, so that hashes will be the same
26# in different builds.
27export CCACHE_BASEDIR ?= "${TMPDIR}"
28
29# Used for sharing cache files after compiler is rebuilt
30export CCACHE_COMPILERCHECK ?= "%compiler% -dumpspecs"
31
32export CCACHE_CONFIGPATH ?= "${COREBASE}/meta/conf/ccache.conf"
33
34export CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${MULTIMACH_TARGET_SYS}/${PN}"
35
36# We need to stop ccache considering the current directory or the
37# debug-prefix-map target directory to be significant when calculating
38# its hash. Without this the cache would be invalidated every time
39# ${PV} or ${PR} change.
40export CCACHE_NOHASHDIR ?= "1"
41
42python() {
43    """
44    Enable ccache for the recipe
45    """
46    pn = d.getVar('PN')
47    # quilt-native doesn't need ccache since no c files
48    if not (pn in ('ccache-native', 'quilt-native') or
49            bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))):
50        d.appendVar('DEPENDS', ' ccache-native')
51        d.setVar('CCACHE', 'ccache ')
52}
53
54addtask cleanccache after do_clean
55python do_cleanccache() {
56    import shutil
57
58    ccache_dir = d.getVar('CCACHE_DIR')
59    if os.path.exists(ccache_dir):
60        bb.note("Removing %s" % ccache_dir)
61        shutil.rmtree(ccache_dir)
62    else:
63        bb.note("%s doesn't exist" % ccache_dir)
64}
65addtask cleanall after do_cleanccache
66do_cleanccache[nostamp] = "1"
67