| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | # | 
|  | 2 | # Usage: | 
| Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 3 | # - Install ccache package on the host distribution and set up a build directory | 
|  | 4 | # | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 5 | # - 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. | 
|  | 25 | CCACHE_TOP_DIR ?= "${TMPDIR}/ccache" | 
|  | 26 |  | 
|  | 27 | # ccahe removes CCACHE_BASEDIR from file path, so that hashes will be the same | 
|  | 28 | # in different builds. | 
|  | 29 | export CCACHE_BASEDIR ?= "${TMPDIR}" | 
|  | 30 |  | 
|  | 31 | # Used for sharing cache files after compiler is rebuilt | 
|  | 32 | export CCACHE_COMPILERCHECK ?= "%compiler% -dumpspecs" | 
|  | 33 |  | 
|  | 34 | export CCACHE_CONFIGPATH ?= "${COREBASE}/meta/conf/ccache.conf" | 
|  | 35 |  | 
|  | 36 | export CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${MULTIMACH_TARGET_SYS}/${PN}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 |  | 
| Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 38 | # Fixed errors: | 
|  | 39 | # ccache: error: Failed to create directory /run/user/0/ccache-tmp: Permission denied | 
|  | 40 | export CCACHE_TEMPDIR ?= "${CCACHE_DIR}/tmp" | 
|  | 41 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | # 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. | 
|  | 46 | export CCACHE_NOHASHDIR ?= "1" | 
|  | 47 |  | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 48 | python() { | 
|  | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 56 | d.setVar('CCACHE', 'ccache ') | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | addtask cleanccache after do_clean | 
|  | 60 | python 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 | } | 
|  | 70 | addtask cleanall after do_cleanccache | 
|  | 71 | do_cleanccache[nostamp] = "1" |