blob: 34becb69d10a36af69416d910476d631c6a376c9 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7#
Brad Bishop19323692019-04-05 15:28:33 -04008# Usage:
9# - Enable ccache
10# Add the following line to a conffile such as conf/local.conf:
11# INHERIT += "ccache"
12#
13# - Disable ccache for a recipe
14# Add the following line to the recipe if it can't be built with ccache:
15# CCACHE_DISABLE = '1'
16#
17# - Share ccache files between different builds
18# Set CCACHE_TOP_DIR to a shared dir
19# CCACHE_TOP_DIR = /path/to/shared_ccache/
20#
21# - TO debug ccahe
22# export CCACHE_DEBUG = "1"
23# export CCACHE_LOGFILE = "${CCACHE_DIR}/logfile.log"
24# And also set PARALLEL_MAKE = "-j 1" to get make the log in order
25#
26
27# Set it to a shared location for different builds, so that cache files can
28# be shared between different builds.
29CCACHE_TOP_DIR ?= "${TMPDIR}/ccache"
30
31# ccahe removes CCACHE_BASEDIR from file path, so that hashes will be the same
32# in different builds.
33export CCACHE_BASEDIR ?= "${TMPDIR}"
34
35# Used for sharing cache files after compiler is rebuilt
36export CCACHE_COMPILERCHECK ?= "%compiler% -dumpspecs"
37
38export CCACHE_CONFIGPATH ?= "${COREBASE}/meta/conf/ccache.conf"
39
40export CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${MULTIMACH_TARGET_SYS}/${PN}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041
Andrew Geisslerd1e89492021-02-12 15:35:20 -060042# Fixed errors:
43# ccache: error: Failed to create directory /run/user/0/ccache-tmp: Permission denied
44export CCACHE_TEMPDIR ?= "${CCACHE_DIR}/tmp"
45
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046# We need to stop ccache considering the current directory or the
47# debug-prefix-map target directory to be significant when calculating
48# its hash. Without this the cache would be invalidated every time
49# ${PV} or ${PR} change.
50export CCACHE_NOHASHDIR ?= "1"
51
Brad Bishop19323692019-04-05 15:28:33 -040052python() {
53 """
54 Enable ccache for the recipe
55 """
56 pn = d.getVar('PN')
57 # quilt-native doesn't need ccache since no c files
Andrew Geisslerd1e89492021-02-12 15:35:20 -060058 if not (bb.data.inherits_class("native", d) or
Brad Bishop19323692019-04-05 15:28:33 -040059 bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))):
Andrew Geissler706d5aa2021-02-12 15:55:30 -060060 d.appendVar('DEPENDS', ' ccache-native')
Brad Bishop19323692019-04-05 15:28:33 -040061 d.setVar('CCACHE', 'ccache ')
62}
63
64addtask cleanccache after do_clean
65python do_cleanccache() {
66 import shutil
67
68 ccache_dir = d.getVar('CCACHE_DIR')
69 if os.path.exists(ccache_dir):
70 bb.note("Removing %s" % ccache_dir)
71 shutil.rmtree(ccache_dir)
72 else:
73 bb.note("%s doesn't exist" % ccache_dir)
74}
75addtask cleanall after do_cleanccache
76do_cleanccache[nostamp] = "1"