summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
authorMarco Felsch <m.felsch@pengutronix.de>2024-12-11 19:03:46 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-12-13 12:26:01 +0000
commitf391bf2c0804aca812ad24e52c14b30347726111 (patch)
tree518ee74fd0ee20b8ab84315bce2dd9364611b518 /meta/classes
parent22f046d67c02823f2df2b26cb3c463f567eae3fb (diff)
downloadpoky-f391bf2c0804aca812ad24e52c14b30347726111.tar.gz
icecc: convert set_icecc_env to python prefuncs
Since bitbake commit f24bbaaddb36 ("data: Add support for new BB_HASH_CODEPARSER_VALS for cache optimisation") the icecc fails with [1]: ERROR: /Yocto/poky/meta/recipes-core/meta/target-sdk-provides-dummy.bb: no-pn NULL prefix WARNING: /Yocto/poky/meta/recipes-core/meta/target-sdk-provides-dummy.bb: Exception during build_dependencies for set_icecc_env The reason for this is the bb.fatal() within the icecc_version(). icecc_version() is called during the "${@}" python variable expansion while bitbake is running the build_dependencies() for the set_icecc_env() function. To avoid this behaviour set_icecc_env() should be converted into a python function which gets called during task[prefuncs] [2], which is done by this commit. [1] https://lists.yoctoproject.org/g/yocto/topic/icecc_support_broken/103429714 [2] https://lists.openembedded.org/g/openembedded-core/topic/110009272 (From OE-Core rev: 444445c5793aaf831ff0293b62a000f8ab7d40bb) Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/icecc.bbclass200
1 files changed, 91 insertions, 109 deletions
diff --git a/meta/classes/icecc.bbclass b/meta/classes/icecc.bbclass
index 159cae20f8..8fe9739f87 100644
--- a/meta/classes/icecc.bbclass
+++ b/meta/classes/icecc.bbclass
@@ -304,145 +304,127 @@ def icecc_get_and_check_tool(bb, d, tool):
304 else: 304 else:
305 return t 305 return t
306 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
313 TIME_ELAPSED=$(expr $TIME_ELAPSED + 1)
314 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
326set_icecc_env[vardepsexclude] += "KERNEL_CC" 307set_icecc_env[vardepsexclude] += "KERNEL_CC"
327set_icecc_env() { 308python set_icecc_env() {
328 if [ "${@use_icecc(bb, d)}" = "no" ] 309 import os
329 then 310 import subprocess
311
312 if use_icecc(bb, d) == "no":
330 return 313 return
331 fi 314 ICECC_VERSION = icecc_version(bb, d)
332 ICECC_VERSION="${@icecc_version(bb, d)}" 315 if not ICECC_VERSION:
333 if [ "x${ICECC_VERSION}" = "x" ] 316 bb.warn("Cannot use icecc: could not get ICECC_VERSION")
334 then
335 bbwarn "Cannot use icecc: could not get ICECC_VERSION"
336 return 317 return
337 fi
338 318
339 ICE_PATH="${@icecc_path(bb, d)}" 319 ICE_PATH = icecc_path(bb, d)
340 if [ "x${ICE_PATH}" = "x" ] 320 if not ICE_PATH:
341 then 321 bb.warn("Cannot use icecc: could not get ICE_PATH")
342 bbwarn "Cannot use icecc: could not get ICE_PATH"
343 return 322 return
344 fi
345 323
346 ICECC_BIN="${@get_icecc(d)}" 324 ICECC_BIN = get_icecc(d)
347 if [ -z "${ICECC_BIN}" ]; then 325 if not ICECC_BIN:
348 bbwarn "Cannot use icecc: icecc binary not found" 326 bb.warn("Cannot use icecc: icecc binary not found")
349 return 327 return
350 fi 328
351 if [ -z "$(which patchelf patchelf-uninative)" ]; then 329 if (not bb.utils.which(os.getenv("PATH"), "patchelf") and
352 bbwarn "Cannot use icecc: patchelf not found" 330 not bb.utils.which(os.getenv("PATH"), "patchelf-uninative")):
331 bb.warn("Cannot use icecc: patchelf not found")
353 return 332 return
354 fi
355 333
356 ICECC_CC="${@icecc_get_and_check_tool(bb, d, "gcc")}" 334 ICECC_CC = icecc_get_and_check_tool(bb, d, "gcc")
357 ICECC_CXX="${@icecc_get_and_check_tool(bb, d, "g++")}" 335 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 336 # cannot use icecc_get_and_check_tool here because it assumes as without target_sys prefix
359 ICECC_WHICH_AS="${@bb.utils.which(os.getenv('PATH'), 'as')}" 337 ICECC_WHICH_AS = bb.utils.which(os.getenv('PATH'), 'as')
360 if [ ! -x "${ICECC_CC}" -o ! -x "${ICECC_CXX}" ] 338 if (not os.access(ICECC_CC, os.X_OK) or
361 then 339 not os.access(ICECC_CXX, os.X_OK)):
362 bbnote "Cannot use icecc: could not get ICECC_CC or ICECC_CXX" 340 bb.note("Cannot use icecc: could not get ICECC_CC or ICECC_CXX")
341 return
342
343 cmd = []
344 try:
345 cmd = [ICECC_CC, '-dumpversion']
346 ICE_VERSION = subprocess.check_output(cmd).decode("utf-8").strip()
347 except subprocess.CalledProcessError as e:
348 bb.warn("icecc: '{}' returned {}:\n{}".format(cmd, e.returncode, e.output.decode("utf-8")))
363 return 349 return
364 fi
365 350
366 ICE_VERSION="$($ICECC_CC -dumpversion)" 351 ICECC_VERSION = ICECC_VERSION.replace("@VERSION@", ICE_VERSION)
367 ICECC_VERSION=$(echo ${ICECC_VERSION} | sed -e "s/@VERSION@/$ICE_VERSION/g") 352
368 if [ ! -x "${ICECC_ENV_EXEC}" ] 353 if not os.access(d.getVar('ICECC_ENV_EXEC'), os.X_OK):
369 then 354 bb.warn("Cannot use icecc: invalid ICECC_ENV_EXEC")
370 bbwarn "Cannot use icecc: invalid ICECC_ENV_EXEC"
371 return 355 return
372 fi
373 356
374 # Create symlinks to icecc and wrapper-scripts in the recipe-sysroot directory 357 # Create symlinks to icecc and wrapper-scripts in the recipe-sysroot directory
375 mkdir -p $ICE_PATH/symlinks 358 symlink_path = os.path.join(ICE_PATH, "symlinks")
376 if [ -n "${KERNEL_CC}" ]; then 359 bb.utils.mkdirhier(symlink_path)
377 compilers="${@get_cross_kernel_cc(bb,d)}" 360 compilers = []
378 else 361 if d.getVar('KERNEL_CC'):
379 compilers="${HOST_PREFIX}gcc ${HOST_PREFIX}g++" 362 compilers.append(get_cross_kernel_cc(bb,d))
380 fi 363 else:
381 for compiler in $compilers; do 364 host_prefix = d.getVar('HOST_PREFIX')
382 ln -sf $ICECC_BIN $ICE_PATH/symlinks/$compiler 365 compilers.extend([host_prefix + 'gcc', host_prefix + 'g++'])
383 cat <<-__EOF__ > $ICE_PATH/$compiler 366
384 #!/bin/sh -e 367 for compiler in compilers:
385 export ICECC_VERSION=$ICECC_VERSION 368 try:
386 export ICECC_CC=$ICECC_CC 369 os.symlink(ICECC_BIN, symlink_path + '/' + compiler)
387 export ICECC_CXX=$ICECC_CXX 370 except FileExistsError:
388 $ICE_PATH/symlinks/$compiler "\$@" 371 pass
389 __EOF__ 372 wrapper_script = os.path.join(ICE_PATH, compiler)
390 chmod 775 $ICE_PATH/$compiler 373 with open(wrapper_script, 'w') as fd:
391 done 374 fd.write("#!/bin/sh -e\n")
392 375 fd.write("export ICECC_VERSION={}\n".format(ICECC_VERSION))
393 ICECC_AS="$(${ICECC_CC} -print-prog-name=as)" 376 fd.write("export ICECC_CC={}\n".format(ICECC_CC))
377 fd.write("export ICECC_CXX={}\n".format(ICECC_CXX))
378 fd.write("{} \"$@\"\n".format(os.path.join(ICE_PATH, "symlinks", compiler)))
379 os.chmod(wrapper_script, 0o755)
380
381 try:
382 cmd = [ICECC_CC, '-print-prog-name=as']
383 ICECC_AS = subprocess.check_output(cmd).decode("utf-8").strip()
384 except subprocess.CalledProcessError as e:
385 bb.warn("icecc: '{}' returned {}:\n{}".format(cmd, e.returncode, e.output.decode("utf-8")))
386 return
394 # for target recipes should return something like: 387 # 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 388 # /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 389 # and just "as" for native, if it returns "as" in current directory (for whatever reason) use "as" from PATH
397 if [ "$(dirname "${ICECC_AS}")" = "." ] 390 if not os.path.dirname(ICECC_AS):
398 then 391 ICECC_AS = ICECC_WHICH_AS
399 ICECC_AS="${ICECC_WHICH_AS}"
400 fi
401 392
402 if [ ! -f "${ICECC_VERSION}.done" ] 393 if not os.path.isfile(ICECC_VERSION + ".done"):
403 then 394 bb.utils.mkdirhier(os.path.dirname(ICECC_VERSION))
404 mkdir -p "$(dirname "${ICECC_VERSION}")"
405 395
406 # the ICECC_VERSION generation step must be locked by a mutex 396 # the ICECC_VERSION generation step must be locked by a mutex
407 # in order to prevent race conditions 397 # in order to prevent race conditions
408 if flock -n "${ICECC_VERSION}.lock" \ 398 lock = bb.utils.lockfile(ICECC_VERSION + '.lock')
409 ${ICECC_ENV_EXEC} ${ICECC_ENV_DEBUG} "${ICECC_CC}" "${ICECC_CXX}" "${ICECC_AS}" "${ICECC_VERSION}" 399 try:
410 then 400 cmd = [d.getVar('ICECC_ENV_EXEC')]
411 touch "${ICECC_VERSION}.done" 401 if d.getVar('ICECC_ENV_DEBUG'):
412 elif ! wait_for_file "${ICECC_VERSION}.done" 30 402 cmd.append(d.getVar('ICECC_ENV_DEBUG'))
413 then 403 cmd.extend([ICECC_CC, ICECC_CXX, ICECC_AS, ICECC_VERSION])
414 # locking failed so wait for ${ICECC_VERSION}.done to appear 404 subprocess.check_output(cmd)
415 bbwarn "Timeout waiting for ${ICECC_VERSION}.done" 405 cmd = ['touch', ICECC_VERSION + '.done']
406 subprocess.check_output(cmd)
407 except subprocess.CalledProcessError as e:
408 bb.warn("icecc: '{}' returned {}:\n{}".format(cmd, e.returncode, e.output.decode("utf-8")))
409 bb.utils.unlockfile(lock)
416 return 410 return
417 fi 411 bb.utils.unlockfile(lock)
418 fi
419 412
420 # Don't let ccache find the icecream compiler links that have been created, otherwise 413 # Don't let ccache find the icecream compiler links that have been created, otherwise
421 # it can end up invoking icecream recursively. 414 # it can end up invoking icecream recursively.
422 export CCACHE_PATH="$PATH" 415 d.setVar('CCACHE_PATH', d.getVar('PATH'))
423 export CCACHE_DISABLE="1" 416 d.setVar('CCACHE_DISABLE', '1')
424
425 export PATH="$ICE_PATH:$PATH"
426 417
427 bbnote "Using icecc path: $ICE_PATH" 418 d.prependVar('PATH', ICE_PATH + ':')
428 bbnote "Using icecc tarball: $ICECC_VERSION"
429}
430
431do_configure:prepend() {
432 set_icecc_env
433}
434 419
435do_compile:prepend() { 420 bb.note("Using icecc path: {}".format(ICE_PATH))
436 set_icecc_env 421 bb.note("Using icecc tarball: {}".format(ICECC_VERSION))
437} 422}
438 423
439do_compile_kernelmodules:prepend() { 424do_configure[prefuncs] += "set_icecc_env"
440 set_icecc_env 425do_compile[prefuncs] += "set_icecc_env"
441} 426do_compile_kernelmodules[prefuncs] += "set_icecc_env"
442 427do_install[prefuncs] += "set_icecc_env"
443do_install:prepend() {
444 set_icecc_env
445}
446 428
447# Icecream is not (currently) supported in the extensible SDK 429# Icecream is not (currently) supported in the extensible SDK
448ICECC_SDK_HOST_TASK = "nativesdk-icecc-toolchain" 430ICECC_SDK_HOST_TASK = "nativesdk-icecc-toolchain"