Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Sanity check the users setup for common misconfigurations |
| 3 | # |
| 4 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 5 | SANITY_REQUIRED_UTILITIES ?= "patch diffstat git bzip2 tar \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6 | gzip gawk chrpath wget cpio perl file which" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | |
| 8 | def bblayers_conf_file(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9 | return os.path.join(d.getVar('TOPDIR'), 'conf/bblayers.conf') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
| 11 | def sanity_conf_read(fn): |
| 12 | with open(fn, 'r') as f: |
| 13 | lines = f.readlines() |
| 14 | return lines |
| 15 | |
| 16 | def sanity_conf_find_line(pattern, lines): |
| 17 | import re |
| 18 | return next(((index, line) |
| 19 | for index, line in enumerate(lines) |
| 20 | if re.search(pattern, line)), (None, None)) |
| 21 | |
| 22 | def sanity_conf_update(fn, lines, version_var_name, new_version): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 23 | index, line = sanity_conf_find_line(r"^%s" % version_var_name, lines) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | lines[index] = '%s = "%d"\n' % (version_var_name, new_version) |
| 25 | with open(fn, "w") as f: |
| 26 | f.write(''.join(lines)) |
| 27 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 28 | # Functions added to this variable MUST throw a NotImplementedError exception unless |
| 29 | # they successfully changed the config version in the config file. Exceptions |
| 30 | # are used since exec_func doesn't handle return values. |
| 31 | BBLAYERS_CONF_UPDATE_FUNCS += " \ |
| 32 | conf/bblayers.conf:LCONF_VERSION:LAYER_CONF_VERSION:oecore_update_bblayers \ |
| 33 | conf/local.conf:CONF_VERSION:LOCALCONF_VERSION:oecore_update_localconf \ |
| 34 | conf/site.conf:SCONF_VERSION:SITE_CONF_VERSION:oecore_update_siteconf \ |
| 35 | " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 37 | SANITY_DIFF_TOOL ?= "meld" |
| 38 | |
| 39 | SANITY_LOCALCONF_SAMPLE ?= "${COREBASE}/meta*/conf/local.conf.sample" |
| 40 | python oecore_update_localconf() { |
| 41 | # Check we are using a valid local.conf |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | current_conf = d.getVar('CONF_VERSION') |
| 43 | conf_version = d.getVar('LOCALCONF_VERSION') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 44 | |
| 45 | failmsg = """Your version of local.conf was generated from an older/newer version of |
| 46 | local.conf.sample and there have been updates made to this file. Please compare the two |
| 47 | files and merge any changes before continuing. |
| 48 | |
| 49 | Matching the version numbers will remove this message. |
| 50 | |
| 51 | \"${SANITY_DIFF_TOOL} conf/local.conf ${SANITY_LOCALCONF_SAMPLE}\" |
| 52 | |
| 53 | is a good way to visualise the changes.""" |
| 54 | failmsg = d.expand(failmsg) |
| 55 | |
| 56 | raise NotImplementedError(failmsg) |
| 57 | } |
| 58 | |
| 59 | SANITY_SITECONF_SAMPLE ?= "${COREBASE}/meta*/conf/site.conf.sample" |
| 60 | python oecore_update_siteconf() { |
| 61 | # If we have a site.conf, check it's valid |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 62 | current_sconf = d.getVar('SCONF_VERSION') |
| 63 | sconf_version = d.getVar('SITE_CONF_VERSION') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 64 | |
| 65 | failmsg = """Your version of site.conf was generated from an older version of |
| 66 | site.conf.sample and there have been updates made to this file. Please compare the two |
| 67 | files and merge any changes before continuing. |
| 68 | |
| 69 | Matching the version numbers will remove this message. |
| 70 | |
| 71 | \"${SANITY_DIFF_TOOL} conf/site.conf ${SANITY_SITECONF_SAMPLE}\" |
| 72 | |
| 73 | is a good way to visualise the changes.""" |
| 74 | failmsg = d.expand(failmsg) |
| 75 | |
| 76 | raise NotImplementedError(failmsg) |
| 77 | } |
| 78 | |
| 79 | SANITY_BBLAYERCONF_SAMPLE ?= "${COREBASE}/meta*/conf/bblayers.conf.sample" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 80 | python oecore_update_bblayers() { |
| 81 | # bblayers.conf is out of date, so see if we can resolve that |
| 82 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 83 | current_lconf = int(d.getVar('LCONF_VERSION')) |
| 84 | lconf_version = int(d.getVar('LAYER_CONF_VERSION')) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 85 | |
| 86 | failmsg = """Your version of bblayers.conf has the wrong LCONF_VERSION (has ${LCONF_VERSION}, expecting ${LAYER_CONF_VERSION}). |
| 87 | Please compare your file against bblayers.conf.sample and merge any changes before continuing. |
| 88 | "${SANITY_DIFF_TOOL} conf/bblayers.conf ${SANITY_BBLAYERCONF_SAMPLE}" |
| 89 | |
| 90 | is a good way to visualise the changes.""" |
| 91 | failmsg = d.expand(failmsg) |
| 92 | |
| 93 | if not current_lconf: |
| 94 | raise NotImplementedError(failmsg) |
| 95 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | lines = [] |
| 97 | |
| 98 | if current_lconf < 4: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 99 | raise NotImplementedError(failmsg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | |
| 101 | bblayers_fn = bblayers_conf_file(d) |
| 102 | lines = sanity_conf_read(bblayers_fn) |
| 103 | |
| 104 | if current_lconf == 4 and lconf_version > 4: |
| 105 | topdir_var = '$' + '{TOPDIR}' |
| 106 | index, bbpath_line = sanity_conf_find_line('BBPATH', lines) |
| 107 | if bbpath_line: |
| 108 | start = bbpath_line.find('"') |
| 109 | if start != -1 and (len(bbpath_line) != (start + 1)): |
| 110 | if bbpath_line[start + 1] == '"': |
| 111 | lines[index] = (bbpath_line[:start + 1] + |
| 112 | topdir_var + bbpath_line[start + 1:]) |
| 113 | else: |
| 114 | if not topdir_var in bbpath_line: |
| 115 | lines[index] = (bbpath_line[:start + 1] + |
| 116 | topdir_var + ':' + bbpath_line[start + 1:]) |
| 117 | else: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 118 | raise NotImplementedError(failmsg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | else: |
| 120 | index, bbfiles_line = sanity_conf_find_line('BBFILES', lines) |
| 121 | if bbfiles_line: |
| 122 | lines.insert(index, 'BBPATH = "' + topdir_var + '"\n') |
| 123 | else: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 124 | raise NotImplementedError(failmsg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 125 | |
| 126 | current_lconf += 1 |
| 127 | sanity_conf_update(bblayers_fn, lines, 'LCONF_VERSION', current_lconf) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 128 | bb.note("Your conf/bblayers.conf has been automatically updated.") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 129 | return |
| 130 | |
| 131 | elif current_lconf == 5 and lconf_version > 5: |
| 132 | # Null update, to avoid issues with people switching between poky and other distros |
| 133 | current_lconf = 6 |
| 134 | sanity_conf_update(bblayers_fn, lines, 'LCONF_VERSION', current_lconf) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 135 | bb.note("Your conf/bblayers.conf has been automatically updated.") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | return |
| 137 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 138 | status.addresult() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 139 | |
| 140 | elif current_lconf == 6 and lconf_version > 6: |
| 141 | # Handle rename of meta-yocto -> meta-poky |
| 142 | # This marks the start of separate version numbers but code is needed in OE-Core |
| 143 | # for the migration, one last time. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 144 | layers = d.getVar('BBLAYERS').split() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 145 | layers = [ os.path.basename(path) for path in layers ] |
| 146 | if 'meta-yocto' in layers: |
| 147 | found = False |
| 148 | while True: |
| 149 | index, meta_yocto_line = sanity_conf_find_line(r'.*meta-yocto[\'"\s\n]', lines) |
| 150 | if meta_yocto_line: |
| 151 | lines[index] = meta_yocto_line.replace('meta-yocto', 'meta-poky') |
| 152 | found = True |
| 153 | else: |
| 154 | break |
| 155 | if not found: |
| 156 | raise NotImplementedError(failmsg) |
| 157 | index, meta_yocto_line = sanity_conf_find_line('LCONF_VERSION.*\n', lines) |
| 158 | if meta_yocto_line: |
| 159 | lines[index] = 'POKY_BBLAYERS_CONF_VERSION = "1"\n' |
| 160 | else: |
| 161 | raise NotImplementedError(failmsg) |
| 162 | with open(bblayers_fn, "w") as f: |
| 163 | f.write(''.join(lines)) |
| 164 | bb.note("Your conf/bblayers.conf has been automatically updated.") |
| 165 | return |
| 166 | current_lconf += 1 |
| 167 | sanity_conf_update(bblayers_fn, lines, 'LCONF_VERSION', current_lconf) |
| 168 | bb.note("Your conf/bblayers.conf has been automatically updated.") |
| 169 | return |
| 170 | |
| 171 | raise NotImplementedError(failmsg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | def raise_sanity_error(msg, d, network_error=False): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 175 | if d.getVar("SANITY_USE_EVENTS") == "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 176 | try: |
| 177 | bb.event.fire(bb.event.SanityCheckFailed(msg, network_error), d) |
| 178 | except TypeError: |
| 179 | bb.event.fire(bb.event.SanityCheckFailed(msg), d) |
| 180 | return |
| 181 | |
| 182 | bb.fatal(""" OE-core's config sanity checker detected a potential misconfiguration. |
| 183 | Either fix the cause of this error or at your own risk disable the checker (see sanity.conf). |
| 184 | Following is the list of potential problems / advisories: |
| 185 | |
| 186 | %s""" % msg) |
| 187 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 188 | # Check a single tune for validity. |
| 189 | def check_toolchain_tune(data, tune, multilib): |
| 190 | tune_errors = [] |
| 191 | if not tune: |
| 192 | return "No tuning found for %s multilib." % multilib |
| 193 | localdata = bb.data.createCopy(data) |
| 194 | if multilib != "default": |
| 195 | # Apply the overrides so we can look at the details. |
| 196 | overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + multilib |
| 197 | localdata.setVar("OVERRIDES", overrides) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 198 | bb.debug(2, "Sanity-checking tuning '%s' (%s) features:" % (tune, multilib)) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 199 | features = (localdata.getVar("TUNE_FEATURES:tune-%s" % tune) or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | if not features: |
| 201 | return "Tuning '%s' has no defined features, and cannot be used." % tune |
| 202 | valid_tunes = localdata.getVarFlags('TUNEVALID') or {} |
| 203 | conflicts = localdata.getVarFlags('TUNECONFLICTS') or {} |
| 204 | # [doc] is the documentation for the variable, not a real feature |
| 205 | if 'doc' in valid_tunes: |
| 206 | del valid_tunes['doc'] |
| 207 | if 'doc' in conflicts: |
| 208 | del conflicts['doc'] |
| 209 | for feature in features: |
| 210 | if feature in conflicts: |
| 211 | for conflict in conflicts[feature].split(): |
| 212 | if conflict in features: |
| 213 | tune_errors.append("Feature '%s' conflicts with '%s'." % |
| 214 | (feature, conflict)) |
| 215 | if feature in valid_tunes: |
| 216 | bb.debug(2, " %s: %s" % (feature, valid_tunes[feature])) |
| 217 | else: |
| 218 | tune_errors.append("Feature '%s' is not defined." % feature) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 219 | if tune_errors: |
| 220 | return "Tuning '%s' has the following errors:\n" % tune + '\n'.join(tune_errors) |
| 221 | |
| 222 | def check_toolchain(data): |
| 223 | tune_error_set = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 224 | deftune = data.getVar("DEFAULTTUNE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 225 | tune_errors = check_toolchain_tune(data, deftune, 'default') |
| 226 | if tune_errors: |
| 227 | tune_error_set.append(tune_errors) |
| 228 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 229 | multilibs = (data.getVar("MULTILIB_VARIANTS") or "").split() |
| 230 | global_multilibs = (data.getVar("MULTILIB_GLOBAL_VARIANTS") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | |
| 232 | if multilibs: |
| 233 | seen_libs = [] |
| 234 | seen_tunes = [] |
| 235 | for lib in multilibs: |
| 236 | if lib in seen_libs: |
| 237 | tune_error_set.append("The multilib '%s' appears more than once." % lib) |
| 238 | else: |
| 239 | seen_libs.append(lib) |
| 240 | if not lib in global_multilibs: |
| 241 | tune_error_set.append("Multilib %s is not present in MULTILIB_GLOBAL_VARIANTS" % lib) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 242 | tune = data.getVar("DEFAULTTUNE:virtclass-multilib-%s" % lib) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 243 | if tune in seen_tunes: |
| 244 | tune_error_set.append("The tuning '%s' appears in more than one multilib." % tune) |
| 245 | else: |
| 246 | seen_libs.append(tune) |
| 247 | if tune == deftune: |
| 248 | tune_error_set.append("Multilib '%s' (%s) is also the default tuning." % (lib, deftune)) |
| 249 | else: |
| 250 | tune_errors = check_toolchain_tune(data, tune, lib) |
| 251 | if tune_errors: |
| 252 | tune_error_set.append(tune_errors) |
| 253 | if tune_error_set: |
| 254 | return "Toolchain tunings invalid:\n" + '\n'.join(tune_error_set) + "\n" |
| 255 | |
| 256 | return "" |
| 257 | |
| 258 | def check_conf_exists(fn, data): |
| 259 | bbpath = [] |
| 260 | fn = data.expand(fn) |
| 261 | vbbpath = data.getVar("BBPATH", False) |
| 262 | if vbbpath: |
| 263 | bbpath += vbbpath.split(":") |
| 264 | for p in bbpath: |
| 265 | currname = os.path.join(data.expand(p), fn) |
| 266 | if os.access(currname, os.R_OK): |
| 267 | return True |
| 268 | return False |
| 269 | |
| 270 | def check_create_long_filename(filepath, pathname): |
| 271 | import string, random |
| 272 | testfile = os.path.join(filepath, ''.join(random.choice(string.ascii_letters) for x in range(200))) |
| 273 | try: |
| 274 | if not os.path.exists(filepath): |
| 275 | bb.utils.mkdirhier(filepath) |
| 276 | f = open(testfile, "w") |
| 277 | f.close() |
| 278 | os.remove(testfile) |
| 279 | except IOError as e: |
| 280 | import errno |
| 281 | err, strerror = e.args |
| 282 | if err == errno.ENAMETOOLONG: |
| 283 | return "Failed to create a file with a long name in %s. Please use a filesystem that does not unreasonably limit filename length.\n" % pathname |
| 284 | else: |
| 285 | return "Failed to create a file in %s: %s.\n" % (pathname, strerror) |
| 286 | except OSError as e: |
| 287 | errno, strerror = e.args |
| 288 | return "Failed to create %s directory in which to run long name sanity check: %s.\n" % (pathname, strerror) |
| 289 | return "" |
| 290 | |
| 291 | def check_path_length(filepath, pathname, limit): |
| 292 | if len(filepath) > limit: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 293 | return "The length of %s is longer than %s, this would cause unexpected errors, please use a shorter path.\n" % (pathname, limit) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 294 | return "" |
| 295 | |
| 296 | def get_filesystem_id(path): |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 297 | import subprocess |
| 298 | try: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 299 | return subprocess.check_output(["stat", "-f", "-c", "%t", path]).decode('utf-8').strip() |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 300 | except subprocess.CalledProcessError: |
| 301 | bb.warn("Can't get filesystem id of: %s" % path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 302 | return None |
| 303 | |
| 304 | # Check that the path isn't located on nfs. |
| 305 | def check_not_nfs(path, name): |
| 306 | # The nfs' filesystem id is 6969 |
| 307 | if get_filesystem_id(path) == "6969": |
| 308 | return "The %s: %s can't be located on nfs.\n" % (name, path) |
| 309 | return "" |
| 310 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 311 | # Check that the path is on a case-sensitive file system |
| 312 | def check_case_sensitive(path, name): |
| 313 | import tempfile |
| 314 | with tempfile.NamedTemporaryFile(prefix='TmP', dir=path) as tmp_file: |
| 315 | if os.path.exists(tmp_file.name.lower()): |
| 316 | return "The %s (%s) can't be on a case-insensitive file system.\n" % (name, path) |
| 317 | return "" |
| 318 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 319 | # Check that path isn't a broken symlink |
| 320 | def check_symlink(lnk, data): |
| 321 | if os.path.islink(lnk) and not os.path.exists(lnk): |
| 322 | raise_sanity_error("%s is a broken symlink." % lnk, data) |
| 323 | |
| 324 | def check_connectivity(d): |
| 325 | # URI's to check can be set in the CONNECTIVITY_CHECK_URIS variable |
| 326 | # using the same syntax as for SRC_URI. If the variable is not set |
| 327 | # the check is skipped |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 328 | test_uris = (d.getVar('CONNECTIVITY_CHECK_URIS') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 329 | retval = "" |
| 330 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 331 | bbn = d.getVar('BB_NO_NETWORK') |
| 332 | if bbn not in (None, '0', '1'): |
| 333 | return 'BB_NO_NETWORK should be "0" or "1", but it is "%s"' % bbn |
| 334 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 335 | # Only check connectivity if network enabled and the |
| 336 | # CONNECTIVITY_CHECK_URIS are set |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 337 | network_enabled = not (bbn == '1') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 338 | check_enabled = len(test_uris) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 339 | if check_enabled and network_enabled: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 340 | # Take a copy of the data store and unset MIRRORS and PREMIRRORS |
| 341 | data = bb.data.createCopy(d) |
| 342 | data.delVar('PREMIRRORS') |
| 343 | data.delVar('MIRRORS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 344 | try: |
| 345 | fetcher = bb.fetch2.Fetch(test_uris, data) |
| 346 | fetcher.checkstatus() |
| 347 | except Exception as err: |
| 348 | # Allow the message to be configured so that users can be |
| 349 | # pointed to a support mechanism. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 350 | msg = data.getVar('CONNECTIVITY_CHECK_MSG') or "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | if len(msg) == 0: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 352 | msg = "%s.\n" % err |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 353 | msg += " Please ensure your host's network is configured correctly.\n" |
| 354 | msg += " If your ISP or network is blocking the above URL,\n" |
| 355 | msg += " try with another domain name, for example by setting:\n" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 356 | msg += " CONNECTIVITY_CHECK_URIS = \"https://www.example.com/\"" |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 357 | msg += " You could also set BB_NO_NETWORK = \"1\" to disable network\n" |
| 358 | msg += " access if all required sources are on local disk.\n" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 359 | retval = msg |
| 360 | |
| 361 | return retval |
| 362 | |
| 363 | def check_supported_distro(sanity_data): |
| 364 | from fnmatch import fnmatch |
| 365 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 366 | tested_distros = sanity_data.getVar('SANITY_TESTED_DISTROS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | if not tested_distros: |
| 368 | return |
| 369 | |
| 370 | try: |
| 371 | distro = oe.lsb.distro_identifier() |
| 372 | except Exception: |
| 373 | distro = None |
| 374 | |
| 375 | if not distro: |
| 376 | bb.warn('Host distribution could not be determined; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.') |
| 377 | |
| 378 | for supported in [x.strip() for x in tested_distros.split('\\n')]: |
| 379 | if fnmatch(distro, supported): |
| 380 | return |
| 381 | |
| 382 | bb.warn('Host distribution "%s" has not been validated with this version of the build system; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.' % distro) |
| 383 | |
| 384 | # Checks we should only make if MACHINE is set correctly |
| 385 | def check_sanity_validmachine(sanity_data): |
| 386 | messages = "" |
| 387 | |
| 388 | # Check TUNE_ARCH is set |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 389 | if sanity_data.getVar('TUNE_ARCH') == 'INVALID': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 390 | messages = messages + 'TUNE_ARCH is unset. Please ensure your MACHINE configuration includes a valid tune configuration file which will set this correctly.\n' |
| 391 | |
| 392 | # Check TARGET_OS is set |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 393 | if sanity_data.getVar('TARGET_OS') == 'INVALID': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 394 | messages = messages + 'Please set TARGET_OS directly, or choose a MACHINE or DISTRO that does so.\n' |
| 395 | |
| 396 | # Check that we don't have duplicate entries in PACKAGE_ARCHS & that TUNE_PKGARCH is in PACKAGE_ARCHS |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 397 | pkgarchs = sanity_data.getVar('PACKAGE_ARCHS') |
| 398 | tunepkg = sanity_data.getVar('TUNE_PKGARCH') |
| 399 | defaulttune = sanity_data.getVar('DEFAULTTUNE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 400 | tunefound = False |
| 401 | seen = {} |
| 402 | dups = [] |
| 403 | |
| 404 | for pa in pkgarchs.split(): |
| 405 | if seen.get(pa, 0) == 1: |
| 406 | dups.append(pa) |
| 407 | else: |
| 408 | seen[pa] = 1 |
| 409 | if pa == tunepkg: |
| 410 | tunefound = True |
| 411 | |
| 412 | if len(dups): |
| 413 | messages = messages + "Error, the PACKAGE_ARCHS variable contains duplicates. The following archs are listed more than once: %s" % " ".join(dups) |
| 414 | |
| 415 | if tunefound == False: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 416 | messages = messages + "Error, the PACKAGE_ARCHS variable (%s) for DEFAULTTUNE (%s) does not contain TUNE_PKGARCH (%s)." % (pkgarchs, defaulttune, tunepkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 417 | |
| 418 | return messages |
| 419 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 420 | # Patch before 2.7 can't handle all the features in git-style diffs. Some |
| 421 | # patches may incorrectly apply, and others won't apply at all. |
| 422 | def check_patch_version(sanity_data): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 423 | import re, subprocess |
| 424 | |
| 425 | try: |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 426 | result = subprocess.check_output(["patch", "--version"], stderr=subprocess.STDOUT).decode('utf-8') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 427 | version = re.search(r"[0-9.]+", result.splitlines()[0]).group() |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 428 | if bb.utils.vercmp_string_op(version, "2.7", "<"): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 429 | return "Your version of patch is older than 2.7 and has bugs which will break builds. Please install a newer version of patch.\n" |
| 430 | else: |
| 431 | return None |
| 432 | except subprocess.CalledProcessError as e: |
| 433 | return "Unable to execute patch --version, exit code %d:\n%s\n" % (e.returncode, e.output) |
| 434 | |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 435 | # Glibc needs make 4.0 or later, we may as well match at this point |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 436 | def check_make_version(sanity_data): |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 437 | import subprocess |
| 438 | |
| 439 | try: |
| 440 | result = subprocess.check_output(['make', '--version'], stderr=subprocess.STDOUT).decode('utf-8') |
| 441 | except subprocess.CalledProcessError as e: |
| 442 | return "Unable to execute make --version, exit code %d\n%s\n" % (e.returncode, e.output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 443 | version = result.split()[2] |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 444 | if bb.utils.vercmp_string_op(version, "4.0", "<"): |
| 445 | return "Please install a make version of 4.0 or later.\n" |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 446 | |
| 447 | if bb.utils.vercmp_string_op(version, "4.2.1", "=="): |
| 448 | distro = oe.lsb.distro_identifier() |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 449 | if "ubuntu" in distro or "debian" in distro or "linuxmint" in distro: |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 450 | return None |
| 451 | return "make version 4.2.1 is known to have issues on Centos/OpenSUSE and other non-Ubuntu systems. Please use a buildtools-make-tarball or a newer version of make.\n" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 452 | return None |
| 453 | |
| 454 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 455 | # Check if we're running on WSL (Windows Subsystem for Linux). |
| 456 | # WSLv1 is known not to work but WSLv2 should work properly as |
| 457 | # long as the VHDX file is optimized often, let the user know |
| 458 | # upfront. |
| 459 | # More information on installing WSLv2 at: |
| 460 | # https://docs.microsoft.com/en-us/windows/wsl/wsl2-install |
Brad Bishop | e2d5b61 | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 461 | def check_wsl(d): |
| 462 | with open("/proc/version", "r") as f: |
| 463 | verdata = f.readlines() |
| 464 | for l in verdata: |
| 465 | if "Microsoft" in l: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 466 | return "OpenEmbedded doesn't work under WSLv1, please upgrade to WSLv2 if you want to run builds on Windows" |
| 467 | elif "microsoft" in l: |
| 468 | bb.warn("You are running bitbake under WSLv2, this works properly but you should optimize your VHDX file eventually to avoid running out of storage space") |
| 469 | return None |
| 470 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 471 | # Require at least gcc version 7.5. |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 472 | # |
| 473 | # This can be fixed on CentOS-7 with devtoolset-6+ |
| 474 | # https://www.softwarecollections.org/en/scls/rhscl/devtoolset-6/ |
| 475 | # |
| 476 | # A less invasive fix is with scripts/install-buildtools (or with user |
| 477 | # built buildtools-extended-tarball) |
| 478 | # |
| 479 | def check_gcc_version(sanity_data): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 480 | import subprocess |
| 481 | |
| 482 | build_cc, version = oe.utils.get_host_compiler_version(sanity_data) |
| 483 | if build_cc.strip() == "gcc": |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 484 | if bb.utils.vercmp_string_op(version, "7.5", "<"): |
| 485 | return "Your version of gcc is older than 7.5 and will break builds. Please install a newer version of gcc (you could use the project's buildtools-extended-tarball or use scripts/install-buildtools).\n" |
Brad Bishop | e2d5b61 | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 486 | return None |
| 487 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 488 | # Tar version 1.24 and onwards handle overwriting symlinks correctly |
| 489 | # but earlier versions do not; this needs to work properly for sstate |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 490 | # Version 1.28 is needed so opkg-build works correctly when reproducibile builds are enabled |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 491 | def check_tar_version(sanity_data): |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 492 | import subprocess |
| 493 | try: |
| 494 | result = subprocess.check_output(["tar", "--version"], stderr=subprocess.STDOUT).decode('utf-8') |
| 495 | except subprocess.CalledProcessError as e: |
| 496 | return "Unable to execute tar --version, exit code %d\n%s\n" % (e.returncode, e.output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 497 | version = result.split()[3] |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 498 | if bb.utils.vercmp_string_op(version, "1.28", "<"): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 499 | return "Your version of tar is older than 1.28 and does not have the support needed to enable reproducible builds. Please install a newer version of tar (you could use the project's buildtools-tarball from our last release or use scripts/install-buildtools).\n" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 500 | return None |
| 501 | |
| 502 | # We use git parameters and functionality only found in 1.7.8 or later |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 503 | # The kernel tools assume git >= 1.8.3.1 (verified needed > 1.7.9.5) see #6162 |
| 504 | # The git fetcher also had workarounds for git < 1.7.9.2 which we've dropped |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 505 | def check_git_version(sanity_data): |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 506 | import subprocess |
| 507 | try: |
| 508 | result = subprocess.check_output(["git", "--version"], stderr=subprocess.DEVNULL).decode('utf-8') |
| 509 | except subprocess.CalledProcessError as e: |
| 510 | return "Unable to execute git --version, exit code %d\n%s\n" % (e.returncode, e.output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 511 | version = result.split()[2] |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 512 | if bb.utils.vercmp_string_op(version, "1.8.3.1", "<"): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 513 | return "Your version of git is older than 1.8.3.1 and has bugs which will break builds. Please install a newer version of git.\n" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 514 | return None |
| 515 | |
| 516 | # Check the required perl modules which may not be installed by default |
| 517 | def check_perl_modules(sanity_data): |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 518 | import subprocess |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 519 | ret = "" |
| 520 | modules = ( "Text::ParseWords", "Thread::Queue", "Data::Dumper" ) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 521 | errresult = '' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 522 | for m in modules: |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 523 | try: |
| 524 | subprocess.check_output(["perl", "-e", "use %s" % m]) |
| 525 | except subprocess.CalledProcessError as e: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 526 | errresult += bytes.decode(e.output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 527 | ret += "%s " % m |
| 528 | if ret: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 529 | return "Required perl module(s) not found: %s\n\n%s\n" % (ret, errresult) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 530 | return None |
| 531 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 532 | def sanity_check_conffiles(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 533 | funcs = d.getVar('BBLAYERS_CONF_UPDATE_FUNCS').split() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 534 | for func in funcs: |
| 535 | conffile, current_version, required_version, func = func.split(":") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 536 | if check_conf_exists(conffile, d) and d.getVar(current_version) is not None and \ |
| 537 | d.getVar(current_version) != d.getVar(required_version): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 538 | try: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 539 | bb.build.exec_func(func, d) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 540 | except NotImplementedError as e: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 541 | bb.fatal(str(e)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 542 | d.setVar("BB_INVALIDCONF", True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 543 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 544 | def drop_v14_cross_builds(d): |
| 545 | import glob |
| 546 | indexes = glob.glob(d.expand("${SSTATE_MANIFESTS}/index-${BUILD_ARCH}_*")) |
| 547 | for i in indexes: |
| 548 | with open(i, "r") as f: |
| 549 | lines = f.readlines() |
| 550 | for l in reversed(lines): |
| 551 | try: |
| 552 | (stamp, manifest, workdir) = l.split() |
| 553 | except ValueError: |
| 554 | bb.fatal("Invalid line '%s' in sstate manifest '%s'" % (l, i)) |
| 555 | for m in glob.glob(manifest + ".*"): |
| 556 | if m.endswith(".postrm"): |
| 557 | continue |
| 558 | sstate_clean_manifest(m, d) |
| 559 | bb.utils.remove(stamp + "*") |
| 560 | bb.utils.remove(workdir, recurse = True) |
| 561 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 562 | def sanity_handle_abichanges(status, d): |
| 563 | # |
| 564 | # Check the 'ABI' of TMPDIR |
| 565 | # |
| 566 | import subprocess |
| 567 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 568 | current_abi = d.getVar('OELAYOUT_ABI') |
| 569 | abifile = d.getVar('SANITY_ABIFILE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 570 | if os.path.exists(abifile): |
| 571 | with open(abifile, "r") as f: |
| 572 | abi = f.read().strip() |
| 573 | if not abi.isdigit(): |
| 574 | with open(abifile, "w") as f: |
| 575 | f.write(current_abi) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 576 | elif int(abi) <= 11 and current_abi == "12": |
| 577 | status.addresult("The layout of TMPDIR changed for Recipe Specific Sysroots.\nConversion doesn't make sense and this change will rebuild everything so please delete TMPDIR (%s).\n" % d.getVar("TMPDIR")) |
Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 578 | elif int(abi) <= 13 and current_abi == "14": |
| 579 | status.addresult("TMPDIR changed to include path filtering from the pseudo database.\nIt is recommended to use a clean TMPDIR with the new pseudo path filtering so TMPDIR (%s) would need to be removed to continue.\n" % d.getVar("TMPDIR")) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 580 | elif int(abi) == 14 and current_abi == "15": |
| 581 | drop_v14_cross_builds(d) |
| 582 | with open(abifile, "w") as f: |
| 583 | f.write(current_abi) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 584 | elif (abi != current_abi): |
| 585 | # Code to convert from one ABI to another could go here if possible. |
| 586 | status.addresult("Error, TMPDIR has changed its layout version number (%s to %s) and you need to either rebuild, revert or adjust it at your own risk.\n" % (abi, current_abi)) |
| 587 | else: |
| 588 | with open(abifile, "w") as f: |
| 589 | f.write(current_abi) |
| 590 | |
| 591 | def check_sanity_sstate_dir_change(sstate_dir, data): |
| 592 | # Sanity checks to be done when the value of SSTATE_DIR changes |
| 593 | |
| 594 | # Check that SSTATE_DIR isn't on a filesystem with limited filename length (eg. eCryptFS) |
| 595 | testmsg = "" |
| 596 | if sstate_dir != "": |
| 597 | testmsg = check_create_long_filename(sstate_dir, "SSTATE_DIR") |
| 598 | # If we don't have permissions to SSTATE_DIR, suggest the user set it as an SSTATE_MIRRORS |
| 599 | try: |
| 600 | err = testmsg.split(': ')[1].strip() |
| 601 | if err == "Permission denied.": |
| 602 | testmsg = testmsg + "You could try using %s in SSTATE_MIRRORS rather than as an SSTATE_CACHE.\n" % (sstate_dir) |
| 603 | except IndexError: |
| 604 | pass |
| 605 | return testmsg |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 606 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 607 | def check_sanity_version_change(status, d): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 608 | # Sanity checks to be done when SANITY_VERSION or NATIVELSBSTRING changes |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 609 | # In other words, these tests run once in a given build directory and then |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 610 | # never again until the sanity version or host distrubution id/version changes. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 611 | |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 612 | # Check the python install is complete. Examples that are often removed in |
| 613 | # minimal installations: glib-2.0-natives requries # xml.parsers.expat and icu |
| 614 | # requires distutils.sysconfig. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 615 | try: |
| 616 | import xml.parsers.expat |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 617 | import distutils.sysconfig |
| 618 | except ImportError as e: |
| 619 | status.addresult('Your Python 3 is not a full install. Please install the module %s (see the Getting Started guide for further information).\n' % e.name) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 620 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 621 | status.addresult(check_gcc_version(d)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 622 | status.addresult(check_make_version(d)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 623 | status.addresult(check_patch_version(d)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 624 | status.addresult(check_tar_version(d)) |
| 625 | status.addresult(check_git_version(d)) |
| 626 | status.addresult(check_perl_modules(d)) |
Brad Bishop | e2d5b61 | 2018-11-23 10:55:50 +1300 | [diff] [blame] | 627 | status.addresult(check_wsl(d)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 628 | |
| 629 | missing = "" |
| 630 | |
| 631 | if not check_app_exists("${MAKE}", d): |
| 632 | missing = missing + "GNU make," |
| 633 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 634 | if not check_app_exists('${BUILD_CC}', d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 635 | missing = missing + "C Compiler (%s)," % d.getVar("BUILD_CC") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 636 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 637 | if not check_app_exists('${BUILD_CXX}', d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 638 | missing = missing + "C++ Compiler (%s)," % d.getVar("BUILD_CXX") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 639 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 640 | required_utilities = d.getVar('SANITY_REQUIRED_UTILITIES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 641 | |
| 642 | for util in required_utilities.split(): |
| 643 | if not check_app_exists(util, d): |
| 644 | missing = missing + "%s," % util |
| 645 | |
| 646 | if missing: |
| 647 | missing = missing.rstrip(',') |
| 648 | status.addresult("Please install the following missing utilities: %s\n" % missing) |
| 649 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 650 | assume_provided = d.getVar('ASSUME_PROVIDED').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 651 | # Check user doesn't have ASSUME_PROVIDED = instead of += in local.conf |
| 652 | if "diffstat-native" not in assume_provided: |
| 653 | status.addresult('Please use ASSUME_PROVIDED +=, not ASSUME_PROVIDED = in your local.conf\n') |
| 654 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 655 | # Check that TMPDIR isn't on a filesystem with limited filename length (eg. eCryptFS) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 656 | import stat |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 657 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 658 | status.addresult(check_create_long_filename(tmpdir, "TMPDIR")) |
| 659 | tmpdirmode = os.stat(tmpdir).st_mode |
| 660 | if (tmpdirmode & stat.S_ISGID): |
| 661 | status.addresult("TMPDIR is setgid, please don't build in a setgid directory") |
| 662 | if (tmpdirmode & stat.S_ISUID): |
| 663 | status.addresult("TMPDIR is setuid, please don't build in a setuid directory") |
| 664 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 665 | # Check that a user isn't building in a path in PSEUDO_IGNORE_PATHS |
| 666 | pseudoignorepaths = d.getVar('PSEUDO_IGNORE_PATHS', expand=True).split(",") |
| 667 | workdir = d.getVar('WORKDIR', expand=True) |
| 668 | for i in pseudoignorepaths: |
| 669 | if i and workdir.startswith(i): |
| 670 | status.addresult("You are building in a path included in PSEUDO_IGNORE_PATHS " + str(i) + " please locate the build outside this path.\n") |
| 671 | |
| 672 | # Check if PSEUDO_IGNORE_PATHS and and paths under pseudo control overlap |
| 673 | pseudoignorepaths = d.getVar('PSEUDO_IGNORE_PATHS', expand=True).split(",") |
| 674 | pseudo_control_dir = "${D},${PKGD},${PKGDEST},${IMAGEROOTFS},${SDK_OUTPUT}" |
| 675 | pseudocontroldir = d.expand(pseudo_control_dir).split(",") |
| 676 | for i in pseudoignorepaths: |
| 677 | for j in pseudocontroldir: |
| 678 | if i and j: |
| 679 | if j.startswith(i): |
| 680 | status.addresult("A path included in PSEUDO_IGNORE_PATHS " + str(i) + " and the path " + str(j) + " overlap and this will break pseudo permission and ownership tracking. Please set the path " + str(j) + " to a different directory which does not overlap with pseudo controlled directories. \n") |
| 681 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 682 | # Some third-party software apparently relies on chmod etc. being suid root (!!) |
| 683 | import stat |
| 684 | suid_check_bins = "chown chmod mknod".split() |
| 685 | for bin_cmd in suid_check_bins: |
| 686 | bin_path = bb.utils.which(os.environ["PATH"], bin_cmd) |
| 687 | if bin_path: |
| 688 | bin_stat = os.stat(bin_path) |
| 689 | if bin_stat.st_uid == 0 and bin_stat.st_mode & stat.S_ISUID: |
| 690 | status.addresult('%s has the setuid bit set. This interferes with pseudo and may cause other issues that break the build process.\n' % bin_path) |
| 691 | |
| 692 | # Check that we can fetch from various network transports |
| 693 | netcheck = check_connectivity(d) |
| 694 | status.addresult(netcheck) |
| 695 | if netcheck: |
| 696 | status.network_error = True |
| 697 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 698 | nolibs = d.getVar('NO32LIBS') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 699 | if not nolibs: |
| 700 | lib32path = '/lib' |
| 701 | if os.path.exists('/lib64') and ( os.path.islink('/lib64') or os.path.islink('/lib') ): |
| 702 | lib32path = '/lib32' |
| 703 | |
| 704 | if os.path.exists('%s/libc.so.6' % lib32path) and not os.path.exists('/usr/include/gnu/stubs-32.h'): |
| 705 | status.addresult("You have a 32-bit libc, but no 32-bit headers. You must install the 32-bit libc headers.\n") |
| 706 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 707 | bbpaths = d.getVar('BBPATH').split(":") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 708 | if ("." in bbpaths or "./" in bbpaths or "" in bbpaths): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 709 | status.addresult("BBPATH references the current directory, either through " \ |
| 710 | "an empty entry, a './' or a '.'.\n\t This is unsafe and means your "\ |
| 711 | "layer configuration is adding empty elements to BBPATH.\n\t "\ |
| 712 | "Please check your layer.conf files and other BBPATH " \ |
| 713 | "settings to remove the current working directory " \ |
| 714 | "references.\n" \ |
| 715 | "Parsed BBPATH is" + str(bbpaths)); |
| 716 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 717 | oes_bb_conf = d.getVar( 'OES_BITBAKE_CONF') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 718 | if not oes_bb_conf: |
| 719 | status.addresult('You are not using the OpenEmbedded version of conf/bitbake.conf. This means your environment is misconfigured, in particular check BBPATH.\n') |
| 720 | |
| 721 | # The length of TMPDIR can't be longer than 410 |
| 722 | status.addresult(check_path_length(tmpdir, "TMPDIR", 410)) |
| 723 | |
| 724 | # Check that TMPDIR isn't located on nfs |
| 725 | status.addresult(check_not_nfs(tmpdir, "TMPDIR")) |
| 726 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 727 | # Check for case-insensitive file systems (such as Linux in Docker on |
| 728 | # macOS with default HFS+ file system) |
| 729 | status.addresult(check_case_sensitive(tmpdir, "TMPDIR")) |
| 730 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 731 | def sanity_check_locale(d): |
| 732 | """ |
| 733 | Currently bitbake switches locale to en_US.UTF-8 so check that this locale actually exists. |
| 734 | """ |
| 735 | import locale |
| 736 | try: |
| 737 | locale.setlocale(locale.LC_ALL, "en_US.UTF-8") |
| 738 | except locale.Error: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 739 | raise_sanity_error("Your system needs to support the en_US.UTF-8 locale.", d) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 740 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 741 | def check_sanity_everybuild(status, d): |
| 742 | import os, stat |
| 743 | # Sanity tests which test the users environment so need to run at each build (or are so cheap |
| 744 | # it makes sense to always run them. |
| 745 | |
| 746 | if 0 == os.getuid(): |
| 747 | raise_sanity_error("Do not use Bitbake as root.", d) |
| 748 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 749 | # Check the Python version, we now have a minimum of Python 3.6 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 750 | import sys |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 751 | if sys.hexversion < 0x030600F0: |
| 752 | status.addresult('The system requires at least Python 3.6 to run. Please update your Python interpreter.\n') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 753 | |
| 754 | # Check the bitbake version meets minimum requirements |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 755 | minversion = d.getVar('BB_MIN_VERSION') |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 756 | if bb.utils.vercmp_string_op(bb.__version__, minversion, "<"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 757 | status.addresult('Bitbake version %s is required and version %s was found\n' % (minversion, bb.__version__)) |
| 758 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 759 | sanity_check_locale(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 760 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 761 | paths = d.getVar('PATH').split(":") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 762 | if "." in paths or "./" in paths or "" in paths: |
| 763 | status.addresult("PATH contains '.', './' or '' (empty element), which will break the build, please remove this.\nParsed PATH is " + str(paths) + "\n") |
| 764 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 765 | #Check if bitbake is present in PATH environment variable |
| 766 | bb_check = bb.utils.which(d.getVar('PATH'), 'bitbake') |
| 767 | if not bb_check: |
| 768 | bb.warn("bitbake binary is not found in PATH, did you source the script?") |
| 769 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 770 | # Check whether 'inherit' directive is found (used for a class to inherit) |
| 771 | # in conf file it's supposed to be uppercase INHERIT |
| 772 | inherit = d.getVar('inherit') |
| 773 | if inherit: |
| 774 | status.addresult("Please don't use inherit directive in your local.conf. The directive is supposed to be used in classes and recipes only to inherit of bbclasses. Here INHERIT should be used.\n") |
| 775 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 776 | # Check that the DISTRO is valid, if set |
| 777 | # need to take into account DISTRO renaming DISTRO |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 778 | distro = d.getVar('DISTRO') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 779 | if distro and distro != "nodistro": |
| 780 | if not ( check_conf_exists("conf/distro/${DISTRO}.conf", d) or check_conf_exists("conf/distro/include/${DISTRO}.inc", d) ): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 781 | status.addresult("DISTRO '%s' not found. Please set a valid DISTRO in your local.conf\n" % d.getVar("DISTRO")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 782 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 783 | # Check that these variables don't use tilde-expansion as we don't do that |
| 784 | for v in ("TMPDIR", "DL_DIR", "SSTATE_DIR"): |
| 785 | if d.getVar(v).startswith("~"): |
| 786 | status.addresult("%s uses ~ but Bitbake will not expand this, use an absolute path or variables." % v) |
| 787 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 788 | # Check that DL_DIR is set, exists and is writable. In theory, we should never even hit the check if DL_DIR isn't |
| 789 | # set, since so much relies on it being set. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 790 | dldir = d.getVar('DL_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 791 | if not dldir: |
| 792 | status.addresult("DL_DIR is not set. Your environment is misconfigured, check that DL_DIR is set, and if the directory exists, that it is writable. \n") |
| 793 | if os.path.exists(dldir) and not os.access(dldir, os.W_OK): |
| 794 | status.addresult("DL_DIR: %s exists but you do not appear to have write access to it. \n" % dldir) |
| 795 | check_symlink(dldir, d) |
| 796 | |
| 797 | # Check that the MACHINE is valid, if it is set |
| 798 | machinevalid = True |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 799 | if d.getVar('MACHINE'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 800 | if not check_conf_exists("conf/machine/${MACHINE}.conf", d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 801 | status.addresult('MACHINE=%s is invalid. Please set a valid MACHINE in your local.conf, environment or other configuration file.\n' % (d.getVar('MACHINE'))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 802 | machinevalid = False |
| 803 | else: |
| 804 | status.addresult(check_sanity_validmachine(d)) |
| 805 | else: |
| 806 | status.addresult('Please set a MACHINE in your local.conf or environment\n') |
| 807 | machinevalid = False |
| 808 | if machinevalid: |
| 809 | status.addresult(check_toolchain(d)) |
| 810 | |
| 811 | # Check that the SDKMACHINE is valid, if it is set |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 812 | if d.getVar('SDKMACHINE'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 813 | if not check_conf_exists("conf/machine-sdk/${SDKMACHINE}.conf", d): |
| 814 | status.addresult('Specified SDKMACHINE value is not valid\n') |
| 815 | elif d.getVar('SDK_ARCH', False) == "${BUILD_ARCH}": |
| 816 | status.addresult('SDKMACHINE is set, but SDK_ARCH has not been changed as a result - SDKMACHINE may have been set too late (e.g. in the distro configuration)\n') |
| 817 | |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 818 | # If SDK_VENDOR looks like "-my-sdk" then the triples are badly formed so fail early |
| 819 | sdkvendor = d.getVar("SDK_VENDOR") |
| 820 | if not (sdkvendor.startswith("-") and sdkvendor.count("-") == 1): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 821 | status.addresult("SDK_VENDOR should be of the form '-foosdk' with a single dash; found '%s'\n" % sdkvendor) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 822 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 823 | check_supported_distro(d) |
| 824 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 825 | omask = os.umask(0o022) |
| 826 | if omask & 0o755: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 827 | status.addresult("Please use a umask which allows a+rx and u+rwx\n") |
| 828 | os.umask(omask) |
| 829 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 830 | if d.getVar('TARGET_ARCH') == "arm": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 831 | # This path is no longer user-readable in modern (very recent) Linux |
| 832 | try: |
| 833 | if os.path.exists("/proc/sys/vm/mmap_min_addr"): |
| 834 | f = open("/proc/sys/vm/mmap_min_addr", "r") |
| 835 | try: |
| 836 | if (int(f.read().strip()) > 65536): |
| 837 | status.addresult("/proc/sys/vm/mmap_min_addr is not <= 65536. This will cause problems with qemu so please fix the value (as root).\n\nTo fix this in later reboots, set vm.mmap_min_addr = 65536 in /etc/sysctl.conf.\n") |
| 838 | finally: |
| 839 | f.close() |
| 840 | except: |
| 841 | pass |
| 842 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 843 | for checkdir in ['COREBASE', 'TMPDIR']: |
| 844 | val = d.getVar(checkdir) |
| 845 | if val.find('..') != -1: |
| 846 | status.addresult("Error, you have '..' in your %s directory path. Please ensure the variable contains an absolute path as this can break some recipe builds in obtuse ways." % checkdir) |
| 847 | if val.find('+') != -1: |
| 848 | status.addresult("Error, you have an invalid character (+) in your %s directory path. Please move the installation to a directory which doesn't include any + characters." % checkdir) |
| 849 | if val.find('@') != -1: |
| 850 | status.addresult("Error, you have an invalid character (@) in your %s directory path. Please move the installation to a directory which doesn't include any @ characters." % checkdir) |
| 851 | if val.find(' ') != -1: |
| 852 | status.addresult("Error, you have a space in your %s directory path. Please move the installation to a directory which doesn't include a space since autotools doesn't support this." % checkdir) |
| 853 | if val.find('%') != -1: |
| 854 | status.addresult("Error, you have an invalid character (%) in your %s directory path which causes problems with python string formatting. Please move the installation to a directory which doesn't include any % characters." % checkdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 855 | |
| 856 | # Check the format of MIRRORS, PREMIRRORS and SSTATE_MIRRORS |
| 857 | import re |
| 858 | mirror_vars = ['MIRRORS', 'PREMIRRORS', 'SSTATE_MIRRORS'] |
| 859 | protocols = ['http', 'ftp', 'file', 'https', \ |
| 860 | 'git', 'gitsm', 'hg', 'osc', 'p4', 'svn', \ |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame^] | 861 | 'bzr', 'cvs', 'npm', 'sftp', 'ssh', 's3', 'az', 'ftps'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 862 | for mirror_var in mirror_vars: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 863 | mirrors = (d.getVar(mirror_var) or '').replace('\\n', ' ').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 864 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 865 | # Split into pairs |
| 866 | if len(mirrors) % 2 != 0: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 867 | bb.warn('Invalid mirror variable value for %s: %s, should contain paired members.' % (mirror_var, str(mirrors))) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 868 | continue |
| 869 | mirrors = list(zip(*[iter(mirrors)]*2)) |
| 870 | |
| 871 | for mirror_entry in mirrors: |
| 872 | pattern, mirror = mirror_entry |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 873 | |
| 874 | decoded = bb.fetch2.decodeurl(pattern) |
| 875 | try: |
| 876 | pattern_scheme = re.compile(decoded[0]) |
| 877 | except re.error as exc: |
| 878 | bb.warn('Invalid scheme regex (%s) in %s; %s' % (pattern, mirror_var, mirror_entry)) |
| 879 | continue |
| 880 | |
| 881 | if not any(pattern_scheme.match(protocol) for protocol in protocols): |
| 882 | bb.warn('Invalid protocol (%s) in %s: %s' % (decoded[0], mirror_var, mirror_entry)) |
| 883 | continue |
| 884 | |
| 885 | if not any(mirror.startswith(protocol + '://') for protocol in protocols): |
| 886 | bb.warn('Invalid protocol in %s: %s' % (mirror_var, mirror_entry)) |
| 887 | continue |
| 888 | |
| 889 | if mirror.startswith('file://'): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 890 | import urllib |
| 891 | check_symlink(urllib.parse.urlparse(mirror).path, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 892 | # SSTATE_MIRROR ends with a /PATH string |
| 893 | if mirror.endswith('/PATH'): |
| 894 | # remove /PATH$ from SSTATE_MIRROR to get a working |
| 895 | # base directory path |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 896 | mirror_base = urllib.parse.urlparse(mirror[:-1*len('/PATH')]).path |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 897 | check_symlink(mirror_base, d) |
| 898 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 899 | # Check sstate mirrors aren't being used with a local hash server and no remote |
| 900 | hashserv = d.getVar("BB_HASHSERVE") |
| 901 | if d.getVar("SSTATE_MIRRORS") and hashserv and hashserv.startswith("unix://") and not d.getVar("BB_HASHSERVE_UPSTREAM"): |
| 902 | bb.warn("You are using a local hash equivalence server but have configured an sstate mirror. This will likely mean no sstate will match from the mirror. You may wish to disable the hash equivalence use (BB_HASHSERVE), or use a hash equivalence server alongside the sstate mirror.") |
| 903 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 904 | # Check that TMPDIR hasn't changed location since the last time we were run |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 905 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 906 | checkfile = os.path.join(tmpdir, "saved_tmpdir") |
| 907 | if os.path.exists(checkfile): |
| 908 | with open(checkfile, "r") as f: |
| 909 | saved_tmpdir = f.read().strip() |
| 910 | if (saved_tmpdir != tmpdir): |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 911 | status.addresult("Error, TMPDIR has changed location. You need to either move it back to %s or delete it and rebuild\n" % saved_tmpdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 912 | else: |
| 913 | bb.utils.mkdirhier(tmpdir) |
| 914 | # Remove setuid, setgid and sticky bits from TMPDIR |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 915 | try: |
| 916 | os.chmod(tmpdir, os.stat(tmpdir).st_mode & ~ stat.S_ISUID) |
| 917 | os.chmod(tmpdir, os.stat(tmpdir).st_mode & ~ stat.S_ISGID) |
| 918 | os.chmod(tmpdir, os.stat(tmpdir).st_mode & ~ stat.S_ISVTX) |
| 919 | except OSError as exc: |
| 920 | bb.warn("Unable to chmod TMPDIR: %s" % exc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 921 | with open(checkfile, "w") as f: |
| 922 | f.write(tmpdir) |
| 923 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 924 | # If /bin/sh is a symlink, check that it points to dash or bash |
| 925 | if os.path.islink('/bin/sh'): |
| 926 | real_sh = os.path.realpath('/bin/sh') |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 927 | # Due to update-alternatives, the shell name may take various |
| 928 | # forms, such as /bin/dash, bin/bash, /bin/bash.bash ... |
| 929 | if '/dash' not in real_sh and '/bash' not in real_sh: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 930 | status.addresult("Error, /bin/sh links to %s, must be dash or bash\n" % real_sh) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 931 | |
| 932 | def check_sanity(sanity_data): |
| 933 | class SanityStatus(object): |
| 934 | def __init__(self): |
| 935 | self.messages = "" |
| 936 | self.network_error = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 937 | |
| 938 | def addresult(self, message): |
| 939 | if message: |
| 940 | self.messages = self.messages + message |
| 941 | |
| 942 | status = SanityStatus() |
| 943 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 944 | tmpdir = sanity_data.getVar('TMPDIR') |
| 945 | sstate_dir = sanity_data.getVar('SSTATE_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 946 | |
| 947 | check_symlink(sstate_dir, sanity_data) |
| 948 | |
| 949 | # Check saved sanity info |
| 950 | last_sanity_version = 0 |
| 951 | last_tmpdir = "" |
| 952 | last_sstate_dir = "" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 953 | last_nativelsbstr = "" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 954 | sanityverfile = sanity_data.expand("${TOPDIR}/cache/sanity_info") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 955 | if os.path.exists(sanityverfile): |
| 956 | with open(sanityverfile, 'r') as f: |
| 957 | for line in f: |
| 958 | if line.startswith('SANITY_VERSION'): |
| 959 | last_sanity_version = int(line.split()[1]) |
| 960 | if line.startswith('TMPDIR'): |
| 961 | last_tmpdir = line.split()[1] |
| 962 | if line.startswith('SSTATE_DIR'): |
| 963 | last_sstate_dir = line.split()[1] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 964 | if line.startswith('NATIVELSBSTRING'): |
| 965 | last_nativelsbstr = line.split()[1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 966 | |
| 967 | check_sanity_everybuild(status, sanity_data) |
| 968 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 969 | sanity_version = int(sanity_data.getVar('SANITY_VERSION') or 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 970 | network_error = False |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 971 | # NATIVELSBSTRING var may have been overridden with "universal", so |
| 972 | # get actual host distribution id and version |
| 973 | nativelsbstr = lsb_distro_identifier(sanity_data) |
| 974 | if last_sanity_version < sanity_version or last_nativelsbstr != nativelsbstr: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 975 | check_sanity_version_change(status, sanity_data) |
| 976 | status.addresult(check_sanity_sstate_dir_change(sstate_dir, sanity_data)) |
| 977 | else: |
| 978 | if last_sstate_dir != sstate_dir: |
| 979 | status.addresult(check_sanity_sstate_dir_change(sstate_dir, sanity_data)) |
| 980 | |
| 981 | if os.path.exists(os.path.dirname(sanityverfile)) and not status.messages: |
| 982 | with open(sanityverfile, 'w') as f: |
| 983 | f.write("SANITY_VERSION %s\n" % sanity_version) |
| 984 | f.write("TMPDIR %s\n" % tmpdir) |
| 985 | f.write("SSTATE_DIR %s\n" % sstate_dir) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 986 | f.write("NATIVELSBSTRING %s\n" % nativelsbstr) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 987 | |
| 988 | sanity_handle_abichanges(status, sanity_data) |
| 989 | |
| 990 | if status.messages != "": |
| 991 | raise_sanity_error(sanity_data.expand(status.messages), sanity_data, status.network_error) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 992 | |
| 993 | # Create a copy of the datastore and finalise it to ensure appends and |
| 994 | # overrides are set - the datastore has yet to be finalised at ConfigParsed |
| 995 | def copy_data(e): |
| 996 | sanity_data = bb.data.createCopy(e.data) |
| 997 | sanity_data.finalize() |
| 998 | return sanity_data |
| 999 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1000 | addhandler config_reparse_eventhandler |
| 1001 | config_reparse_eventhandler[eventmask] = "bb.event.ConfigParsed" |
| 1002 | python config_reparse_eventhandler() { |
| 1003 | sanity_check_conffiles(e.data) |
| 1004 | } |
| 1005 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1006 | addhandler check_sanity_eventhandler |
| 1007 | check_sanity_eventhandler[eventmask] = "bb.event.SanityCheck bb.event.NetworkTest" |
| 1008 | python check_sanity_eventhandler() { |
| 1009 | if bb.event.getName(e) == "SanityCheck": |
| 1010 | sanity_data = copy_data(e) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1011 | check_sanity(sanity_data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1012 | if e.generateevents: |
| 1013 | sanity_data.setVar("SANITY_USE_EVENTS", "1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1014 | bb.event.fire(bb.event.SanityCheckPassed(), e.data) |
| 1015 | elif bb.event.getName(e) == "NetworkTest": |
| 1016 | sanity_data = copy_data(e) |
| 1017 | if e.generateevents: |
| 1018 | sanity_data.setVar("SANITY_USE_EVENTS", "1") |
| 1019 | bb.event.fire(bb.event.NetworkTestFailed() if check_connectivity(sanity_data) else bb.event.NetworkTestPassed(), e.data) |
| 1020 | |
| 1021 | return |
| 1022 | } |