Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | # |
| 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. |
| 23 | CCACHE_TOP_DIR ?= "${TMPDIR}/ccache" |
| 24 | |
| 25 | # ccahe removes CCACHE_BASEDIR from file path, so that hashes will be the same |
| 26 | # in different builds. |
| 27 | export CCACHE_BASEDIR ?= "${TMPDIR}" |
| 28 | |
| 29 | # Used for sharing cache files after compiler is rebuilt |
| 30 | export CCACHE_COMPILERCHECK ?= "%compiler% -dumpspecs" |
| 31 | |
| 32 | export CCACHE_CONFIGPATH ?= "${COREBASE}/meta/conf/ccache.conf" |
| 33 | |
| 34 | export CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${MULTIMACH_TARGET_SYS}/${PN}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 36 | # Fixed errors: |
| 37 | # ccache: error: Failed to create directory /run/user/0/ccache-tmp: Permission denied |
| 38 | export CCACHE_TEMPDIR ?= "${CCACHE_DIR}/tmp" |
| 39 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 40 | # 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. |
| 44 | export CCACHE_NOHASHDIR ?= "1" |
| 45 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 46 | python() { |
| 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 Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 52 | if not (bb.data.inherits_class("native", d) or |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 53 | bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))): |
Andrew Geissler | 706d5aa | 2021-02-12 15:55:30 -0600 | [diff] [blame] | 54 | d.appendVar('DEPENDS', ' ccache-native') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 55 | d.setVar('CCACHE', 'ccache ') |
| 56 | } |
| 57 | |
| 58 | addtask cleanccache after do_clean |
| 59 | python 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 | } |
| 69 | addtask cleanall after do_cleanccache |
| 70 | do_cleanccache[nostamp] = "1" |