blob: 4532894c574ededab69a51e7e4ee4d9dfddc30e3 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001#
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}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035
Andrew Geisslerd1e89492021-02-12 15:35:20 -060036# Fixed errors:
37# ccache: error: Failed to create directory /run/user/0/ccache-tmp: Permission denied
38export CCACHE_TEMPDIR ?= "${CCACHE_DIR}/tmp"
39
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040# We need to stop ccache considering the current directory or the
41# debug-prefix-map target directory to be significant when calculating
42# its hash. Without this the cache would be invalidated every time
43# ${PV} or ${PR} change.
44export CCACHE_NOHASHDIR ?= "1"
45
Brad Bishop19323692019-04-05 15:28:33 -040046python() {
47 """
48 Enable ccache for the recipe
49 """
50 pn = d.getVar('PN')
51 # quilt-native doesn't need ccache since no c files
Andrew Geisslerd1e89492021-02-12 15:35:20 -060052 if not (bb.data.inherits_class("native", d) or
Brad Bishop19323692019-04-05 15:28:33 -040053 bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))):
Andrew Geissler706d5aa2021-02-12 15:55:30 -060054 d.appendVar('DEPENDS', ' ccache-native')
Brad Bishop19323692019-04-05 15:28:33 -040055 d.setVar('CCACHE', 'ccache ')
56}
57
58addtask cleanccache after do_clean
59python do_cleanccache() {
60 import shutil
61
62 ccache_dir = d.getVar('CCACHE_DIR')
63 if os.path.exists(ccache_dir):
64 bb.note("Removing %s" % ccache_dir)
65 shutil.rmtree(ccache_dir)
66 else:
67 bb.note("%s doesn't exist" % ccache_dir)
68}
69addtask cleanall after do_cleanccache
70do_cleanccache[nostamp] = "1"