blob: 312e0f17b554b838fe7d3a8034ad99fe290fdbca [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
Andrew Geissler87f5cff2022-09-30 13:13:31 -05007# Icecream distributed compiling support
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008#
9# Stages directories with symlinks from gcc/g++ to icecc, for both
10# native and cross compilers. Depending on each configure or compile,
11# the directories are added at the head of the PATH list and ICECC_CXX
Andrew Geissler87f5cff2022-09-30 13:13:31 -050012# and ICECC_CC are set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013#
14# For the cross compiler, creates a tar.gz of our toolchain and sets
15# ICECC_VERSION accordingly.
16#
17# The class now handles all 3 different compile 'stages' (i.e native ,cross-kernel and target) creating the
18# necessary environment tar.gz file to be used by the remote machines.
Andrew Geissler87f5cff2022-09-30 13:13:31 -050019# It also supports meta-toolchain generation.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020#
21# If ICECC_PATH is not set in local.conf then the class will try to locate it using 'bb.utils.which'
Andrew Geissler87f5cff2022-09-30 13:13:31 -050022# but nothing is sure. ;)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023#
24# If ICECC_ENV_EXEC is set in local.conf, then it should point to the icecc-create-env script provided by the user
Andrew Geissler87f5cff2022-09-30 13:13:31 -050025# or the default one provided by icecc-create-env_0.1.bb will be used.
26# (NOTE that this is a modified version of the needed script and *not the one that comes with icecream*).
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027#
Andrew Geissler87f5cff2022-09-30 13:13:31 -050028# User can specify if specific recipes or recipes inheriting specific classes should not use icecc to distribute
29# compile jobs to remote machines, but handle them locally by defining ICECC_CLASS_DISABLE and ICECC_RECIPE_DISABLE
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000030# with the appropriate values in local.conf. In addition the user can force to enable icecc for recipes
31# which set an empty PARALLEL_MAKE variable by defining ICECC_RECIPE_ENABLE.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032#
33#########################################################################################
Andrew Geissler87f5cff2022-09-30 13:13:31 -050034# Error checking is kept to minimum so double check any parameters you pass to the class
35#########################################################################################
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000037BB_BASEHASH_IGNORE_VARS += "ICECC_PARALLEL_MAKE ICECC_DISABLED ICECC_RECIPE_DISABLE \
38 ICECC_CLASS_DISABLE ICECC_RECIPE_ENABLE ICECC_PATH ICECC_ENV_EXEC \
Brad Bishop316dfdd2018-06-25 12:45:53 -040039 ICECC_CARET_WORKAROUND ICECC_CFLAGS ICECC_ENV_VERSION \
40 ICECC_DEBUG ICECC_LOGFILE ICECC_REPEAT_RATE ICECC_PREFERRED_HOST \
41 ICECC_CLANG_REMOTE_CPP ICECC_IGNORE_UNVERIFIED ICECC_TEST_SOCKET \
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000042 ICECC_ENV_DEBUG ICECC_REMOTE_CPP \
Brad Bishop316dfdd2018-06-25 12:45:53 -040043 "
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044
45ICECC_ENV_EXEC ?= "${STAGING_BINDIR_NATIVE}/icecc-create-env"
46
Brad Bishop977dc1a2019-02-06 16:01:43 -050047HOSTTOOLS_NONFATAL += "icecc patchelf"
48
Brad Bishop316dfdd2018-06-25 12:45:53 -040049# This version can be incremented when changes are made to the environment that
50# invalidate the version on the compile nodes. Changing it will cause a new
51# environment to be created.
52#
Andrew Geissler87f5cff2022-09-30 13:13:31 -050053# A useful thing to do for testing icecream changes locally is to add a
Brad Bishop316dfdd2018-06-25 12:45:53 -040054# subversion in local.conf:
Patrick Williams213cb262021-08-07 19:21:33 -050055# ICECC_ENV_VERSION:append = "-my-ver-1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040056ICECC_ENV_VERSION = "2"
57
58# Default to disabling the caret workaround, If set to "1" in local.conf, icecc
59# will locally recompile any files that have warnings, which can adversely
60# affect performance.
61#
62# See: https://github.com/icecc/icecream/issues/190
63export ICECC_CARET_WORKAROUND ??= "0"
64
Brad Bishop96ff1982019-08-19 13:50:42 -040065export ICECC_REMOTE_CPP ??= "0"
Brad Bishop19323692019-04-05 15:28:33 -040066
Brad Bishop316dfdd2018-06-25 12:45:53 -040067ICECC_CFLAGS = ""
68CFLAGS += "${ICECC_CFLAGS}"
69CXXFLAGS += "${ICECC_CFLAGS}"
70
71# Debug flags when generating environments
72ICECC_ENV_DEBUG ??= ""
73
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000074# Disable recipe list contains a list of recipes that can not distribute
Andrew Geissler87f5cff2022-09-30 13:13:31 -050075# compile tasks for one reason or the other. When adding a new entry, please
Brad Bishopa5c52ff2018-11-23 10:55:50 +130076# document why (how it failed) so that we can re-evaluate it later e.g. when
Andrew Geissler87f5cff2022-09-30 13:13:31 -050077# there is a new version.
Brad Bishopa5c52ff2018-11-23 10:55:50 +130078#
79# libgcc-initial - fails with CPP sanity check error if host sysroot contains
Andrew Geissler87f5cff2022-09-30 13:13:31 -050080# cross gcc built for another target tune/variant.
Brad Bishopa34c0302019-09-23 22:34:48 -040081# pixman - prng_state: TLS reference mismatches non-TLS reference, possibly due to
Andrew Geissler87f5cff2022-09-30 13:13:31 -050082# pragma omp threadprivate(prng_state).
Brad Bishop79641f22019-09-10 07:20:22 -040083# systemtap - _HelperSDT.c undefs macros and uses the identifiers in macros emitting
Andrew Geissler87f5cff2022-09-30 13:13:31 -050084# inline assembly.
Brad Bishopa5c52ff2018-11-23 10:55:50 +130085# target-sdk-provides-dummy - ${HOST_PREFIX} is empty which triggers the "NULL
86# prefix" error.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000087ICECC_RECIPE_DISABLE += "\
Brad Bishopa5c52ff2018-11-23 10:55:50 +130088 libgcc-initial \
Brad Bishopa34c0302019-09-23 22:34:48 -040089 pixman \
Brad Bishop79641f22019-09-10 07:20:22 -040090 systemtap \
Brad Bishopa5c52ff2018-11-23 10:55:50 +130091 target-sdk-provides-dummy \
92 "
93
Andrew Geissler87f5cff2022-09-30 13:13:31 -050094# Classes that should not use icecc. When adding a new entry, please
95# document why (how it failed) so that we can re-evaluate it later.
Brad Bishopa5c52ff2018-11-23 10:55:50 +130096#
Andrew Geissler87f5cff2022-09-30 13:13:31 -050097# image - images aren't compiling, but the testing framework for images captures
Brad Bishopa5c52ff2018-11-23 10:55:50 +130098# PARALLEL_MAKE as part of the test environment. Many tests won't use
99# icecream, but leaving the high level of parallelism can cause them to
100# consume an unnecessary amount of resources.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000101ICECC_CLASS_DISABLE += "\
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300102 image \
103 "
104
Patrick Williams213cb262021-08-07 19:21:33 -0500105def get_icecc_dep(d):
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500106 # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 # we need that built is the responsibility of the patch function / class, not
108 # the application.
Brad Bishop316dfdd2018-06-25 12:45:53 -0400109 if not d.getVar('INHIBIT_DEFAULT_DEPS'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110 return "icecc-create-env-native"
111 return ""
112
Patrick Williams213cb262021-08-07 19:21:33 -0500113DEPENDS:prepend = "${@get_icecc_dep(d)} "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500115get_cross_kernel_cc[vardepsexclude] += "KERNEL_CC"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116def get_cross_kernel_cc(bb,d):
Brad Bishop977dc1a2019-02-06 16:01:43 -0500117 if not icecc_is_kernel(bb, d):
118 return None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119
120 # evaluate the expression by the shell if necessary
Brad Bishop977dc1a2019-02-06 16:01:43 -0500121 kernel_cc = d.getVar('KERNEL_CC')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 if '`' in kernel_cc or '$(' in kernel_cc:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600123 import subprocess
124 kernel_cc = subprocess.check_output("echo %s" % kernel_cc, shell=True).decode("utf-8")[:-1]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 kernel_cc = kernel_cc.replace('ccache', '').strip()
127 kernel_cc = kernel_cc.split(' ')[0]
128 kernel_cc = kernel_cc.strip()
129 return kernel_cc
130
131def get_icecc(d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400132 return d.getVar('ICECC_PATH') or bb.utils.which(os.getenv("PATH"), "icecc")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500134def use_icecc(bb,d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400135 if d.getVar('ICECC_DISABLED') == "1":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136 # don't even try it, when explicitly disabled
137 return "no"
138
139 # allarch recipes don't use compiler
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500140 if icecc_is_allarch(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141 return "no"
142
Brad Bishop316dfdd2018-06-25 12:45:53 -0400143 if icecc_is_cross_canadian(bb, d):
144 return "no"
145
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500146 pn = d.getVar('PN')
Brad Bishop19323692019-04-05 15:28:33 -0400147 bpn = d.getVar('BPN')
148
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000149 # Enable/disable checks are made against BPN, because there is a good
Brad Bishop19323692019-04-05 15:28:33 -0400150 # chance that if icecc should be skipped for a recipe, it should be skipped
151 # for all the variants of that recipe. PN is still checked in case a user
152 # specified a more specific recipe.
153 check_pn = set([pn, bpn])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000155 class_disable = (d.getVar('ICECC_CLASS_DISABLE') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500156
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000157 for bbclass in class_disable:
158 if bb.data.inherits_class(bbclass, d):
159 bb.debug(1, "%s: bbclass %s found in disable, disable icecc" % (pn, bbclass))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160 return "no"
161
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000162 disabled_recipes = (d.getVar('ICECC_RECIPE_DISABLE') or "").split()
163 enabled_recipes = (d.getVar('ICECC_RECIPE_ENABLE') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000165 if check_pn & set(disabled_recipes):
166 bb.debug(1, "%s: found in disable list, disable icecc" % pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167 return "no"
168
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000169 if check_pn & set(enabled_recipes):
170 bb.debug(1, "%s: found in enabled recipes list, enable icecc" % pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171 return "yes"
172
Brad Bishop316dfdd2018-06-25 12:45:53 -0400173 if d.getVar('PARALLEL_MAKE') == "":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174 bb.debug(1, "%s: has empty PARALLEL_MAKE, disable icecc" % pn)
175 return "no"
176
177 return "yes"
178
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500179def icecc_is_allarch(bb, d):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800180 return d.getVar("PACKAGE_ARCH") == "all"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500182def icecc_is_kernel(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183 return \
184 bb.data.inherits_class("kernel", d);
185
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500186def icecc_is_native(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187 return \
188 bb.data.inherits_class("cross", d) or \
189 bb.data.inherits_class("native", d);
190
Brad Bishop316dfdd2018-06-25 12:45:53 -0400191def icecc_is_cross_canadian(bb, d):
192 return bb.data.inherits_class("cross-canadian", d)
193
194def icecc_dir(bb, d):
195 return d.expand('${TMPDIR}/work-shared/ice')
196
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500197# Don't pollute allarch signatures with TARGET_FPU
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500198icecc_version[vardepsexclude] += "TARGET_FPU"
199def icecc_version(bb, d):
200 if use_icecc(bb, d) == "no":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500201 return ""
202
Brad Bishop316dfdd2018-06-25 12:45:53 -0400203 parallel = d.getVar('ICECC_PARALLEL_MAKE') or ""
204 if not d.getVar('PARALLEL_MAKE') == "" and parallel:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500205 d.setVar("PARALLEL_MAKE", parallel)
206
Brad Bishop316dfdd2018-06-25 12:45:53 -0400207 # Disable showing the caret in the GCC compiler output if the workaround is
208 # disabled
209 if d.getVar('ICECC_CARET_WORKAROUND') == '0':
210 d.setVar('ICECC_CFLAGS', '-fno-diagnostics-show-caret')
211
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500212 if icecc_is_native(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500213 archive_name = "local-host-env"
214 elif d.expand('${HOST_PREFIX}') == "":
215 bb.fatal(d.expand("${PN}"), " NULL prefix")
216 else:
217 prefix = d.expand('${HOST_PREFIX}' )
218 distro = d.expand('${DISTRO}')
219 target_sys = d.expand('${TARGET_SYS}')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400220 float = d.getVar('TARGET_FPU') or "hard"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221 archive_name = prefix + distro + "-" + target_sys + "-" + float
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500222 if icecc_is_kernel(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223 archive_name += "-kernel"
224
225 import socket
Brad Bishop316dfdd2018-06-25 12:45:53 -0400226 ice_dir = icecc_dir(bb, d)
227 tar_file = os.path.join(ice_dir, "{archive}-{version}-@VERSION@-{hostname}.tar.gz".format(
228 archive=archive_name,
229 version=d.getVar('ICECC_ENV_VERSION'),
230 hostname=socket.gethostname()
231 ))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232
233 return tar_file
234
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500235def icecc_path(bb,d):
236 if use_icecc(bb, d) == "no":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237 # don't create unnecessary directories when icecc is disabled
238 return
239
Brad Bishop977dc1a2019-02-06 16:01:43 -0500240 staging = os.path.join(d.expand('${STAGING_BINDIR}'), "ice")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500241 if icecc_is_kernel(bb, d):
Brad Bishop977dc1a2019-02-06 16:01:43 -0500242 staging += "-kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500243
Brad Bishop977dc1a2019-02-06 16:01:43 -0500244 return staging
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500245
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500246def icecc_get_external_tool(bb, d, tool):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247 external_toolchain_bindir = d.expand('${EXTERNAL_TOOLCHAIN}${bindir_cross}')
248 target_prefix = d.expand('${TARGET_PREFIX}')
249 return os.path.join(external_toolchain_bindir, '%s%s' % (target_prefix, tool))
250
Brad Bishop316dfdd2018-06-25 12:45:53 -0400251def icecc_get_tool_link(tool, d):
252 import subprocess
Brad Bishop08902b02019-08-20 09:16:51 -0400253 try:
254 return subprocess.check_output("readlink -f %s" % tool, shell=True).decode("utf-8")[:-1]
255 except subprocess.CalledProcessError as e:
256 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")))
257 return tool
Brad Bishop316dfdd2018-06-25 12:45:53 -0400258
259def icecc_get_path_tool(tool, d):
260 # This is a little ugly, but we want to make sure we add an actual
261 # compiler to the toolchain, not ccache. Some distros (e.g. Fedora)
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500262 # have ccache enabled by default using symlinks in PATH, meaning ccache
Brad Bishop316dfdd2018-06-25 12:45:53 -0400263 # would be found first when looking for the compiler.
264 paths = os.getenv("PATH").split(':')
265 while True:
266 p, hist = bb.utils.which(':'.join(paths), tool, history=True)
267 if not p or os.path.basename(icecc_get_tool_link(p, d)) != 'ccache':
268 return p
269 paths = paths[len(hist):]
270
271 return ""
272
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273# Don't pollute native signatures with target TUNE_PKGARCH through STAGING_BINDIR_TOOLCHAIN
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500274icecc_get_tool[vardepsexclude] += "STAGING_BINDIR_TOOLCHAIN"
275def icecc_get_tool(bb, d, tool):
276 if icecc_is_native(bb, d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400277 return icecc_get_path_tool(tool, d)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500278 elif icecc_is_kernel(bb, d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400279 return icecc_get_path_tool(get_cross_kernel_cc(bb, d), d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500280 else:
281 ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}')
282 target_sys = d.expand('${TARGET_SYS}')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400283 for p in ice_dir.split(':'):
284 tool_bin = os.path.join(p, "%s-%s" % (target_sys, tool))
285 if os.path.isfile(tool_bin):
286 return tool_bin
287 external_tool_bin = icecc_get_external_tool(bb, d, tool)
288 if os.path.isfile(external_tool_bin):
289 return external_tool_bin
290 return ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500292def icecc_get_and_check_tool(bb, d, tool):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500293 # Check that g++ or gcc is not a symbolic link to icecc binary in
294 # PATH or icecc-create-env script will silently create an invalid
295 # compiler environment package.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500296 t = icecc_get_tool(bb, d, tool)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600297 if t:
Brad Bishop977dc1a2019-02-06 16:01:43 -0500298 link_path = icecc_get_tool_link(t, d)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600299 if link_path == get_icecc(d):
Brad Bishop977dc1a2019-02-06 16:01:43 -0500300 bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, link_path))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600301 return ""
302 else:
303 return t
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500304 else:
305 return t
306
307wait_for_file() {
308 local TIME_ELAPSED=0
309 local FILE_TO_TEST=$1
310 local TIMEOUT=$2
311 until [ -f "$FILE_TO_TEST" ]
312 do
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000313 TIME_ELAPSED=$(expr $TIME_ELAPSED + 1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500314 if [ $TIME_ELAPSED -gt $TIMEOUT ]
315 then
316 return 1
317 fi
318 sleep 1
319 done
320}
321
322def set_icecc_env():
323 # dummy python version of set_icecc_env
324 return
325
Brad Bishopc342db32019-05-15 21:57:59 -0400326set_icecc_env[vardepsexclude] += "KERNEL_CC"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500327set_icecc_env() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500328 if [ "${@use_icecc(bb, d)}" = "no" ]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500329 then
330 return
331 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500332 ICECC_VERSION="${@icecc_version(bb, d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500333 if [ "x${ICECC_VERSION}" = "x" ]
334 then
335 bbwarn "Cannot use icecc: could not get ICECC_VERSION"
336 return
337 fi
338
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500339 ICE_PATH="${@icecc_path(bb, d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340 if [ "x${ICE_PATH}" = "x" ]
341 then
342 bbwarn "Cannot use icecc: could not get ICE_PATH"
343 return
344 fi
345
Brad Bishop977dc1a2019-02-06 16:01:43 -0500346 ICECC_BIN="${@get_icecc(d)}"
347 if [ -z "${ICECC_BIN}" ]; then
348 bbwarn "Cannot use icecc: icecc binary not found"
349 return
350 fi
351 if [ -z "$(which patchelf patchelf-uninative)" ]; then
352 bbwarn "Cannot use icecc: patchelf not found"
353 return
354 fi
355
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500356 ICECC_CC="${@icecc_get_and_check_tool(bb, d, "gcc")}"
357 ICECC_CXX="${@icecc_get_and_check_tool(bb, d, "g++")}"
358 # cannot use icecc_get_and_check_tool here because it assumes as without target_sys prefix
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500359 ICECC_WHICH_AS="${@bb.utils.which(os.getenv('PATH'), 'as')}"
360 if [ ! -x "${ICECC_CC}" -o ! -x "${ICECC_CXX}" ]
361 then
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700362 bbnote "Cannot use icecc: could not get ICECC_CC or ICECC_CXX"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500363 return
364 fi
365
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000366 ICE_VERSION="$($ICECC_CC -dumpversion)"
367 ICECC_VERSION=$(echo ${ICECC_VERSION} | sed -e "s/@VERSION@/$ICE_VERSION/g")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500368 if [ ! -x "${ICECC_ENV_EXEC}" ]
369 then
370 bbwarn "Cannot use icecc: invalid ICECC_ENV_EXEC"
371 return
372 fi
373
Brad Bishop64c979e2019-11-04 13:55:29 -0500374 # Create symlinks to icecc and wrapper-scripts in the recipe-sysroot directory
375 mkdir -p $ICE_PATH/symlinks
376 if [ -n "${KERNEL_CC}" ]; then
377 compilers="${@get_cross_kernel_cc(bb,d)}"
378 else
379 compilers="${HOST_PREFIX}gcc ${HOST_PREFIX}g++"
380 fi
381 for compiler in $compilers; do
382 ln -sf $ICECC_BIN $ICE_PATH/symlinks/$compiler
Brad Bishop64c979e2019-11-04 13:55:29 -0500383 cat <<-__EOF__ > $ICE_PATH/$compiler
384 #!/bin/sh -e
385 export ICECC_VERSION=$ICECC_VERSION
386 export ICECC_CC=$ICECC_CC
387 export ICECC_CXX=$ICECC_CXX
388 $ICE_PATH/symlinks/$compiler "\$@"
389 __EOF__
390 chmod 775 $ICE_PATH/$compiler
391 done
392
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000393 ICECC_AS="$(${ICECC_CC} -print-prog-name=as)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500394 # for target recipes should return something like:
395 # /OE/tmp-eglibc/sysroots/x86_64-linux/usr/libexec/arm920tt-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.8.2/as
396 # and just "as" for native, if it returns "as" in current directory (for whatever reason) use "as" from PATH
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000397 if [ "$(dirname "${ICECC_AS}")" = "." ]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500398 then
399 ICECC_AS="${ICECC_WHICH_AS}"
400 fi
401
402 if [ ! -f "${ICECC_VERSION}.done" ]
403 then
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000404 mkdir -p "$(dirname "${ICECC_VERSION}")"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500405
406 # the ICECC_VERSION generation step must be locked by a mutex
407 # in order to prevent race conditions
408 if flock -n "${ICECC_VERSION}.lock" \
Brad Bishop316dfdd2018-06-25 12:45:53 -0400409 ${ICECC_ENV_EXEC} ${ICECC_ENV_DEBUG} "${ICECC_CC}" "${ICECC_CXX}" "${ICECC_AS}" "${ICECC_VERSION}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500410 then
411 touch "${ICECC_VERSION}.done"
Brad Bishop19323692019-04-05 15:28:33 -0400412 elif ! wait_for_file "${ICECC_VERSION}.done" 30
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500413 then
414 # locking failed so wait for ${ICECC_VERSION}.done to appear
415 bbwarn "Timeout waiting for ${ICECC_VERSION}.done"
416 return
417 fi
418 fi
419
Brad Bishop316dfdd2018-06-25 12:45:53 -0400420 # Don't let ccache find the icecream compiler links that have been created, otherwise
421 # it can end up invoking icecream recursively.
422 export CCACHE_PATH="$PATH"
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300423 export CCACHE_DISABLE="1"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400424
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500425 export PATH="$ICE_PATH:$PATH"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500426
Brad Bishop19323692019-04-05 15:28:33 -0400427 bbnote "Using icecc path: $ICE_PATH"
428 bbnote "Using icecc tarball: $ICECC_VERSION"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500429}
430
Andrew Geissler9aee5002022-03-30 16:27:02 +0000431do_configure[network] = "1"
Patrick Williams213cb262021-08-07 19:21:33 -0500432do_configure:prepend() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500433 set_icecc_env
434}
435
Andrew Geissler9aee5002022-03-30 16:27:02 +0000436do_compile[network] = "1"
Patrick Williams213cb262021-08-07 19:21:33 -0500437do_compile:prepend() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500438 set_icecc_env
439}
440
Andrew Geissler9aee5002022-03-30 16:27:02 +0000441do_compile_kernelmodules[network] = "1"
Patrick Williams213cb262021-08-07 19:21:33 -0500442do_compile_kernelmodules:prepend() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500443 set_icecc_env
444}
445
Andrew Geissler9aee5002022-03-30 16:27:02 +0000446do_install[network] = "1"
Patrick Williams213cb262021-08-07 19:21:33 -0500447do_install:prepend() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500448 set_icecc_env
449}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400450
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500451# Icecream is not (currently) supported in the extensible SDK
Brad Bishop316dfdd2018-06-25 12:45:53 -0400452ICECC_SDK_HOST_TASK = "nativesdk-icecc-toolchain"
Patrick Williams213cb262021-08-07 19:21:33 -0500453ICECC_SDK_HOST_TASK:task-populate-sdk-ext = ""
Brad Bishop316dfdd2018-06-25 12:45:53 -0400454
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500455# Don't include icecream in uninative tarball
Patrick Williams213cb262021-08-07 19:21:33 -0500456ICECC_SDK_HOST_TASK:pn-uninative-tarball = ""
Brad Bishop316dfdd2018-06-25 12:45:53 -0400457
458# Add the toolchain scripts to the SDK
Patrick Williams213cb262021-08-07 19:21:33 -0500459TOOLCHAIN_HOST_TASK:append = " ${ICECC_SDK_HOST_TASK}"