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