blob: a550b6af2479bf8f24b381d85e43634cb4fd3841 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# 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 Geissler7e0e3c02022-02-25 20:34:39 +000022# 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 Williamsc124f4f2015-09-15 14:41:29 -050026#
27#########################################################################################
28#Error checking is kept to minimum so double check any parameters you pass to the class
29###########################################################################################
30
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000031BB_BASEHASH_IGNORE_VARS += "ICECC_PARALLEL_MAKE ICECC_DISABLED ICECC_RECIPE_DISABLE \
32 ICECC_CLASS_DISABLE ICECC_RECIPE_ENABLE ICECC_PATH ICECC_ENV_EXEC \
Brad Bishop316dfdd2018-06-25 12:45:53 -040033 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 Geissler7e0e3c02022-02-25 20:34:39 +000036 ICECC_ENV_DEBUG ICECC_REMOTE_CPP \
Brad Bishop316dfdd2018-06-25 12:45:53 -040037 "
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038
39ICECC_ENV_EXEC ?= "${STAGING_BINDIR_NATIVE}/icecc-create-env"
40
Brad Bishop977dc1a2019-02-06 16:01:43 -050041HOSTTOOLS_NONFATAL += "icecc patchelf"
42
Brad Bishop316dfdd2018-06-25 12:45:53 -040043# 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 Williams213cb262021-08-07 19:21:33 -050049# ICECC_ENV_VERSION:append = "-my-ver-1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040050ICECC_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
57export ICECC_CARET_WORKAROUND ??= "0"
58
Brad Bishop96ff1982019-08-19 13:50:42 -040059export ICECC_REMOTE_CPP ??= "0"
Brad Bishop19323692019-04-05 15:28:33 -040060
Brad Bishop316dfdd2018-06-25 12:45:53 -040061ICECC_CFLAGS = ""
62CFLAGS += "${ICECC_CFLAGS}"
63CXXFLAGS += "${ICECC_CFLAGS}"
64
65# Debug flags when generating environments
66ICECC_ENV_DEBUG ??= ""
67
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000068# Disable recipe list contains a list of recipes that can not distribute
Brad Bishopa5c52ff2018-11-23 10:55:50 +130069# 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 Bishopa34c0302019-09-23 22:34:48 -040075# pixman - prng_state: TLS reference mismatches non-TLS reference, possibly due to
76# pragma omp threadprivate(prng_state)
Brad Bishop79641f22019-09-10 07:20:22 -040077# systemtap - _HelperSDT.c undefs macros and uses the identifiers in macros emitting
78# inline assembly
Brad Bishopa5c52ff2018-11-23 10:55:50 +130079# target-sdk-provides-dummy - ${HOST_PREFIX} is empty which triggers the "NULL
80# prefix" error.
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000081ICECC_RECIPE_DISABLE += "\
Brad Bishopa5c52ff2018-11-23 10:55:50 +130082 libgcc-initial \
Brad Bishopa34c0302019-09-23 22:34:48 -040083 pixman \
Brad Bishop79641f22019-09-10 07:20:22 -040084 systemtap \
Brad Bishopa5c52ff2018-11-23 10:55:50 +130085 target-sdk-provides-dummy \
86 "
87
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000088# Classes that should not use icecc. When adding new entry, please
Brad Bishopa5c52ff2018-11-23 10:55:50 +130089# 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 Geissler7e0e3c02022-02-25 20:34:39 +000095ICECC_CLASS_DISABLE += "\
Brad Bishopa5c52ff2018-11-23 10:55:50 +130096 image \
97 "
98
Patrick Williams213cb262021-08-07 19:21:33 -050099def get_icecc_dep(d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 # 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 Bishop316dfdd2018-06-25 12:45:53 -0400103 if not d.getVar('INHIBIT_DEFAULT_DEPS'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 return "icecc-create-env-native"
105 return ""
106
Patrick Williams213cb262021-08-07 19:21:33 -0500107DEPENDS:prepend = "${@get_icecc_dep(d)} "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500109get_cross_kernel_cc[vardepsexclude] += "KERNEL_CC"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110def get_cross_kernel_cc(bb,d):
Brad Bishop977dc1a2019-02-06 16:01:43 -0500111 if not icecc_is_kernel(bb, d):
112 return None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113
114 # evaluate the expression by the shell if necessary
Brad Bishop977dc1a2019-02-06 16:01:43 -0500115 kernel_cc = d.getVar('KERNEL_CC')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 if '`' in kernel_cc or '$(' in kernel_cc:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600117 import subprocess
118 kernel_cc = subprocess.check_output("echo %s" % kernel_cc, shell=True).decode("utf-8")[:-1]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120 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
125def get_icecc(d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400126 return d.getVar('ICECC_PATH') or bb.utils.which(os.getenv("PATH"), "icecc")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500127
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500128def use_icecc(bb,d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400129 if d.getVar('ICECC_DISABLED') == "1":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 # don't even try it, when explicitly disabled
131 return "no"
132
133 # allarch recipes don't use compiler
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500134 if icecc_is_allarch(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135 return "no"
136
Brad Bishop316dfdd2018-06-25 12:45:53 -0400137 if icecc_is_cross_canadian(bb, d):
138 return "no"
139
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500140 pn = d.getVar('PN')
Brad Bishop19323692019-04-05 15:28:33 -0400141 bpn = d.getVar('BPN')
142
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000143 # Enable/disable checks are made against BPN, because there is a good
Brad Bishop19323692019-04-05 15:28:33 -0400144 # 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 Williamsc124f4f2015-09-15 14:41:29 -0500148
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000149 class_disable = (d.getVar('ICECC_CLASS_DISABLE') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000151 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 Williamsc124f4f2015-09-15 14:41:29 -0500154 return "no"
155
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000156 disabled_recipes = (d.getVar('ICECC_RECIPE_DISABLE') or "").split()
157 enabled_recipes = (d.getVar('ICECC_RECIPE_ENABLE') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000159 if check_pn & set(disabled_recipes):
160 bb.debug(1, "%s: found in disable list, disable icecc" % pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161 return "no"
162
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000163 if check_pn & set(enabled_recipes):
164 bb.debug(1, "%s: found in enabled recipes list, enable icecc" % pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165 return "yes"
166
Brad Bishop316dfdd2018-06-25 12:45:53 -0400167 if d.getVar('PARALLEL_MAKE') == "":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168 bb.debug(1, "%s: has empty PARALLEL_MAKE, disable icecc" % pn)
169 return "no"
170
171 return "yes"
172
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500173def icecc_is_allarch(bb, d):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800174 return d.getVar("PACKAGE_ARCH") == "all"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500176def icecc_is_kernel(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500177 return \
178 bb.data.inherits_class("kernel", d);
179
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500180def icecc_is_native(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181 return \
182 bb.data.inherits_class("cross", d) or \
183 bb.data.inherits_class("native", d);
184
Brad Bishop316dfdd2018-06-25 12:45:53 -0400185def icecc_is_cross_canadian(bb, d):
186 return bb.data.inherits_class("cross-canadian", d)
187
188def icecc_dir(bb, d):
189 return d.expand('${TMPDIR}/work-shared/ice')
190
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191# Don't pollute allarch signatures with TARGET_FPU
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500192icecc_version[vardepsexclude] += "TARGET_FPU"
193def icecc_version(bb, d):
194 if use_icecc(bb, d) == "no":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500195 return ""
196
Brad Bishop316dfdd2018-06-25 12:45:53 -0400197 parallel = d.getVar('ICECC_PARALLEL_MAKE') or ""
198 if not d.getVar('PARALLEL_MAKE') == "" and parallel:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500199 d.setVar("PARALLEL_MAKE", parallel)
200
Brad Bishop316dfdd2018-06-25 12:45:53 -0400201 # 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 Williamsd8c66bc2016-06-20 12:57:21 -0500206 if icecc_is_native(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207 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 Bishop316dfdd2018-06-25 12:45:53 -0400214 float = d.getVar('TARGET_FPU') or "hard"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215 archive_name = prefix + distro + "-" + target_sys + "-" + float
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500216 if icecc_is_kernel(bb, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217 archive_name += "-kernel"
218
219 import socket
Brad Bishop316dfdd2018-06-25 12:45:53 -0400220 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 Williamsc124f4f2015-09-15 14:41:29 -0500226
227 return tar_file
228
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500229def icecc_path(bb,d):
230 if use_icecc(bb, d) == "no":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231 # don't create unnecessary directories when icecc is disabled
232 return
233
Brad Bishop977dc1a2019-02-06 16:01:43 -0500234 staging = os.path.join(d.expand('${STAGING_BINDIR}'), "ice")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500235 if icecc_is_kernel(bb, d):
Brad Bishop977dc1a2019-02-06 16:01:43 -0500236 staging += "-kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237
Brad Bishop977dc1a2019-02-06 16:01:43 -0500238 return staging
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500240def icecc_get_external_tool(bb, d, tool):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241 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 Bishop316dfdd2018-06-25 12:45:53 -0400245def icecc_get_tool_link(tool, d):
246 import subprocess
Brad Bishop08902b02019-08-20 09:16:51 -0400247 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 Bishop316dfdd2018-06-25 12:45:53 -0400252
253def 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 Williamsc124f4f2015-09-15 14:41:29 -0500267# Don't pollute native signatures with target TUNE_PKGARCH through STAGING_BINDIR_TOOLCHAIN
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500268icecc_get_tool[vardepsexclude] += "STAGING_BINDIR_TOOLCHAIN"
269def icecc_get_tool(bb, d, tool):
270 if icecc_is_native(bb, d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400271 return icecc_get_path_tool(tool, d)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500272 elif icecc_is_kernel(bb, d):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400273 return icecc_get_path_tool(get_cross_kernel_cc(bb, d), d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500274 else:
275 ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}')
276 target_sys = d.expand('${TARGET_SYS}')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400277 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 Williamsc124f4f2015-09-15 14:41:29 -0500285
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500286def icecc_get_and_check_tool(bb, d, tool):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500287 # 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 Williamsd8c66bc2016-06-20 12:57:21 -0500290 t = icecc_get_tool(bb, d, tool)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600291 if t:
Brad Bishop977dc1a2019-02-06 16:01:43 -0500292 link_path = icecc_get_tool_link(t, d)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600293 if link_path == get_icecc(d):
Brad Bishop977dc1a2019-02-06 16:01:43 -0500294 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 -0600295 return ""
296 else:
297 return t
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 else:
299 return t
300
301wait_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 Geissler7e0e3c02022-02-25 20:34:39 +0000307 TIME_ELAPSED=$(expr $TIME_ELAPSED + 1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500308 if [ $TIME_ELAPSED -gt $TIMEOUT ]
309 then
310 return 1
311 fi
312 sleep 1
313 done
314}
315
316def set_icecc_env():
317 # dummy python version of set_icecc_env
318 return
319
Brad Bishopc342db32019-05-15 21:57:59 -0400320set_icecc_env[vardepsexclude] += "KERNEL_CC"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500321set_icecc_env() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500322 if [ "${@use_icecc(bb, d)}" = "no" ]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500323 then
324 return
325 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500326 ICECC_VERSION="${@icecc_version(bb, d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500327 if [ "x${ICECC_VERSION}" = "x" ]
328 then
329 bbwarn "Cannot use icecc: could not get ICECC_VERSION"
330 return
331 fi
332
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500333 ICE_PATH="${@icecc_path(bb, d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500334 if [ "x${ICE_PATH}" = "x" ]
335 then
336 bbwarn "Cannot use icecc: could not get ICE_PATH"
337 return
338 fi
339
Brad Bishop977dc1a2019-02-06 16:01:43 -0500340 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 Williamsd8c66bc2016-06-20 12:57:21 -0500350 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 Williamsc124f4f2015-09-15 14:41:29 -0500353 ICECC_WHICH_AS="${@bb.utils.which(os.getenv('PATH'), 'as')}"
354 if [ ! -x "${ICECC_CC}" -o ! -x "${ICECC_CXX}" ]
355 then
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700356 bbnote "Cannot use icecc: could not get ICECC_CC or ICECC_CXX"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357 return
358 fi
359
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000360 ICE_VERSION="$($ICECC_CC -dumpversion)"
361 ICECC_VERSION=$(echo ${ICECC_VERSION} | sed -e "s/@VERSION@/$ICE_VERSION/g")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500362 if [ ! -x "${ICECC_ENV_EXEC}" ]
363 then
364 bbwarn "Cannot use icecc: invalid ICECC_ENV_EXEC"
365 return
366 fi
367
Brad Bishop64c979e2019-11-04 13:55:29 -0500368 # 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 Geissler7e0e3c02022-02-25 20:34:39 +0000388 ICECC_AS="$(${ICECC_CC} -print-prog-name=as)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500389 # 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 Geissler7e0e3c02022-02-25 20:34:39 +0000392 if [ "$(dirname "${ICECC_AS}")" = "." ]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500393 then
394 ICECC_AS="${ICECC_WHICH_AS}"
395 fi
396
397 if [ ! -f "${ICECC_VERSION}.done" ]
398 then
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000399 mkdir -p "$(dirname "${ICECC_VERSION}")"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500400
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 Bishop316dfdd2018-06-25 12:45:53 -0400404 ${ICECC_ENV_EXEC} ${ICECC_ENV_DEBUG} "${ICECC_CC}" "${ICECC_CXX}" "${ICECC_AS}" "${ICECC_VERSION}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500405 then
406 touch "${ICECC_VERSION}.done"
Brad Bishop19323692019-04-05 15:28:33 -0400407 elif ! wait_for_file "${ICECC_VERSION}.done" 30
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500408 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 Bishop316dfdd2018-06-25 12:45:53 -0400415 # 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 Bishopa5c52ff2018-11-23 10:55:50 +1300418 export CCACHE_DISABLE="1"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400419
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500420 export PATH="$ICE_PATH:$PATH"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500421
Brad Bishop19323692019-04-05 15:28:33 -0400422 bbnote "Using icecc path: $ICE_PATH"
423 bbnote "Using icecc tarball: $ICECC_VERSION"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500424}
425
Patrick Williams213cb262021-08-07 19:21:33 -0500426do_configure:prepend() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500427 set_icecc_env
428}
429
Patrick Williams213cb262021-08-07 19:21:33 -0500430do_compile:prepend() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500431 set_icecc_env
432}
433
Patrick Williams213cb262021-08-07 19:21:33 -0500434do_compile_kernelmodules:prepend() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500435 set_icecc_env
436}
437
Patrick Williams213cb262021-08-07 19:21:33 -0500438do_install:prepend() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500439 set_icecc_env
440}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400441
442# IceCream is not (currently) supported in the extensible SDK
443ICECC_SDK_HOST_TASK = "nativesdk-icecc-toolchain"
Patrick Williams213cb262021-08-07 19:21:33 -0500444ICECC_SDK_HOST_TASK:task-populate-sdk-ext = ""
Brad Bishop316dfdd2018-06-25 12:45:53 -0400445
446# Don't include IceCream in uninative tarball
Patrick Williams213cb262021-08-07 19:21:33 -0500447ICECC_SDK_HOST_TASK:pn-uninative-tarball = ""
Brad Bishop316dfdd2018-06-25 12:45:53 -0400448
449# Add the toolchain scripts to the SDK
Patrick Williams213cb262021-08-07 19:21:33 -0500450TOOLCHAIN_HOST_TASK:append = " ${ICECC_SDK_HOST_TASK}"