ccache.bbclass 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. #
  7. # Usage:
  8. # - Enable ccache
  9. # Add the following line to a conffile such as conf/local.conf:
  10. # INHERIT += "ccache"
  11. #
  12. # - Disable ccache for a recipe
  13. # Add the following line to the recipe if it can't be built with ccache:
  14. # CCACHE_DISABLE = '1'
  15. #
  16. # - Share ccache files between different builds
  17. # Set CCACHE_TOP_DIR to a shared dir
  18. # CCACHE_TOP_DIR = /path/to/shared_ccache/
  19. #
  20. # - TO debug ccahe
  21. # export CCACHE_DEBUG = "1"
  22. # export CCACHE_LOGFILE = "${CCACHE_DIR}/logfile.log"
  23. # And also set PARALLEL_MAKE = "-j 1" to get make the log in order
  24. #
  25. # Set it to a shared location for different builds, so that cache files can
  26. # be shared between different builds.
  27. CCACHE_TOP_DIR ?= "${TMPDIR}/ccache"
  28. # ccache-native and cmake-native have a circular dependency
  29. # that affects other native recipes, but not all.
  30. # Allows to use ccache in specified native recipes.
  31. CCACHE_NATIVE_RECIPES_ALLOWED ?= ""
  32. # ccahe removes CCACHE_BASEDIR from file path, so that hashes will be the same
  33. # in different builds.
  34. export CCACHE_BASEDIR ?= "${TMPDIR}"
  35. # Used for sharing cache files after compiler is rebuilt
  36. export CCACHE_COMPILERCHECK ?= "%compiler% -dumpspecs"
  37. export CCACHE_CONFIGPATH ?= "${COREBASE}/meta/conf/ccache.conf"
  38. export CCACHE_DIR ?= "${CCACHE_TOP_DIR}/${MULTIMACH_TARGET_SYS}/${PN}"
  39. # Fixed errors:
  40. # ccache: error: Failed to create directory /run/user/0/ccache-tmp: Permission denied
  41. export CCACHE_TEMPDIR ?= "${CCACHE_DIR}/tmp"
  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. python() {
  48. """
  49. Enable ccache for the recipe
  50. """
  51. pn = d.getVar('PN')
  52. if (pn in d.getVar('CCACHE_NATIVE_RECIPES_ALLOWED') or
  53. not (bb.data.inherits_class("native", d) or
  54. bb.utils.to_boolean(d.getVar('CCACHE_DISABLE')))):
  55. d.appendVar('DEPENDS', ' ccache-native')
  56. d.setVar('CCACHE', 'ccache ')
  57. }
  58. addtask cleanccache after do_clean
  59. python do_cleanccache() {
  60. import shutil
  61. ccache_dir = d.getVar('CCACHE_DIR')
  62. if os.path.exists(ccache_dir):
  63. bb.note("Removing %s" % ccache_dir)
  64. shutil.rmtree(ccache_dir)
  65. else:
  66. bb.note("%s doesn't exist" % ccache_dir)
  67. }
  68. addtask cleanall after do_cleanccache
  69. do_cleanccache[nostamp] = "1"