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