Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # IceCream distributed compiling support |
| 2 | # |
| 3 | # Stages directories with symlinks from gcc/g++ to icecc, for both |
| 4 | # native and cross compilers. Depending on each configure or compile, |
| 5 | # the directories are added at the head of the PATH list and ICECC_CXX |
| 6 | # and ICEC_CC are set. |
| 7 | # |
| 8 | # For the cross compiler, creates a tar.gz of our toolchain and sets |
| 9 | # ICECC_VERSION accordingly. |
| 10 | # |
| 11 | # The class now handles all 3 different compile 'stages' (i.e native ,cross-kernel and target) creating the |
| 12 | # necessary environment tar.gz file to be used by the remote machines. |
| 13 | # It also supports meta-toolchain generation |
| 14 | # |
| 15 | # If ICECC_PATH is not set in local.conf then the class will try to locate it using 'bb.utils.which' |
| 16 | # but nothing is sure ;) |
| 17 | # |
| 18 | # If ICECC_ENV_EXEC is set in local.conf, then it should point to the icecc-create-env script provided by the user |
| 19 | # or the default one provided by icecc-create-env.bb will be used |
| 20 | # (NOTE that this is a modified version of the script need it and *not the one that comes with icecc* |
| 21 | # |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 22 | # User can specify if specific recipes or recipes belonging to class should not use icecc to distribute |
| 23 | # compile jobs to remote machines, but handled locally, by defining ICECC_CLASS_DISABLE and ICECC_RECIPE_DISABLE |
| 24 | # with the appropriate values in local.conf. In addition the user can force to enable icecc for recipes |
| 25 | # which set an empty PARALLEL_MAKE variable by defining ICECC_RECIPE_ENABLE. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | # |
| 27 | ######################################################################################### |
| 28 | #Error checking is kept to minimum so double check any parameters you pass to the class |
| 29 | ########################################################################################### |
| 30 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 31 | BB_BASEHASH_IGNORE_VARS += "ICECC_PARALLEL_MAKE ICECC_DISABLED ICECC_RECIPE_DISABLE \ |
| 32 | ICECC_CLASS_DISABLE ICECC_RECIPE_ENABLE ICECC_PATH ICECC_ENV_EXEC \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 33 | ICECC_CARET_WORKAROUND ICECC_CFLAGS ICECC_ENV_VERSION \ |
| 34 | ICECC_DEBUG ICECC_LOGFILE ICECC_REPEAT_RATE ICECC_PREFERRED_HOST \ |
| 35 | ICECC_CLANG_REMOTE_CPP ICECC_IGNORE_UNVERIFIED ICECC_TEST_SOCKET \ |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 36 | ICECC_ENV_DEBUG ICECC_REMOTE_CPP \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 37 | " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | |
| 39 | ICECC_ENV_EXEC ?= "${STAGING_BINDIR_NATIVE}/icecc-create-env" |
| 40 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 41 | HOSTTOOLS_NONFATAL += "icecc patchelf" |
| 42 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 43 | # This version can be incremented when changes are made to the environment that |
| 44 | # invalidate the version on the compile nodes. Changing it will cause a new |
| 45 | # environment to be created. |
| 46 | # |
| 47 | # A useful thing to do for testing Icecream changes locally is to add a |
| 48 | # subversion in local.conf: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 49 | # ICECC_ENV_VERSION:append = "-my-ver-1" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 50 | ICECC_ENV_VERSION = "2" |
| 51 | |
| 52 | # Default to disabling the caret workaround, If set to "1" in local.conf, icecc |
| 53 | # will locally recompile any files that have warnings, which can adversely |
| 54 | # affect performance. |
| 55 | # |
| 56 | # See: https://github.com/icecc/icecream/issues/190 |
| 57 | export ICECC_CARET_WORKAROUND ??= "0" |
| 58 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 59 | export ICECC_REMOTE_CPP ??= "0" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 60 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 61 | ICECC_CFLAGS = "" |
| 62 | CFLAGS += "${ICECC_CFLAGS}" |
| 63 | CXXFLAGS += "${ICECC_CFLAGS}" |
| 64 | |
| 65 | # Debug flags when generating environments |
| 66 | ICECC_ENV_DEBUG ??= "" |
| 67 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 68 | # Disable recipe list contains a list of recipes that can not distribute |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 69 | # compile tasks for one reason or the other. When adding new entry, please |
| 70 | # document why (how it failed) so that we can re-evaluate it later e.g. when |
| 71 | # there is new version |
| 72 | # |
| 73 | # libgcc-initial - fails with CPP sanity check error if host sysroot contains |
| 74 | # cross gcc built for another target tune/variant |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 75 | # pixman - prng_state: TLS reference mismatches non-TLS reference, possibly due to |
| 76 | # pragma omp threadprivate(prng_state) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 77 | # systemtap - _HelperSDT.c undefs macros and uses the identifiers in macros emitting |
| 78 | # inline assembly |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 79 | # target-sdk-provides-dummy - ${HOST_PREFIX} is empty which triggers the "NULL |
| 80 | # prefix" error. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 81 | ICECC_RECIPE_DISABLE += "\ |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 82 | libgcc-initial \ |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 83 | pixman \ |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 84 | systemtap \ |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 85 | target-sdk-provides-dummy \ |
| 86 | " |
| 87 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 88 | # Classes that should not use icecc. When adding new entry, please |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 89 | # document why (how it failed) so that we can re-evaluate it later |
| 90 | # |
| 91 | # image - Image aren't compiling, but the testing framework for images captures |
| 92 | # PARALLEL_MAKE as part of the test environment. Many tests won't use |
| 93 | # icecream, but leaving the high level of parallelism can cause them to |
| 94 | # consume an unnecessary amount of resources. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 95 | ICECC_CLASS_DISABLE += "\ |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 96 | image \ |
| 97 | " |
| 98 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 99 | def get_icecc_dep(d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not |
| 101 | # we need that built is the responsibility of the patch function / class, not |
| 102 | # the application. |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 103 | if not d.getVar('INHIBIT_DEFAULT_DEPS'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | return "icecc-create-env-native" |
| 105 | return "" |
| 106 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 107 | DEPENDS:prepend = "${@get_icecc_dep(d)} " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 109 | get_cross_kernel_cc[vardepsexclude] += "KERNEL_CC" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | def get_cross_kernel_cc(bb,d): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 111 | if not icecc_is_kernel(bb, d): |
| 112 | return None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | |
| 114 | # evaluate the expression by the shell if necessary |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 115 | kernel_cc = d.getVar('KERNEL_CC') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 116 | if '`' in kernel_cc or '$(' in kernel_cc: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 117 | import subprocess |
| 118 | kernel_cc = subprocess.check_output("echo %s" % kernel_cc, shell=True).decode("utf-8")[:-1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | kernel_cc = kernel_cc.replace('ccache', '').strip() |
| 121 | kernel_cc = kernel_cc.split(' ')[0] |
| 122 | kernel_cc = kernel_cc.strip() |
| 123 | return kernel_cc |
| 124 | |
| 125 | def get_icecc(d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 126 | return d.getVar('ICECC_PATH') or bb.utils.which(os.getenv("PATH"), "icecc") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 128 | def use_icecc(bb,d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 129 | if d.getVar('ICECC_DISABLED') == "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | # don't even try it, when explicitly disabled |
| 131 | return "no" |
| 132 | |
| 133 | # allarch recipes don't use compiler |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 134 | if icecc_is_allarch(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | return "no" |
| 136 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 137 | if icecc_is_cross_canadian(bb, d): |
| 138 | return "no" |
| 139 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 140 | pn = d.getVar('PN') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 141 | bpn = d.getVar('BPN') |
| 142 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 143 | # Enable/disable checks are made against BPN, because there is a good |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 144 | # chance that if icecc should be skipped for a recipe, it should be skipped |
| 145 | # for all the variants of that recipe. PN is still checked in case a user |
| 146 | # specified a more specific recipe. |
| 147 | check_pn = set([pn, bpn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 148 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 149 | class_disable = (d.getVar('ICECC_CLASS_DISABLE') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 151 | for bbclass in class_disable: |
| 152 | if bb.data.inherits_class(bbclass, d): |
| 153 | bb.debug(1, "%s: bbclass %s found in disable, disable icecc" % (pn, bbclass)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | return "no" |
| 155 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 156 | disabled_recipes = (d.getVar('ICECC_RECIPE_DISABLE') or "").split() |
| 157 | enabled_recipes = (d.getVar('ICECC_RECIPE_ENABLE') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 158 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 159 | if check_pn & set(disabled_recipes): |
| 160 | bb.debug(1, "%s: found in disable list, disable icecc" % pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 161 | return "no" |
| 162 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 163 | if check_pn & set(enabled_recipes): |
| 164 | bb.debug(1, "%s: found in enabled recipes list, enable icecc" % pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | return "yes" |
| 166 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 167 | if d.getVar('PARALLEL_MAKE') == "": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | bb.debug(1, "%s: has empty PARALLEL_MAKE, disable icecc" % pn) |
| 169 | return "no" |
| 170 | |
| 171 | return "yes" |
| 172 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 173 | def icecc_is_allarch(bb, d): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 174 | return d.getVar("PACKAGE_ARCH") == "all" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 175 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 176 | def icecc_is_kernel(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 177 | return \ |
| 178 | bb.data.inherits_class("kernel", d); |
| 179 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 180 | def icecc_is_native(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 181 | return \ |
| 182 | bb.data.inherits_class("cross", d) or \ |
| 183 | bb.data.inherits_class("native", d); |
| 184 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 185 | def icecc_is_cross_canadian(bb, d): |
| 186 | return bb.data.inherits_class("cross-canadian", d) |
| 187 | |
| 188 | def icecc_dir(bb, d): |
| 189 | return d.expand('${TMPDIR}/work-shared/ice') |
| 190 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | # Don't pollute allarch signatures with TARGET_FPU |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 192 | icecc_version[vardepsexclude] += "TARGET_FPU" |
| 193 | def icecc_version(bb, d): |
| 194 | if use_icecc(bb, d) == "no": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 195 | return "" |
| 196 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 197 | parallel = d.getVar('ICECC_PARALLEL_MAKE') or "" |
| 198 | if not d.getVar('PARALLEL_MAKE') == "" and parallel: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | d.setVar("PARALLEL_MAKE", parallel) |
| 200 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 201 | # Disable showing the caret in the GCC compiler output if the workaround is |
| 202 | # disabled |
| 203 | if d.getVar('ICECC_CARET_WORKAROUND') == '0': |
| 204 | d.setVar('ICECC_CFLAGS', '-fno-diagnostics-show-caret') |
| 205 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 206 | if icecc_is_native(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 207 | archive_name = "local-host-env" |
| 208 | elif d.expand('${HOST_PREFIX}') == "": |
| 209 | bb.fatal(d.expand("${PN}"), " NULL prefix") |
| 210 | else: |
| 211 | prefix = d.expand('${HOST_PREFIX}' ) |
| 212 | distro = d.expand('${DISTRO}') |
| 213 | target_sys = d.expand('${TARGET_SYS}') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 214 | float = d.getVar('TARGET_FPU') or "hard" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 215 | archive_name = prefix + distro + "-" + target_sys + "-" + float |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 216 | if icecc_is_kernel(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 217 | archive_name += "-kernel" |
| 218 | |
| 219 | import socket |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 220 | ice_dir = icecc_dir(bb, d) |
| 221 | tar_file = os.path.join(ice_dir, "{archive}-{version}-@VERSION@-{hostname}.tar.gz".format( |
| 222 | archive=archive_name, |
| 223 | version=d.getVar('ICECC_ENV_VERSION'), |
| 224 | hostname=socket.gethostname() |
| 225 | )) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | |
| 227 | return tar_file |
| 228 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 229 | def icecc_path(bb,d): |
| 230 | if use_icecc(bb, d) == "no": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | # don't create unnecessary directories when icecc is disabled |
| 232 | return |
| 233 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 234 | staging = os.path.join(d.expand('${STAGING_BINDIR}'), "ice") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 235 | if icecc_is_kernel(bb, d): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 236 | staging += "-kernel" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 237 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 238 | return staging |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 240 | def icecc_get_external_tool(bb, d, tool): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | external_toolchain_bindir = d.expand('${EXTERNAL_TOOLCHAIN}${bindir_cross}') |
| 242 | target_prefix = d.expand('${TARGET_PREFIX}') |
| 243 | return os.path.join(external_toolchain_bindir, '%s%s' % (target_prefix, tool)) |
| 244 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 245 | def icecc_get_tool_link(tool, d): |
| 246 | import subprocess |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 247 | try: |
| 248 | return subprocess.check_output("readlink -f %s" % tool, shell=True).decode("utf-8")[:-1] |
| 249 | except subprocess.CalledProcessError as e: |
| 250 | bb.note("icecc: one of the tools probably disappeared during recipe parsing, cmd readlink -f %s returned %d:\n%s" % (tool, e.returncode, e.output.decode("utf-8"))) |
| 251 | return tool |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 252 | |
| 253 | def icecc_get_path_tool(tool, d): |
| 254 | # This is a little ugly, but we want to make sure we add an actual |
| 255 | # compiler to the toolchain, not ccache. Some distros (e.g. Fedora) |
| 256 | # have ccache enabled by default using symlinks PATH, meaning ccache |
| 257 | # would be found first when looking for the compiler. |
| 258 | paths = os.getenv("PATH").split(':') |
| 259 | while True: |
| 260 | p, hist = bb.utils.which(':'.join(paths), tool, history=True) |
| 261 | if not p or os.path.basename(icecc_get_tool_link(p, d)) != 'ccache': |
| 262 | return p |
| 263 | paths = paths[len(hist):] |
| 264 | |
| 265 | return "" |
| 266 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | # Don't pollute native signatures with target TUNE_PKGARCH through STAGING_BINDIR_TOOLCHAIN |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 268 | icecc_get_tool[vardepsexclude] += "STAGING_BINDIR_TOOLCHAIN" |
| 269 | def icecc_get_tool(bb, d, tool): |
| 270 | if icecc_is_native(bb, d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 271 | return icecc_get_path_tool(tool, d) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 272 | elif icecc_is_kernel(bb, d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 273 | return icecc_get_path_tool(get_cross_kernel_cc(bb, d), d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 274 | else: |
| 275 | ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}') |
| 276 | target_sys = d.expand('${TARGET_SYS}') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 277 | for p in ice_dir.split(':'): |
| 278 | tool_bin = os.path.join(p, "%s-%s" % (target_sys, tool)) |
| 279 | if os.path.isfile(tool_bin): |
| 280 | return tool_bin |
| 281 | external_tool_bin = icecc_get_external_tool(bb, d, tool) |
| 282 | if os.path.isfile(external_tool_bin): |
| 283 | return external_tool_bin |
| 284 | return "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 285 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 286 | def icecc_get_and_check_tool(bb, d, tool): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 287 | # Check that g++ or gcc is not a symbolic link to icecc binary in |
| 288 | # PATH or icecc-create-env script will silently create an invalid |
| 289 | # compiler environment package. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 290 | t = icecc_get_tool(bb, d, tool) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 291 | if t: |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 292 | link_path = icecc_get_tool_link(t, d) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 293 | if link_path == get_icecc(d): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 294 | bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, link_path)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 295 | return "" |
| 296 | else: |
| 297 | return t |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 298 | else: |
| 299 | return t |
| 300 | |
| 301 | wait_for_file() { |
| 302 | local TIME_ELAPSED=0 |
| 303 | local FILE_TO_TEST=$1 |
| 304 | local TIMEOUT=$2 |
| 305 | until [ -f "$FILE_TO_TEST" ] |
| 306 | do |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 307 | TIME_ELAPSED=$(expr $TIME_ELAPSED + 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 308 | if [ $TIME_ELAPSED -gt $TIMEOUT ] |
| 309 | then |
| 310 | return 1 |
| 311 | fi |
| 312 | sleep 1 |
| 313 | done |
| 314 | } |
| 315 | |
| 316 | def set_icecc_env(): |
| 317 | # dummy python version of set_icecc_env |
| 318 | return |
| 319 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 320 | set_icecc_env[vardepsexclude] += "KERNEL_CC" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 321 | set_icecc_env() { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 322 | if [ "${@use_icecc(bb, d)}" = "no" ] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 323 | then |
| 324 | return |
| 325 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 326 | ICECC_VERSION="${@icecc_version(bb, d)}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 327 | if [ "x${ICECC_VERSION}" = "x" ] |
| 328 | then |
| 329 | bbwarn "Cannot use icecc: could not get ICECC_VERSION" |
| 330 | return |
| 331 | fi |
| 332 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 333 | ICE_PATH="${@icecc_path(bb, d)}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 334 | if [ "x${ICE_PATH}" = "x" ] |
| 335 | then |
| 336 | bbwarn "Cannot use icecc: could not get ICE_PATH" |
| 337 | return |
| 338 | fi |
| 339 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 340 | ICECC_BIN="${@get_icecc(d)}" |
| 341 | if [ -z "${ICECC_BIN}" ]; then |
| 342 | bbwarn "Cannot use icecc: icecc binary not found" |
| 343 | return |
| 344 | fi |
| 345 | if [ -z "$(which patchelf patchelf-uninative)" ]; then |
| 346 | bbwarn "Cannot use icecc: patchelf not found" |
| 347 | return |
| 348 | fi |
| 349 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 350 | ICECC_CC="${@icecc_get_and_check_tool(bb, d, "gcc")}" |
| 351 | ICECC_CXX="${@icecc_get_and_check_tool(bb, d, "g++")}" |
| 352 | # cannot use icecc_get_and_check_tool here because it assumes as without target_sys prefix |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 353 | ICECC_WHICH_AS="${@bb.utils.which(os.getenv('PATH'), 'as')}" |
| 354 | if [ ! -x "${ICECC_CC}" -o ! -x "${ICECC_CXX}" ] |
| 355 | then |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 356 | bbnote "Cannot use icecc: could not get ICECC_CC or ICECC_CXX" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 357 | return |
| 358 | fi |
| 359 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 360 | ICE_VERSION="$($ICECC_CC -dumpversion)" |
| 361 | ICECC_VERSION=$(echo ${ICECC_VERSION} | sed -e "s/@VERSION@/$ICE_VERSION/g") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 362 | if [ ! -x "${ICECC_ENV_EXEC}" ] |
| 363 | then |
| 364 | bbwarn "Cannot use icecc: invalid ICECC_ENV_EXEC" |
| 365 | return |
| 366 | fi |
| 367 | |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 368 | # Create symlinks to icecc and wrapper-scripts in the recipe-sysroot directory |
| 369 | mkdir -p $ICE_PATH/symlinks |
| 370 | if [ -n "${KERNEL_CC}" ]; then |
| 371 | compilers="${@get_cross_kernel_cc(bb,d)}" |
| 372 | else |
| 373 | compilers="${HOST_PREFIX}gcc ${HOST_PREFIX}g++" |
| 374 | fi |
| 375 | for compiler in $compilers; do |
| 376 | ln -sf $ICECC_BIN $ICE_PATH/symlinks/$compiler |
| 377 | rm -f $ICE_PATH/$compiler |
| 378 | cat <<-__EOF__ > $ICE_PATH/$compiler |
| 379 | #!/bin/sh -e |
| 380 | export ICECC_VERSION=$ICECC_VERSION |
| 381 | export ICECC_CC=$ICECC_CC |
| 382 | export ICECC_CXX=$ICECC_CXX |
| 383 | $ICE_PATH/symlinks/$compiler "\$@" |
| 384 | __EOF__ |
| 385 | chmod 775 $ICE_PATH/$compiler |
| 386 | done |
| 387 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 388 | ICECC_AS="$(${ICECC_CC} -print-prog-name=as)" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 389 | # for target recipes should return something like: |
| 390 | # /OE/tmp-eglibc/sysroots/x86_64-linux/usr/libexec/arm920tt-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.8.2/as |
| 391 | # and just "as" for native, if it returns "as" in current directory (for whatever reason) use "as" from PATH |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 392 | if [ "$(dirname "${ICECC_AS}")" = "." ] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 393 | then |
| 394 | ICECC_AS="${ICECC_WHICH_AS}" |
| 395 | fi |
| 396 | |
| 397 | if [ ! -f "${ICECC_VERSION}.done" ] |
| 398 | then |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 399 | mkdir -p "$(dirname "${ICECC_VERSION}")" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 400 | |
| 401 | # the ICECC_VERSION generation step must be locked by a mutex |
| 402 | # in order to prevent race conditions |
| 403 | if flock -n "${ICECC_VERSION}.lock" \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 404 | ${ICECC_ENV_EXEC} ${ICECC_ENV_DEBUG} "${ICECC_CC}" "${ICECC_CXX}" "${ICECC_AS}" "${ICECC_VERSION}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 405 | then |
| 406 | touch "${ICECC_VERSION}.done" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 407 | elif ! wait_for_file "${ICECC_VERSION}.done" 30 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 408 | then |
| 409 | # locking failed so wait for ${ICECC_VERSION}.done to appear |
| 410 | bbwarn "Timeout waiting for ${ICECC_VERSION}.done" |
| 411 | return |
| 412 | fi |
| 413 | fi |
| 414 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 415 | # Don't let ccache find the icecream compiler links that have been created, otherwise |
| 416 | # it can end up invoking icecream recursively. |
| 417 | export CCACHE_PATH="$PATH" |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 418 | export CCACHE_DISABLE="1" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 419 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 420 | export PATH="$ICE_PATH:$PATH" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 421 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 422 | bbnote "Using icecc path: $ICE_PATH" |
| 423 | bbnote "Using icecc tarball: $ICECC_VERSION" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 424 | } |
| 425 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 426 | do_configure[network] = "1" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 427 | do_configure:prepend() { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 428 | set_icecc_env |
| 429 | } |
| 430 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 431 | do_compile[network] = "1" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 432 | do_compile:prepend() { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 433 | set_icecc_env |
| 434 | } |
| 435 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 436 | do_compile_kernelmodules[network] = "1" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 437 | do_compile_kernelmodules:prepend() { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 438 | set_icecc_env |
| 439 | } |
| 440 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 441 | do_install[network] = "1" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 442 | do_install:prepend() { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 443 | set_icecc_env |
| 444 | } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 445 | |
| 446 | # IceCream is not (currently) supported in the extensible SDK |
| 447 | ICECC_SDK_HOST_TASK = "nativesdk-icecc-toolchain" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 448 | ICECC_SDK_HOST_TASK:task-populate-sdk-ext = "" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 449 | |
| 450 | # Don't include IceCream in uninative tarball |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 451 | ICECC_SDK_HOST_TASK:pn-uninative-tarball = "" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 452 | |
| 453 | # Add the toolchain scripts to the SDK |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 454 | TOOLCHAIN_HOST_TASK:append = " ${ICECC_SDK_HOST_TASK}" |