Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 8 | # 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. |
| 29 | CCACHE_TOP_DIR ?= "${TMPDIR}/ccache" |
| 30 | |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 31 | # ccache-native and cmake-native have a circular dependency |
| 32 | # that affects other native recipes, but not all. |
| 33 | # Allows to use ccache in specified native recipes. |
| 34 | CCACHE_NATIVE_RECIPES_ALLOWED ?= "" |
| 35 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 | # ccahe removes CCACHE_BASEDIR from file path, so that hashes will be the same |
| 37 | # in different builds. |
| 38 | export CCACHE_BASEDIR ?= "${TMPDIR}" |
| 39 | |
| 40 | # Used for sharing cache files after compiler is rebuilt |
| 41 | export CCACHE_COMPILERCHECK ?= "%compiler% -dumpspecs" |
| 42 | |
| 43 | export CCACHE_CONFIGPATH ?= "${COREBASE}/meta/conf/ccache.conf" |
| 44 | |
| 45 | export CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${MULTIMACH_TARGET_SYS}/${PN}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 47 | # Fixed errors: |
| 48 | # ccache: error: Failed to create directory /run/user/0/ccache-tmp: Permission denied |
| 49 | export CCACHE_TEMPDIR ?= "${CCACHE_DIR}/tmp" |
| 50 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | # We need to stop ccache considering the current directory or the |
| 52 | # debug-prefix-map target directory to be significant when calculating |
| 53 | # its hash. Without this the cache would be invalidated every time |
| 54 | # ${PV} or ${PR} change. |
| 55 | export CCACHE_NOHASHDIR ?= "1" |
| 56 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 57 | python() { |
| 58 | """ |
| 59 | Enable ccache for the recipe |
| 60 | """ |
| 61 | pn = d.getVar('PN') |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 62 | if (pn in d.getVar('CCACHE_NATIVE_RECIPES_ALLOWED') or |
| 63 | not (bb.data.inherits_class("native", d) or |
| 64 | bb.utils.to_boolean(d.getVar('CCACHE_DISABLE')))): |
Andrew Geissler | 706d5aa | 2021-02-12 15:55:30 -0600 | [diff] [blame] | 65 | d.appendVar('DEPENDS', ' ccache-native') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 66 | d.setVar('CCACHE', 'ccache ') |
| 67 | } |
| 68 | |
| 69 | addtask cleanccache after do_clean |
| 70 | python do_cleanccache() { |
| 71 | import shutil |
| 72 | |
| 73 | ccache_dir = d.getVar('CCACHE_DIR') |
| 74 | if os.path.exists(ccache_dir): |
| 75 | bb.note("Removing %s" % ccache_dir) |
| 76 | shutil.rmtree(ccache_dir) |
| 77 | else: |
| 78 | bb.note("%s doesn't exist" % ccache_dir) |
| 79 | } |
| 80 | addtask cleanall after do_cleanccache |
| 81 | do_cleanccache[nostamp] = "1" |