sanity.bbclass 44 KB

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