blob: f00fafc292a4562b9c552a73681aee8470c2fc46 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001#
2# Usage:
Andrew Geisslerc723b722021-01-08 16:14:09 -06003# - Install ccache package on the host distribution and set up a build directory
4#
Brad Bishop19323692019-04-05 15:28:33 -04005# - Enable ccache
6# Add the following line to a conffile such as conf/local.conf:
7# INHERIT += "ccache"
8#
9# - Disable ccache for a recipe
10# Add the following line to the recipe if it can't be built with ccache:
11# CCACHE_DISABLE = '1'
12#
13# - Share ccache files between different builds
14# Set CCACHE_TOP_DIR to a shared dir
15# CCACHE_TOP_DIR = /path/to/shared_ccache/
16#
17# - TO debug ccahe
18# export CCACHE_DEBUG = "1"
19# export CCACHE_LOGFILE = "${CCACHE_DIR}/logfile.log"
20# And also set PARALLEL_MAKE = "-j 1" to get make the log in order
21#
22
23# Set it to a shared location for different builds, so that cache files can
24# be shared between different builds.
25CCACHE_TOP_DIR ?= "${TMPDIR}/ccache"
26
27# ccahe removes CCACHE_BASEDIR from file path, so that hashes will be the same
28# in different builds.
29export CCACHE_BASEDIR ?= "${TMPDIR}"
30
31# Used for sharing cache files after compiler is rebuilt
32export CCACHE_COMPILERCHECK ?= "%compiler% -dumpspecs"
33
34export CCACHE_CONFIGPATH ?= "${COREBASE}/meta/conf/ccache.conf"
35
36export CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${MULTIMACH_TARGET_SYS}/${PN}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
Andrew Geisslerc723b722021-01-08 16:14:09 -060038# Fixed errors:
39# ccache: error: Failed to create directory /run/user/0/ccache-tmp: Permission denied
40export CCACHE_TEMPDIR ?= "${CCACHE_DIR}/tmp"
41
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042# We need to stop ccache considering the current directory or the
43# debug-prefix-map target directory to be significant when calculating
44# its hash. Without this the cache would be invalidated every time
45# ${PV} or ${PR} change.
46export CCACHE_NOHASHDIR ?= "1"
47
Brad Bishop19323692019-04-05 15:28:33 -040048python() {
49 """
50 Enable ccache for the recipe
51 """
52 pn = d.getVar('PN')
53 # quilt-native doesn't need ccache since no c files
54 if not (pn in ('ccache-native', 'quilt-native') or
55 bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))):
Brad Bishop19323692019-04-05 15:28:33 -040056 d.setVar('CCACHE', 'ccache ')
57}
58
59addtask cleanccache after do_clean
60python do_cleanccache() {
61 import shutil
62
63 ccache_dir = d.getVar('CCACHE_DIR')
64 if os.path.exists(ccache_dir):
65 bb.note("Removing %s" % ccache_dir)
66 shutil.rmtree(ccache_dir)
67 else:
68 bb.note("%s doesn't exist" % ccache_dir)
69}
70addtask cleanall after do_cleanccache
71do_cleanccache[nostamp] = "1"