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