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 | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 37 | " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | |
| 39 | ICECC_ENV_EXEC ?= "${STAGING_BINDIR_NATIVE}/icecc-create-env" |
| 40 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 41 | HOSTTOOLS_NONFATAL += "icecc patchelf" |
| 42 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 43 | # 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: |
| 49 | # ICECC_ENV_VERSION_append = "-my-ver-1" |
| 50 | ICECC_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 |
| 57 | export ICECC_CARET_WORKAROUND ??= "0" |
| 58 | |
| 59 | ICECC_CFLAGS = "" |
| 60 | CFLAGS += "${ICECC_CFLAGS}" |
| 61 | CXXFLAGS += "${ICECC_CFLAGS}" |
| 62 | |
| 63 | # Debug flags when generating environments |
| 64 | ICECC_ENV_DEBUG ??= "" |
| 65 | |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 66 | # "system" recipe blacklist contains a list of packages that can not distribute |
| 67 | # compile tasks for one reason or the other. When adding new entry, please |
| 68 | # document why (how it failed) so that we can re-evaluate it later e.g. when |
| 69 | # there is new version |
| 70 | # |
| 71 | # libgcc-initial - fails with CPP sanity check error if host sysroot contains |
| 72 | # cross gcc built for another target tune/variant |
| 73 | # target-sdk-provides-dummy - ${HOST_PREFIX} is empty which triggers the "NULL |
| 74 | # prefix" error. |
| 75 | ICECC_SYSTEM_PACKAGE_BL += "\ |
| 76 | libgcc-initial \ |
| 77 | target-sdk-provides-dummy \ |
| 78 | " |
| 79 | |
| 80 | # "system" classes that should be blacklisted. When adding new entry, please |
| 81 | # document why (how it failed) so that we can re-evaluate it later |
| 82 | # |
| 83 | # image - Image aren't compiling, but the testing framework for images captures |
| 84 | # PARALLEL_MAKE as part of the test environment. Many tests won't use |
| 85 | # icecream, but leaving the high level of parallelism can cause them to |
| 86 | # consume an unnecessary amount of resources. |
| 87 | ICECC_SYSTEM_CLASS_BL += "\ |
| 88 | image \ |
| 89 | " |
| 90 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | def icecc_dep_prepend(d): |
| 92 | # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not |
| 93 | # we need that built is the responsibility of the patch function / class, not |
| 94 | # the application. |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 95 | if not d.getVar('INHIBIT_DEFAULT_DEPS'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | return "icecc-create-env-native" |
| 97 | return "" |
| 98 | |
| 99 | DEPENDS_prepend += "${@icecc_dep_prepend(d)} " |
| 100 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 101 | get_cross_kernel_cc[vardepsexclude] += "KERNEL_CC" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | def get_cross_kernel_cc(bb,d): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 103 | if not icecc_is_kernel(bb, d): |
| 104 | return None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | |
| 106 | # evaluate the expression by the shell if necessary |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 107 | kernel_cc = d.getVar('KERNEL_CC') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | if '`' in kernel_cc or '$(' in kernel_cc: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 109 | import subprocess |
| 110 | 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] | 111 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | kernel_cc = kernel_cc.replace('ccache', '').strip() |
| 113 | kernel_cc = kernel_cc.split(' ')[0] |
| 114 | kernel_cc = kernel_cc.strip() |
| 115 | return kernel_cc |
| 116 | |
| 117 | def get_icecc(d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 118 | 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] | 119 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 120 | def use_icecc(bb,d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 121 | if d.getVar('ICECC_DISABLED') == "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | # don't even try it, when explicitly disabled |
| 123 | return "no" |
| 124 | |
| 125 | # allarch recipes don't use compiler |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 126 | if icecc_is_allarch(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | return "no" |
| 128 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 129 | if icecc_is_cross_canadian(bb, d): |
| 130 | return "no" |
| 131 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 134 | system_class_blacklist = (d.getVar('ICECC_SYSTEM_CLASS_BL') or "").split() |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 135 | user_class_blacklist = (d.getVar('ICECC_USER_CLASS_BL') or "none").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | package_class_blacklist = system_class_blacklist + user_class_blacklist |
| 137 | |
| 138 | for black in package_class_blacklist: |
| 139 | if bb.data.inherits_class(black, d): |
| 140 | bb.debug(1, "%s: class %s found in blacklist, disable icecc" % (pn, black)) |
| 141 | return "no" |
| 142 | |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 143 | system_package_blacklist = (d.getVar('ICECC_SYSTEM_PACKAGE_BL') or "").split() |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 144 | user_package_blacklist = (d.getVar('ICECC_USER_PACKAGE_BL') or "").split() |
| 145 | user_package_whitelist = (d.getVar('ICECC_USER_PACKAGE_WL') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 146 | package_blacklist = system_package_blacklist + user_package_blacklist |
| 147 | |
| 148 | if pn in package_blacklist: |
| 149 | bb.debug(1, "%s: found in blacklist, disable icecc" % pn) |
| 150 | return "no" |
| 151 | |
| 152 | if pn in user_package_whitelist: |
| 153 | bb.debug(1, "%s: found in whitelist, enable icecc" % pn) |
| 154 | return "yes" |
| 155 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 156 | if d.getVar('PARALLEL_MAKE') == "": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 157 | bb.debug(1, "%s: has empty PARALLEL_MAKE, disable icecc" % pn) |
| 158 | return "no" |
| 159 | |
| 160 | return "yes" |
| 161 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 162 | def icecc_is_allarch(bb, d): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 163 | return d.getVar("PACKAGE_ARCH") == "all" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 165 | def icecc_is_kernel(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | return \ |
| 167 | bb.data.inherits_class("kernel", d); |
| 168 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 169 | def icecc_is_native(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 170 | return \ |
| 171 | bb.data.inherits_class("cross", d) or \ |
| 172 | bb.data.inherits_class("native", d); |
| 173 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 174 | def icecc_is_cross_canadian(bb, d): |
| 175 | return bb.data.inherits_class("cross-canadian", d) |
| 176 | |
| 177 | def icecc_dir(bb, d): |
| 178 | return d.expand('${TMPDIR}/work-shared/ice') |
| 179 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 180 | # Don't pollute allarch signatures with TARGET_FPU |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 181 | icecc_version[vardepsexclude] += "TARGET_FPU" |
| 182 | def icecc_version(bb, d): |
| 183 | if use_icecc(bb, d) == "no": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 184 | return "" |
| 185 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 186 | parallel = d.getVar('ICECC_PARALLEL_MAKE') or "" |
| 187 | if not d.getVar('PARALLEL_MAKE') == "" and parallel: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 188 | d.setVar("PARALLEL_MAKE", parallel) |
| 189 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 190 | # Disable showing the caret in the GCC compiler output if the workaround is |
| 191 | # disabled |
| 192 | if d.getVar('ICECC_CARET_WORKAROUND') == '0': |
| 193 | d.setVar('ICECC_CFLAGS', '-fno-diagnostics-show-caret') |
| 194 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 195 | if icecc_is_native(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | archive_name = "local-host-env" |
| 197 | elif d.expand('${HOST_PREFIX}') == "": |
| 198 | bb.fatal(d.expand("${PN}"), " NULL prefix") |
| 199 | else: |
| 200 | prefix = d.expand('${HOST_PREFIX}' ) |
| 201 | distro = d.expand('${DISTRO}') |
| 202 | target_sys = d.expand('${TARGET_SYS}') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 203 | float = d.getVar('TARGET_FPU') or "hard" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 204 | archive_name = prefix + distro + "-" + target_sys + "-" + float |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 205 | if icecc_is_kernel(bb, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 206 | archive_name += "-kernel" |
| 207 | |
| 208 | import socket |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 209 | ice_dir = icecc_dir(bb, d) |
| 210 | tar_file = os.path.join(ice_dir, "{archive}-{version}-@VERSION@-{hostname}.tar.gz".format( |
| 211 | archive=archive_name, |
| 212 | version=d.getVar('ICECC_ENV_VERSION'), |
| 213 | hostname=socket.gethostname() |
| 214 | )) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 215 | |
| 216 | return tar_file |
| 217 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 218 | def icecc_path(bb,d): |
| 219 | if use_icecc(bb, d) == "no": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | # don't create unnecessary directories when icecc is disabled |
| 221 | return |
| 222 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 223 | staging = os.path.join(d.expand('${STAGING_BINDIR}'), "ice") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 224 | if icecc_is_kernel(bb, d): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 225 | staging += "-kernel" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 227 | return staging |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 229 | def icecc_get_external_tool(bb, d, tool): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | external_toolchain_bindir = d.expand('${EXTERNAL_TOOLCHAIN}${bindir_cross}') |
| 231 | target_prefix = d.expand('${TARGET_PREFIX}') |
| 232 | return os.path.join(external_toolchain_bindir, '%s%s' % (target_prefix, tool)) |
| 233 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 234 | def icecc_get_tool_link(tool, d): |
| 235 | import subprocess |
| 236 | return subprocess.check_output("readlink -f %s" % tool, shell=True).decode("utf-8")[:-1] |
| 237 | |
| 238 | def icecc_get_path_tool(tool, d): |
| 239 | # This is a little ugly, but we want to make sure we add an actual |
| 240 | # compiler to the toolchain, not ccache. Some distros (e.g. Fedora) |
| 241 | # have ccache enabled by default using symlinks PATH, meaning ccache |
| 242 | # would be found first when looking for the compiler. |
| 243 | paths = os.getenv("PATH").split(':') |
| 244 | while True: |
| 245 | p, hist = bb.utils.which(':'.join(paths), tool, history=True) |
| 246 | if not p or os.path.basename(icecc_get_tool_link(p, d)) != 'ccache': |
| 247 | return p |
| 248 | paths = paths[len(hist):] |
| 249 | |
| 250 | return "" |
| 251 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | # 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] | 253 | icecc_get_tool[vardepsexclude] += "STAGING_BINDIR_TOOLCHAIN" |
| 254 | def icecc_get_tool(bb, d, tool): |
| 255 | if icecc_is_native(bb, d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 256 | return icecc_get_path_tool(tool, d) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 257 | elif icecc_is_kernel(bb, d): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 258 | return icecc_get_path_tool(get_cross_kernel_cc(bb, d), d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | else: |
| 260 | ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}') |
| 261 | target_sys = d.expand('${TARGET_SYS}') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 262 | for p in ice_dir.split(':'): |
| 263 | tool_bin = os.path.join(p, "%s-%s" % (target_sys, tool)) |
| 264 | if os.path.isfile(tool_bin): |
| 265 | return tool_bin |
| 266 | external_tool_bin = icecc_get_external_tool(bb, d, tool) |
| 267 | if os.path.isfile(external_tool_bin): |
| 268 | return external_tool_bin |
| 269 | return "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 271 | def icecc_get_and_check_tool(bb, d, tool): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 272 | # Check that g++ or gcc is not a symbolic link to icecc binary in |
| 273 | # PATH or icecc-create-env script will silently create an invalid |
| 274 | # compiler environment package. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 275 | t = icecc_get_tool(bb, d, tool) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 276 | if t: |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 277 | link_path = icecc_get_tool_link(t, d) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 278 | if link_path == get_icecc(d): |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 279 | 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] | 280 | return "" |
| 281 | else: |
| 282 | return t |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 283 | else: |
| 284 | return t |
| 285 | |
| 286 | wait_for_file() { |
| 287 | local TIME_ELAPSED=0 |
| 288 | local FILE_TO_TEST=$1 |
| 289 | local TIMEOUT=$2 |
| 290 | until [ -f "$FILE_TO_TEST" ] |
| 291 | do |
| 292 | TIME_ELAPSED=`expr $TIME_ELAPSED + 1` |
| 293 | if [ $TIME_ELAPSED -gt $TIMEOUT ] |
| 294 | then |
| 295 | return 1 |
| 296 | fi |
| 297 | sleep 1 |
| 298 | done |
| 299 | } |
| 300 | |
| 301 | def set_icecc_env(): |
| 302 | # dummy python version of set_icecc_env |
| 303 | return |
| 304 | |
| 305 | set_icecc_env() { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 306 | if [ "${@use_icecc(bb, d)}" = "no" ] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 307 | then |
| 308 | return |
| 309 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 310 | ICECC_VERSION="${@icecc_version(bb, d)}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 311 | if [ "x${ICECC_VERSION}" = "x" ] |
| 312 | then |
| 313 | bbwarn "Cannot use icecc: could not get ICECC_VERSION" |
| 314 | return |
| 315 | fi |
| 316 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 317 | ICE_PATH="${@icecc_path(bb, d)}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 318 | if [ "x${ICE_PATH}" = "x" ] |
| 319 | then |
| 320 | bbwarn "Cannot use icecc: could not get ICE_PATH" |
| 321 | return |
| 322 | fi |
| 323 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 324 | ICECC_BIN="${@get_icecc(d)}" |
| 325 | if [ -z "${ICECC_BIN}" ]; then |
| 326 | bbwarn "Cannot use icecc: icecc binary not found" |
| 327 | return |
| 328 | fi |
| 329 | if [ -z "$(which patchelf patchelf-uninative)" ]; then |
| 330 | bbwarn "Cannot use icecc: patchelf not found" |
| 331 | return |
| 332 | fi |
| 333 | |
| 334 | # Create symlinks to icecc in the recipe-sysroot directory |
| 335 | mkdir -p ${ICE_PATH} |
| 336 | if [ -n "${KERNEL_CC}" ]; then |
| 337 | compilers="${@get_cross_kernel_cc(bb,d)}" |
| 338 | else |
| 339 | compilers="${HOST_PREFIX}gcc ${HOST_PREFIX}g++" |
| 340 | fi |
| 341 | for compiler in $compilers; do |
| 342 | ln -sf ${ICECC_BIN} ${ICE_PATH}/$compiler |
| 343 | done |
| 344 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 345 | ICECC_CC="${@icecc_get_and_check_tool(bb, d, "gcc")}" |
| 346 | ICECC_CXX="${@icecc_get_and_check_tool(bb, d, "g++")}" |
| 347 | # 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] | 348 | ICECC_WHICH_AS="${@bb.utils.which(os.getenv('PATH'), 'as')}" |
| 349 | if [ ! -x "${ICECC_CC}" -o ! -x "${ICECC_CXX}" ] |
| 350 | then |
| 351 | bbwarn "Cannot use icecc: could not get ICECC_CC or ICECC_CXX" |
| 352 | return |
| 353 | fi |
| 354 | |
| 355 | ICE_VERSION=`$ICECC_CC -dumpversion` |
| 356 | ICECC_VERSION=`echo ${ICECC_VERSION} | sed -e "s/@VERSION@/$ICE_VERSION/g"` |
| 357 | if [ ! -x "${ICECC_ENV_EXEC}" ] |
| 358 | then |
| 359 | bbwarn "Cannot use icecc: invalid ICECC_ENV_EXEC" |
| 360 | return |
| 361 | fi |
| 362 | |
| 363 | ICECC_AS="`${ICECC_CC} -print-prog-name=as`" |
| 364 | # for target recipes should return something like: |
| 365 | # /OE/tmp-eglibc/sysroots/x86_64-linux/usr/libexec/arm920tt-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.8.2/as |
| 366 | # and just "as" for native, if it returns "as" in current directory (for whatever reason) use "as" from PATH |
| 367 | if [ "`dirname "${ICECC_AS}"`" = "." ] |
| 368 | then |
| 369 | ICECC_AS="${ICECC_WHICH_AS}" |
| 370 | fi |
| 371 | |
| 372 | if [ ! -f "${ICECC_VERSION}.done" ] |
| 373 | then |
| 374 | mkdir -p "`dirname "${ICECC_VERSION}"`" |
| 375 | |
| 376 | # the ICECC_VERSION generation step must be locked by a mutex |
| 377 | # in order to prevent race conditions |
| 378 | if flock -n "${ICECC_VERSION}.lock" \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 379 | ${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] | 380 | then |
| 381 | touch "${ICECC_VERSION}.done" |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame^] | 382 | elif ! wait_for_file "${ICECC_VERSION}.done" 30 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 383 | then |
| 384 | # locking failed so wait for ${ICECC_VERSION}.done to appear |
| 385 | bbwarn "Timeout waiting for ${ICECC_VERSION}.done" |
| 386 | return |
| 387 | fi |
| 388 | fi |
| 389 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 390 | # Don't let ccache find the icecream compiler links that have been created, otherwise |
| 391 | # it can end up invoking icecream recursively. |
| 392 | export CCACHE_PATH="$PATH" |
Brad Bishop | a5c52ff | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 393 | export CCACHE_DISABLE="1" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 394 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 395 | export ICECC_VERSION ICECC_CC ICECC_CXX |
| 396 | export PATH="$ICE_PATH:$PATH" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 397 | |
| 398 | bbnote "Using icecc" |
| 399 | } |
| 400 | |
| 401 | do_configure_prepend() { |
| 402 | set_icecc_env |
| 403 | } |
| 404 | |
| 405 | do_compile_prepend() { |
| 406 | set_icecc_env |
| 407 | } |
| 408 | |
| 409 | do_compile_kernelmodules_prepend() { |
| 410 | set_icecc_env |
| 411 | } |
| 412 | |
| 413 | do_install_prepend() { |
| 414 | set_icecc_env |
| 415 | } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 416 | |
| 417 | # IceCream is not (currently) supported in the extensible SDK |
| 418 | ICECC_SDK_HOST_TASK = "nativesdk-icecc-toolchain" |
| 419 | ICECC_SDK_HOST_TASK_task-populate-sdk-ext = "" |
| 420 | |
| 421 | # Don't include IceCream in uninative tarball |
| 422 | ICECC_SDK_HOST_TASK_pn-uninative-tarball = "" |
| 423 | |
| 424 | # Add the toolchain scripts to the SDK |
| 425 | TOOLCHAIN_HOST_TASK_append = " ${ICECC_SDK_HOST_TASK}" |