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