poky/meta/classes/ccache.bbclass
Robert Yang e96d0200ca ccache.bbclass: Set CCACHE_CONFIGPATH to fix race issues
Fixed race issues when parallel build:
ccache: error: /path/to/ccache/i586-poky-linux/mmc-utils/ccache.conf: No such file or directory
ccache: error: /path/to/ccache/i586-poky-linux/mmc-utils/ccache.conf: No such file or directory

This is because we set CCACHE_DIR for earch recipe, and ccache will create a
ccache.conf for each CCACHE_DIR when CCACHE_CONFIGPATH is not set, but there
might be a race issue in parallel build:

ccache gcc file1.c
ccache gcc file2.c

If the two ccache processes use fopen(path, "w") to create ccache.conf at the
same time, the error would happen. Set CCACHE_CONFIGPATH to
meta/conf/ccache.conf can fix the problem, and we can add other configs to the
file when needed.

And also set cache_dir_levels to 1 (default is 2) since each recipe has a cache
dir, thus we don't have too many files in one dir.

(From OE-Core rev: 2abbc4d0cd571e82ed6188d3b2d84b4cd6be25e8)

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2019-01-14 11:35:55 +00:00

67 lines
2.0 KiB
Plaintext

#
# Usage:
# - Enable ccache
# Add the following line to a conffile such as conf/local.conf:
# INHERIT += "ccache"
#
# - Disable ccache for a recipe
# Add the following line to the recipe if it can't be built with ccache:
# CCACHE_DISABLE = '1'
#
# - Share ccache files between different builds
# Set CCACHE_TOP_DIR to a shared dir
# CCACHE_TOP_DIR = /path/to/shared_ccache/
#
# - TO debug ccahe
# export CCACHE_DEBUG = "1"
# export CCACHE_LOGFILE = "${CCACHE_DIR}/logfile.log"
# And also set PARALLEL_MAKE = "-j 1" to get make the log in order
#
# Set it to a shared location for different builds, so that cache files can
# be shared between different builds.
CCACHE_TOP_DIR ?= "${TMPDIR}/ccache"
# ccahe removes CCACHE_BASEDIR from file path, so that hashes will be the same
# in different builds.
export CCACHE_BASEDIR ?= "${TMPDIR}"
# Used for sharing cache files after compiler is rebuilt
export CCACHE_COMPILERCHECK ?= "%compiler% -dumpspecs"
export CCACHE_CONFIGPATH ?= "${COREBASE}/meta/conf/ccache.conf"
export CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${MULTIMACH_TARGET_SYS}/${PN}"
# We need to stop ccache considering the current directory or the
# debug-prefix-map target directory to be significant when calculating
# its hash. Without this the cache would be invalidated every time
# ${PV} or ${PR} change.
export CCACHE_NOHASHDIR ?= "1"
python() {
"""
Enable ccache for the recipe
"""
pn = d.getVar('PN')
# quilt-native doesn't need ccache since no c files
if not (pn in ('ccache-native', 'quilt-native') or
bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))):
d.appendVar('DEPENDS', ' ccache-native')
d.setVar('CCACHE', 'ccache ')
}
addtask cleanccache after do_clean
python do_cleanccache() {
import shutil
ccache_dir = d.getVar('CCACHE_DIR')
if os.path.exists(ccache_dir):
bb.note("Removing %s" % ccache_dir)
shutil.rmtree(ccache_dir)
else:
bb.note("%s doesn't exist" % ccache_dir)
}
addtask cleanall after do_cleanccache
do_cleanccache[nostamp] = "1"