2024-09-09 08:52:07 +00:00
|
|
|
# IceCream distributed compiling support
|
|
|
|
#
|
|
|
|
# Stages directories with symlinks from gcc/g++ to icecc, for both
|
|
|
|
# native and cross compilers. Depending on each configure or compile,
|
|
|
|
# the directories are added at the head of the PATH list and ICECC_CXX
|
|
|
|
# and ICEC_CC are set.
|
|
|
|
#
|
|
|
|
# For the cross compiler, creates a tar.gz of our toolchain and sets
|
|
|
|
# ICECC_VERSION accordingly.
|
|
|
|
#
|
2024-09-09 08:57:42 +00:00
|
|
|
# The class now handles all 3 different compile 'stages' (i.e native ,cross-kernel and target) creating the
|
|
|
|
# necessary environment tar.gz file to be used by the remote machines.
|
|
|
|
# It also supports meta-toolchain generation
|
2024-09-09 08:52:07 +00:00
|
|
|
#
|
2024-09-09 08:57:42 +00:00
|
|
|
# If ICECC_PATH is not set in local.conf then the class will try to locate it using 'bb.utils.which'
|
|
|
|
# but nothing is sure ;)
|
2024-09-09 08:52:07 +00:00
|
|
|
#
|
2024-09-09 08:57:42 +00:00
|
|
|
# If ICECC_ENV_EXEC is set in local.conf, then it should point to the icecc-create-env script provided by the user
|
|
|
|
# or the default one provided by icecc-create-env.bb will be used
|
|
|
|
# (NOTE that this is a modified version of the script need it and *not the one that comes with icecc*
|
|
|
|
#
|
|
|
|
# User can specify if specific packages or packages belonging to class should not use icecc to distribute
|
|
|
|
# compile jobs to remote machines, but handled locally, by defining ICECC_USER_CLASS_BL and ICECC_USER_PACKAGE_BL
|
|
|
|
# with the appropriate values in local.conf. In addition the user can force to enable icecc for packages
|
|
|
|
# which set an empty PARALLEL_MAKE variable by defining ICECC_USER_PACKAGE_WL.
|
2024-09-09 08:52:07 +00:00
|
|
|
#
|
|
|
|
#########################################################################################
|
|
|
|
#Error checking is kept to minimum so double check any parameters you pass to the class
|
|
|
|
###########################################################################################
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
BB_HASHBASE_WHITELIST += "ICECC_PARALLEL_MAKE ICECC_DISABLED ICECC_USER_PACKAGE_BL ICECC_USER_CLASS_BL ICECC_USER_PACKAGE_WL ICECC_PATH ICECC_ENV_EXEC"
|
|
|
|
|
2024-09-09 08:52:07 +00:00
|
|
|
ICECC_ENV_EXEC ?= "${STAGING_BINDIR_NATIVE}/icecc-create-env"
|
|
|
|
|
|
|
|
def icecc_dep_prepend(d):
|
|
|
|
# INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not
|
|
|
|
# we need that built is the responsibility of the patch function / class, not
|
|
|
|
# the application.
|
|
|
|
if not d.getVar('INHIBIT_DEFAULT_DEPS'):
|
|
|
|
return "icecc-create-env-native"
|
|
|
|
return ""
|
|
|
|
|
|
|
|
DEPENDS_prepend += "${@icecc_dep_prepend(d)} "
|
|
|
|
|
|
|
|
def get_cross_kernel_cc(bb,d):
|
2024-09-09 08:57:42 +00:00
|
|
|
kernel_cc = d.getVar('KERNEL_CC')
|
|
|
|
|
|
|
|
# evaluate the expression by the shell if necessary
|
|
|
|
if '`' in kernel_cc or '$(' in kernel_cc:
|
|
|
|
kernel_cc = os.popen("echo %s" % kernel_cc).read()[:-1]
|
|
|
|
|
|
|
|
kernel_cc = d.expand(kernel_cc)
|
2024-09-09 08:52:07 +00:00
|
|
|
kernel_cc = kernel_cc.replace('ccache', '').strip()
|
|
|
|
kernel_cc = kernel_cc.split(' ')[0]
|
|
|
|
kernel_cc = kernel_cc.strip()
|
|
|
|
return kernel_cc
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
def get_icecc(d):
|
|
|
|
return d.getVar('ICECC_PATH') or bb.utils.which(os.getenv("PATH"), "icecc")
|
|
|
|
|
2024-09-09 08:52:07 +00:00
|
|
|
def create_path(compilers, bb, d):
|
|
|
|
"""
|
|
|
|
Create Symlinks for the icecc in the staging directory
|
|
|
|
"""
|
2024-09-09 08:57:42 +00:00
|
|
|
staging = os.path.join(d.expand('${STAGING_BINDIR}'), "ice")
|
2024-09-09 08:52:07 +00:00
|
|
|
if icc_is_kernel(bb, d):
|
|
|
|
staging += "-kernel"
|
|
|
|
|
|
|
|
#check if the icecc path is set by the user
|
2024-09-09 08:57:42 +00:00
|
|
|
icecc = get_icecc(d)
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
# Create the dir if necessary
|
|
|
|
try:
|
|
|
|
os.stat(staging)
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
os.makedirs(staging)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
for compiler in compilers:
|
|
|
|
gcc_path = os.path.join(staging, compiler)
|
|
|
|
try:
|
|
|
|
os.stat(gcc_path)
|
|
|
|
except:
|
|
|
|
try:
|
|
|
|
os.symlink(icecc, gcc_path)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return staging
|
|
|
|
|
|
|
|
def use_icc(bb,d):
|
2024-09-09 08:57:42 +00:00
|
|
|
if d.getVar('ICECC_DISABLED') == "1":
|
|
|
|
# don't even try it, when explicitly disabled
|
|
|
|
return "no"
|
|
|
|
|
|
|
|
# allarch recipes don't use compiler
|
|
|
|
if icc_is_allarch(bb, d):
|
|
|
|
return "no"
|
|
|
|
|
|
|
|
pn = d.getVar('PN', True)
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
system_class_blacklist = []
|
2024-09-09 08:52:07 +00:00
|
|
|
user_class_blacklist = (d.getVar('ICECC_USER_CLASS_BL') or "none").split()
|
|
|
|
package_class_blacklist = system_class_blacklist + user_class_blacklist
|
|
|
|
|
|
|
|
for black in package_class_blacklist:
|
|
|
|
if bb.data.inherits_class(black, d):
|
2024-09-09 08:57:42 +00:00
|
|
|
bb.debug(1, "%s: class %s found in blacklist, disable icecc" % (pn, black))
|
2024-09-09 08:52:07 +00:00
|
|
|
return "no"
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
# "system" recipe blacklist contains a list of packages that can not distribute compile tasks
|
|
|
|
# for one reason or the other
|
|
|
|
# this is the old list (which doesn't seem to be valid anymore, because I was able to build
|
|
|
|
# all these with icecc enabled)
|
|
|
|
# system_package_blacklist = [ "uclibc", "glibc", "gcc", "bind", "u-boot", "dhcp-forwarder", "enchant", "connman", "orbit2" ]
|
|
|
|
# when adding new entry, please document why (how it failed) so that we can re-evaluate it later
|
|
|
|
# e.g. when there is new version
|
|
|
|
system_package_blacklist = []
|
2024-09-09 08:52:07 +00:00
|
|
|
user_package_blacklist = (d.getVar('ICECC_USER_PACKAGE_BL') or "").split()
|
2024-09-09 08:57:42 +00:00
|
|
|
user_package_whitelist = (d.getVar('ICECC_USER_PACKAGE_WL') or "").split()
|
2024-09-09 08:52:07 +00:00
|
|
|
package_blacklist = system_package_blacklist + user_package_blacklist
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
if pn in package_blacklist:
|
|
|
|
bb.debug(1, "%s: found in blacklist, disable icecc" % pn)
|
|
|
|
return "no"
|
|
|
|
|
|
|
|
if pn in user_package_whitelist:
|
|
|
|
bb.debug(1, "%s: found in whitelist, enable icecc" % pn)
|
|
|
|
return "yes"
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
if d.getVar('PARALLEL_MAKE') == "":
|
2024-09-09 08:57:42 +00:00
|
|
|
bb.debug(1, "%s: has empty PARALLEL_MAKE, disable icecc" % pn)
|
2024-09-09 08:52:07 +00:00
|
|
|
return "no"
|
|
|
|
|
|
|
|
return "yes"
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
def icc_is_allarch(bb, d):
|
|
|
|
return d.getVar("PACKAGE_ARCH") == "all"
|
|
|
|
|
2024-09-09 08:52:07 +00:00
|
|
|
def icc_is_kernel(bb, d):
|
|
|
|
return \
|
|
|
|
bb.data.inherits_class("kernel", d);
|
|
|
|
|
|
|
|
def icc_is_native(bb, d):
|
|
|
|
return \
|
|
|
|
bb.data.inherits_class("cross", d) or \
|
|
|
|
bb.data.inherits_class("native", d);
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
# Don't pollute allarch signatures with TARGET_FPU
|
|
|
|
icc_version[vardepsexclude] += "TARGET_FPU"
|
2024-09-09 08:52:07 +00:00
|
|
|
def icc_version(bb, d):
|
|
|
|
if use_icc(bb, d) == "no":
|
|
|
|
return ""
|
|
|
|
|
|
|
|
parallel = d.getVar('ICECC_PARALLEL_MAKE') or ""
|
2024-09-09 08:57:42 +00:00
|
|
|
if not d.getVar('PARALLEL_MAKE') == "" and parallel:
|
|
|
|
d.setVar("PARALLEL_MAKE", parallel)
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
if icc_is_native(bb, d):
|
|
|
|
archive_name = "local-host-env"
|
2024-09-09 08:57:42 +00:00
|
|
|
elif d.expand('${HOST_PREFIX}') == "":
|
|
|
|
bb.fatal(d.expand("${PN}"), " NULL prefix")
|
2024-09-09 08:52:07 +00:00
|
|
|
else:
|
2024-09-09 08:57:42 +00:00
|
|
|
prefix = d.expand('${HOST_PREFIX}' )
|
|
|
|
distro = d.expand('${DISTRO}')
|
|
|
|
target_sys = d.expand('${TARGET_SYS}')
|
2024-09-09 08:52:07 +00:00
|
|
|
float = d.getVar('TARGET_FPU') or "hard"
|
|
|
|
archive_name = prefix + distro + "-" + target_sys + "-" + float
|
|
|
|
if icc_is_kernel(bb, d):
|
|
|
|
archive_name += "-kernel"
|
|
|
|
|
|
|
|
import socket
|
2024-09-09 08:57:42 +00:00
|
|
|
ice_dir = d.expand('${STAGING_DIR_NATIVE}${prefix_native}')
|
2024-09-09 08:52:07 +00:00
|
|
|
tar_file = os.path.join(ice_dir, 'ice', archive_name + "-@VERSION@-" + socket.gethostname() + '.tar.gz')
|
|
|
|
|
|
|
|
return tar_file
|
|
|
|
|
|
|
|
def icc_path(bb,d):
|
2024-09-09 08:57:42 +00:00
|
|
|
if use_icc(bb, d) == "no":
|
|
|
|
# don't create unnecessary directories when icecc is disabled
|
|
|
|
return
|
|
|
|
|
2024-09-09 08:52:07 +00:00
|
|
|
if icc_is_kernel(bb, d):
|
|
|
|
return create_path( [get_cross_kernel_cc(bb,d), ], bb, d)
|
|
|
|
|
|
|
|
else:
|
2024-09-09 08:57:42 +00:00
|
|
|
prefix = d.expand('${HOST_PREFIX}')
|
|
|
|
return create_path( [prefix+"gcc", prefix+"g++"], bb, d)
|
2024-09-09 08:52:07 +00:00
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
def icc_get_external_tool(bb, d, tool):
|
|
|
|
external_toolchain_bindir = d.expand('${EXTERNAL_TOOLCHAIN}${bindir_cross}')
|
|
|
|
target_prefix = d.expand('${TARGET_PREFIX}')
|
|
|
|
return os.path.join(external_toolchain_bindir, '%s%s' % (target_prefix, tool))
|
|
|
|
|
|
|
|
# Don't pollute native signatures with target TUNE_PKGARCH through STAGING_BINDIR_TOOLCHAIN
|
|
|
|
icc_get_tool[vardepsexclude] += "STAGING_BINDIR_TOOLCHAIN"
|
2024-09-09 08:52:07 +00:00
|
|
|
def icc_get_tool(bb, d, tool):
|
|
|
|
if icc_is_native(bb, d):
|
2024-09-09 08:57:42 +00:00
|
|
|
return bb.utils.which(os.getenv("PATH"), tool)
|
2024-09-09 08:52:07 +00:00
|
|
|
elif icc_is_kernel(bb, d):
|
2024-09-09 08:57:42 +00:00
|
|
|
return bb.utils.which(os.getenv("PATH"), get_cross_kernel_cc(bb, d))
|
2024-09-09 08:52:07 +00:00
|
|
|
else:
|
2024-09-09 08:57:42 +00:00
|
|
|
ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}')
|
|
|
|
target_sys = d.expand('${TARGET_SYS}')
|
|
|
|
tool_bin = os.path.join(ice_dir, "%s-%s" % (target_sys, tool))
|
|
|
|
if os.path.isfile(tool_bin):
|
|
|
|
return tool_bin
|
|
|
|
else:
|
|
|
|
external_tool_bin = icc_get_external_tool(bb, d, tool)
|
|
|
|
if os.path.isfile(external_tool_bin):
|
|
|
|
return external_tool_bin
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def icc_get_and_check_tool(bb, d, tool):
|
|
|
|
# Check that g++ or gcc is not a symbolic link to icecc binary in
|
|
|
|
# PATH or icecc-create-env script will silently create an invalid
|
|
|
|
# compiler environment package.
|
|
|
|
t = icc_get_tool(bb, d, tool)
|
|
|
|
if t and os.popen("readlink -f %s" % t).read()[:-1] == get_icecc(d):
|
|
|
|
bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, get_icecc(d)))
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return t
|
|
|
|
|
|
|
|
wait_for_file() {
|
|
|
|
local TIME_ELAPSED=0
|
|
|
|
local FILE_TO_TEST=$1
|
|
|
|
local TIMEOUT=$2
|
|
|
|
until [ -f "$FILE_TO_TEST" ]
|
|
|
|
do
|
|
|
|
TIME_ELAPSED=`expr $TIME_ELAPSED + 1`
|
|
|
|
if [ $TIME_ELAPSED -gt $TIMEOUT ]
|
|
|
|
then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
def set_icecc_env():
|
|
|
|
# dummy python version of set_icecc_env
|
|
|
|
return
|
2024-09-09 08:52:07 +00:00
|
|
|
|
|
|
|
set_icecc_env() {
|
2024-09-09 08:57:42 +00:00
|
|
|
if [ "${@use_icc(bb, d)}" = "no" ]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
2024-09-09 08:52:07 +00:00
|
|
|
ICECC_VERSION="${@icc_version(bb, d)}"
|
|
|
|
if [ "x${ICECC_VERSION}" = "x" ]
|
|
|
|
then
|
2024-09-09 08:57:42 +00:00
|
|
|
bbwarn "Cannot use icecc: could not get ICECC_VERSION"
|
2024-09-09 08:52:07 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
ICE_PATH="${@icc_path(bb, d)}"
|
|
|
|
if [ "x${ICE_PATH}" = "x" ]
|
|
|
|
then
|
2024-09-09 08:57:42 +00:00
|
|
|
bbwarn "Cannot use icecc: could not get ICE_PATH"
|
2024-09-09 08:52:07 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
ICECC_CC="${@icc_get_and_check_tool(bb, d, "gcc")}"
|
|
|
|
ICECC_CXX="${@icc_get_and_check_tool(bb, d, "g++")}"
|
|
|
|
# cannot use icc_get_and_check_tool here because it assumes as without target_sys prefix
|
|
|
|
ICECC_WHICH_AS="${@bb.utils.which(os.getenv('PATH'), 'as')}"
|
2024-09-09 08:52:07 +00:00
|
|
|
if [ ! -x "${ICECC_CC}" -o ! -x "${ICECC_CXX}" ]
|
|
|
|
then
|
2024-09-09 08:57:42 +00:00
|
|
|
bbwarn "Cannot use icecc: could not get ICECC_CC or ICECC_CXX"
|
2024-09-09 08:52:07 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
ICE_VERSION=`$ICECC_CC -dumpversion`
|
|
|
|
ICECC_VERSION=`echo ${ICECC_VERSION} | sed -e "s/@VERSION@/$ICE_VERSION/g"`
|
|
|
|
if [ ! -x "${ICECC_ENV_EXEC}" ]
|
|
|
|
then
|
2024-09-09 08:57:42 +00:00
|
|
|
bbwarn "Cannot use icecc: invalid ICECC_ENV_EXEC"
|
2024-09-09 08:52:07 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
ICECC_AS="`${ICECC_CC} -print-prog-name=as`"
|
2024-09-09 08:57:42 +00:00
|
|
|
# for target recipes should return something like:
|
|
|
|
# /OE/tmp-eglibc/sysroots/x86_64-linux/usr/libexec/arm920tt-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.8.2/as
|
|
|
|
# and just "as" for native, if it returns "as" in current directory (for whatever reason) use "as" from PATH
|
2024-09-09 08:52:07 +00:00
|
|
|
if [ "`dirname "${ICECC_AS}"`" = "." ]
|
|
|
|
then
|
2024-09-09 08:57:42 +00:00
|
|
|
ICECC_AS="${ICECC_WHICH_AS}"
|
2024-09-09 08:52:07 +00:00
|
|
|
fi
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
if [ ! -f "${ICECC_VERSION}.done" ]
|
2024-09-09 08:52:07 +00:00
|
|
|
then
|
|
|
|
mkdir -p "`dirname "${ICECC_VERSION}"`"
|
2024-09-09 08:57:42 +00:00
|
|
|
|
|
|
|
# the ICECC_VERSION generation step must be locked by a mutex
|
|
|
|
# in order to prevent race conditions
|
|
|
|
if flock -n "${ICECC_VERSION}.lock" \
|
|
|
|
${ICECC_ENV_EXEC} "${ICECC_CC}" "${ICECC_CXX}" "${ICECC_AS}" "${ICECC_VERSION}"
|
|
|
|
then
|
|
|
|
touch "${ICECC_VERSION}.done"
|
|
|
|
elif [ ! wait_for_file "${ICECC_VERSION}.done" 30 ]
|
|
|
|
then
|
|
|
|
# locking failed so wait for ${ICECC_VERSION}.done to appear
|
|
|
|
bbwarn "Timeout waiting for ${ICECC_VERSION}.done"
|
|
|
|
return
|
|
|
|
fi
|
2024-09-09 08:52:07 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
export ICECC_VERSION ICECC_CC ICECC_CXX
|
|
|
|
export PATH="$ICE_PATH:$PATH"
|
|
|
|
export CCACHE_PATH="$PATH"
|
2024-09-09 08:57:42 +00:00
|
|
|
|
|
|
|
bbnote "Using icecc"
|
2024-09-09 08:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do_configure_prepend() {
|
|
|
|
set_icecc_env
|
|
|
|
}
|
|
|
|
|
|
|
|
do_compile_prepend() {
|
|
|
|
set_icecc_env
|
|
|
|
}
|
|
|
|
|
|
|
|
do_compile_kernelmodules_prepend() {
|
|
|
|
set_icecc_env
|
|
|
|
}
|
|
|
|
|
2024-09-09 08:57:42 +00:00
|
|
|
do_install_prepend() {
|
|
|
|
set_icecc_env
|
|
|
|
}
|