sanity.bbclass 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. #
  2. # Sanity check the users setup for common misconfigurations
  3. #
  4. SANITY_REQUIRED_UTILITIES ?= "patch diffstat makeinfo git bzip2 tar \
  5. gzip gawk chrpath wget cpio perl file"
  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.data.update_data(localdata)
  188. bb.debug(2, "Sanity-checking tuning '%s' (%s) features:" % (tune, multilib))
  189. features = (localdata.getVar("TUNE_FEATURES_tune-%s" % tune) or "").split()
  190. if not features:
  191. return "Tuning '%s' has no defined features, and cannot be used." % tune
  192. valid_tunes = localdata.getVarFlags('TUNEVALID') or {}
  193. conflicts = localdata.getVarFlags('TUNECONFLICTS') or {}
  194. # [doc] is the documentation for the variable, not a real feature
  195. if 'doc' in valid_tunes:
  196. del valid_tunes['doc']
  197. if 'doc' in conflicts:
  198. del conflicts['doc']
  199. for feature in features:
  200. if feature in conflicts:
  201. for conflict in conflicts[feature].split():
  202. if conflict in features:
  203. tune_errors.append("Feature '%s' conflicts with '%s'." %
  204. (feature, conflict))
  205. if feature in valid_tunes:
  206. bb.debug(2, " %s: %s" % (feature, valid_tunes[feature]))
  207. else:
  208. tune_errors.append("Feature '%s' is not defined." % feature)
  209. whitelist = localdata.getVar("TUNEABI_WHITELIST")
  210. if whitelist:
  211. tuneabi = localdata.getVar("TUNEABI_tune-%s" % tune)
  212. if not tuneabi:
  213. tuneabi = tune
  214. if True not in [x in whitelist.split() for x in tuneabi.split()]:
  215. tune_errors.append("Tuning '%s' (%s) cannot be used with any supported tuning/ABI." %
  216. (tune, tuneabi))
  217. else:
  218. if not check_toolchain_tune_args(localdata, tuneabi, multilib, tune_errors):
  219. bb.debug(2, "Sanity check: Compiler args OK for %s." % tune)
  220. if tune_errors:
  221. return "Tuning '%s' has the following errors:\n" % tune + '\n'.join(tune_errors)
  222. def check_toolchain(data):
  223. tune_error_set = []
  224. deftune = data.getVar("DEFAULTTUNE")
  225. tune_errors = check_toolchain_tune(data, deftune, 'default')
  226. if tune_errors:
  227. tune_error_set.append(tune_errors)
  228. multilibs = (data.getVar("MULTILIB_VARIANTS") or "").split()
  229. global_multilibs = (data.getVar("MULTILIB_GLOBAL_VARIANTS") or "").split()
  230. if multilibs:
  231. seen_libs = []
  232. seen_tunes = []
  233. for lib in multilibs:
  234. if lib in seen_libs:
  235. tune_error_set.append("The multilib '%s' appears more than once." % lib)
  236. else:
  237. seen_libs.append(lib)
  238. if not lib in global_multilibs:
  239. tune_error_set.append("Multilib %s is not present in MULTILIB_GLOBAL_VARIANTS" % lib)
  240. tune = data.getVar("DEFAULTTUNE_virtclass-multilib-%s" % lib)
  241. if tune in seen_tunes:
  242. tune_error_set.append("The tuning '%s' appears in more than one multilib." % tune)
  243. else:
  244. seen_libs.append(tune)
  245. if tune == deftune:
  246. tune_error_set.append("Multilib '%s' (%s) is also the default tuning." % (lib, deftune))
  247. else:
  248. tune_errors = check_toolchain_tune(data, tune, lib)
  249. if tune_errors:
  250. tune_error_set.append(tune_errors)
  251. if tune_error_set:
  252. return "Toolchain tunings invalid:\n" + '\n'.join(tune_error_set) + "\n"
  253. return ""
  254. def check_conf_exists(fn, data):
  255. bbpath = []
  256. fn = data.expand(fn)
  257. vbbpath = data.getVar("BBPATH", False)
  258. if vbbpath:
  259. bbpath += vbbpath.split(":")
  260. for p in bbpath:
  261. currname = os.path.join(data.expand(p), fn)
  262. if os.access(currname, os.R_OK):
  263. return True
  264. return False
  265. def check_create_long_filename(filepath, pathname):
  266. import string, random
  267. testfile = os.path.join(filepath, ''.join(random.choice(string.ascii_letters) for x in range(200)))
  268. try:
  269. if not os.path.exists(filepath):
  270. bb.utils.mkdirhier(filepath)
  271. f = open(testfile, "w")
  272. f.close()
  273. os.remove(testfile)
  274. except IOError as e:
  275. import errno
  276. err, strerror = e.args
  277. if err == errno.ENAMETOOLONG:
  278. 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
  279. else:
  280. return "Failed to create a file in %s: %s.\n" % (pathname, strerror)
  281. except OSError as e:
  282. errno, strerror = e.args
  283. return "Failed to create %s directory in which to run long name sanity check: %s.\n" % (pathname, strerror)
  284. return ""
  285. def check_path_length(filepath, pathname, limit):
  286. if len(filepath) > limit:
  287. return "The length of %s is longer than %s, this would cause unexpected errors, please use a shorter path.\n" % (pathname, limit)
  288. return ""
  289. def get_filesystem_id(path):
  290. status, result = oe.utils.getstatusoutput("stat -f -c '%s' %s" % ("%t", path))
  291. if status == 0:
  292. return result
  293. else:
  294. bb.warn("Can't get the filesystem id of: %s" % path)
  295. return None
  296. # Check that the path isn't located on nfs.
  297. def check_not_nfs(path, name):
  298. # The nfs' filesystem id is 6969
  299. if get_filesystem_id(path) == "6969":
  300. return "The %s: %s can't be located on nfs.\n" % (name, path)
  301. return ""
  302. # Check that path isn't a broken symlink
  303. def check_symlink(lnk, data):
  304. if os.path.islink(lnk) and not os.path.exists(lnk):
  305. raise_sanity_error("%s is a broken symlink." % lnk, data)
  306. def check_connectivity(d):
  307. # URI's to check can be set in the CONNECTIVITY_CHECK_URIS variable
  308. # using the same syntax as for SRC_URI. If the variable is not set
  309. # the check is skipped
  310. test_uris = (d.getVar('CONNECTIVITY_CHECK_URIS') or "").split()
  311. retval = ""
  312. bbn = d.getVar('BB_NO_NETWORK')
  313. if bbn not in (None, '0', '1'):
  314. return 'BB_NO_NETWORK should be "0" or "1", but it is "%s"' % bbn
  315. # Only check connectivity if network enabled and the
  316. # CONNECTIVITY_CHECK_URIS are set
  317. network_enabled = not (bbn == '1')
  318. check_enabled = len(test_uris)
  319. if check_enabled and network_enabled:
  320. # Take a copy of the data store and unset MIRRORS and PREMIRRORS
  321. data = bb.data.createCopy(d)
  322. data.delVar('PREMIRRORS')
  323. data.delVar('MIRRORS')
  324. try:
  325. fetcher = bb.fetch2.Fetch(test_uris, data)
  326. fetcher.checkstatus()
  327. except Exception as err:
  328. # Allow the message to be configured so that users can be
  329. # pointed to a support mechanism.
  330. msg = data.getVar('CONNECTIVITY_CHECK_MSG') or ""
  331. if len(msg) == 0:
  332. msg = "%s.\n" % err
  333. msg += " Please ensure your host's network is configured correctly,\n"
  334. msg += " or set BB_NO_NETWORK = \"1\" to disable network access if\n"
  335. msg += " all required sources are on local disk.\n"
  336. retval = msg
  337. return retval
  338. def check_supported_distro(sanity_data):
  339. from fnmatch import fnmatch
  340. tested_distros = sanity_data.getVar('SANITY_TESTED_DISTROS')
  341. if not tested_distros:
  342. return
  343. try:
  344. distro = oe.lsb.distro_identifier()
  345. except Exception:
  346. distro = None
  347. if not distro:
  348. bb.warn('Host distribution could not be determined; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.')
  349. for supported in [x.strip() for x in tested_distros.split('\\n')]:
  350. if fnmatch(distro, supported):
  351. return
  352. 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)
  353. # Checks we should only make if MACHINE is set correctly
  354. def check_sanity_validmachine(sanity_data):
  355. messages = ""
  356. # Check TUNE_ARCH is set
  357. if sanity_data.getVar('TUNE_ARCH') == 'INVALID':
  358. messages = messages + 'TUNE_ARCH is unset. Please ensure your MACHINE configuration includes a valid tune configuration file which will set this correctly.\n'
  359. # Check TARGET_OS is set
  360. if sanity_data.getVar('TARGET_OS') == 'INVALID':
  361. messages = messages + 'Please set TARGET_OS directly, or choose a MACHINE or DISTRO that does so.\n'
  362. # Check that we don't have duplicate entries in PACKAGE_ARCHS & that TUNE_PKGARCH is in PACKAGE_ARCHS
  363. pkgarchs = sanity_data.getVar('PACKAGE_ARCHS')
  364. tunepkg = sanity_data.getVar('TUNE_PKGARCH')
  365. defaulttune = sanity_data.getVar('DEFAULTTUNE')
  366. tunefound = False
  367. seen = {}
  368. dups = []
  369. for pa in pkgarchs.split():
  370. if seen.get(pa, 0) == 1:
  371. dups.append(pa)
  372. else:
  373. seen[pa] = 1
  374. if pa == tunepkg:
  375. tunefound = True
  376. if len(dups):
  377. messages = messages + "Error, the PACKAGE_ARCHS variable contains duplicates. The following archs are listed more than once: %s" % " ".join(dups)
  378. if tunefound == False:
  379. messages = messages + "Error, the PACKAGE_ARCHS variable (%s) for DEFAULTTUNE (%s) does not contain TUNE_PKGARCH (%s)." % (pkgarchs, defaulttune, tunepkg)
  380. return messages
  381. # Checks if necessary to add option march to host gcc
  382. def check_gcc_march(sanity_data):
  383. result = True
  384. message = ""
  385. # Check if -march not in BUILD_CFLAGS
  386. if sanity_data.getVar("BUILD_CFLAGS").find("-march") < 0:
  387. result = False
  388. # Construct a test file
  389. f = open("gcc_test.c", "w")
  390. f.write("int main (){ volatile int atomic = 2; __sync_bool_compare_and_swap (&atomic, 2, 3); return 0; }\n")
  391. f.close()
  392. # Check if GCC could work without march
  393. if not result:
  394. status,res = oe.utils.getstatusoutput(sanity_data.expand("${BUILD_CC} gcc_test.c -o gcc_test"))
  395. if status == 0:
  396. result = True;
  397. if not result:
  398. status,res = oe.utils.getstatusoutput(sanity_data.expand("${BUILD_CC} -march=native gcc_test.c -o gcc_test"))
  399. if status == 0:
  400. message = "BUILD_CFLAGS_append = \" -march=native\""
  401. result = True;
  402. if not result:
  403. build_arch = sanity_data.getVar('BUILD_ARCH')
  404. status,res = oe.utils.getstatusoutput(sanity_data.expand("${BUILD_CC} -march=%s gcc_test.c -o gcc_test" % build_arch))
  405. if status == 0:
  406. message = "BUILD_CFLAGS_append = \" -march=%s\"" % build_arch
  407. result = True;
  408. os.remove("gcc_test.c")
  409. if os.path.exists("gcc_test"):
  410. os.remove("gcc_test")
  411. return (result, message)
  412. # Unpatched versions of make 3.82 are known to be broken. See GNU Savannah Bug 30612.
  413. # Use a modified reproducer from http://savannah.gnu.org/bugs/?30612 to validate.
  414. def check_make_version(sanity_data):
  415. from distutils.version import LooseVersion
  416. status, result = oe.utils.getstatusoutput("make --version")
  417. if status != 0:
  418. return "Unable to execute make --version, exit code %s\n" % status
  419. version = result.split()[2]
  420. if LooseVersion(version) == LooseVersion("3.82"):
  421. # Construct a test file
  422. f = open("makefile_test", "w")
  423. 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")
  424. f.write("\n")
  425. f.write("makefile_test_a.c:\n")
  426. f.write(" touch $@\n")
  427. f.write("\n")
  428. f.write("makefile_test_b.c:\n")
  429. f.write(" touch $@\n")
  430. f.close()
  431. # Check if make 3.82 has been patched
  432. status,result = oe.utils.getstatusoutput("make -f makefile_test")
  433. os.remove("makefile_test")
  434. if os.path.exists("makefile_test_a.c"):
  435. os.remove("makefile_test_a.c")
  436. if os.path.exists("makefile_test_b.c"):
  437. os.remove("makefile_test_b.c")
  438. if os.path.exists("makefile_test.a"):
  439. os.remove("makefile_test.a")
  440. if status != 0:
  441. return "Your version of make 3.82 is broken. Please revert to 3.81 or install a patched version.\n"
  442. return None
  443. # Tar version 1.24 and onwards handle overwriting symlinks correctly
  444. # but earlier versions do not; this needs to work properly for sstate
  445. def check_tar_version(sanity_data):
  446. from distutils.version import LooseVersion
  447. status, result = oe.utils.getstatusoutput("tar --version")
  448. if status != 0:
  449. return "Unable to execute tar --version, exit code %s\n" % status
  450. version = result.split()[3]
  451. if LooseVersion(version) < LooseVersion("1.24"):
  452. return "Your version of tar is older than 1.24 and has bugs which will break builds. Please install a newer version of tar.\n"
  453. return None
  454. # We use git parameters and functionality only found in 1.7.8 or later
  455. # The kernel tools assume git >= 1.8.3.1 (verified needed > 1.7.9.5) see #6162
  456. # The git fetcher also had workarounds for git < 1.7.9.2 which we've dropped
  457. def check_git_version(sanity_data):
  458. from distutils.version import LooseVersion
  459. status, result = oe.utils.getstatusoutput("git --version 2> /dev/null")
  460. if status != 0:
  461. return "Unable to execute git --version, exit code %s\n" % status
  462. version = result.split()[2]
  463. if LooseVersion(version) < LooseVersion("1.8.3.1"):
  464. 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"
  465. return None
  466. # Check the required perl modules which may not be installed by default
  467. def check_perl_modules(sanity_data):
  468. ret = ""
  469. modules = ( "Text::ParseWords", "Thread::Queue", "Data::Dumper" )
  470. errresult = ''
  471. for m in modules:
  472. status, result = oe.utils.getstatusoutput("perl -e 'use %s'" % m)
  473. if status != 0:
  474. errresult += result
  475. ret += "%s " % m
  476. if ret:
  477. return "Required perl module(s) not found: %s\n\n%s\n" % (ret, errresult)
  478. return None
  479. def sanity_check_conffiles(d):
  480. funcs = d.getVar('BBLAYERS_CONF_UPDATE_FUNCS').split()
  481. for func in funcs:
  482. conffile, current_version, required_version, func = func.split(":")
  483. if check_conf_exists(conffile, d) and d.getVar(current_version) is not None and \
  484. d.getVar(current_version) != d.getVar(required_version):
  485. try:
  486. bb.build.exec_func(func, d, pythonexception=True)
  487. except NotImplementedError as e:
  488. bb.fatal(str(e))
  489. d.setVar("BB_INVALIDCONF", True)
  490. def sanity_handle_abichanges(status, d):
  491. #
  492. # Check the 'ABI' of TMPDIR
  493. #
  494. import subprocess
  495. current_abi = d.getVar('OELAYOUT_ABI')
  496. abifile = d.getVar('SANITY_ABIFILE')
  497. if os.path.exists(abifile):
  498. with open(abifile, "r") as f:
  499. abi = f.read().strip()
  500. if not abi.isdigit():
  501. with open(abifile, "w") as f:
  502. f.write(current_abi)
  503. elif abi == "2" and current_abi == "3":
  504. bb.note("Converting staging from layout version 2 to layout version 3")
  505. subprocess.call(d.expand("mv ${TMPDIR}/staging ${TMPDIR}/sysroots"), shell=True)
  506. subprocess.call(d.expand("ln -s sysroots ${TMPDIR}/staging"), shell=True)
  507. subprocess.call(d.expand("cd ${TMPDIR}/stamps; for i in */*do_populate_staging; do new=`echo $i | sed -e 's/do_populate_staging/do_populate_sysroot/'`; mv $i $new; done"), shell=True)
  508. with open(abifile, "w") as f:
  509. f.write(current_abi)
  510. elif abi == "3" and current_abi == "4":
  511. bb.note("Converting staging layout from version 3 to layout version 4")
  512. if os.path.exists(d.expand("${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}")):
  513. subprocess.call(d.expand("mv ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS} ${STAGING_BINDIR_CROSS}"), shell=True)
  514. subprocess.call(d.expand("ln -s ${STAGING_BINDIR_CROSS} ${STAGING_DIR_NATIVE}${bindir_native}/${MULTIMACH_HOST_SYS}"), shell=True)
  515. with open(abifile, "w") as f:
  516. f.write(current_abi)
  517. elif abi == "4":
  518. status.addresult("Staging layout has changed. The cross directory has been deprecated and cross packages are now built under the native sysroot.\nThis requires a rebuild.\n")
  519. elif abi == "5" and current_abi == "6":
  520. bb.note("Converting staging layout from version 5 to layout version 6")
  521. subprocess.call(d.expand("mv ${TMPDIR}/pstagelogs ${SSTATE_MANIFESTS}"), shell=True)
  522. with open(abifile, "w") as f:
  523. f.write(current_abi)
  524. elif abi == "7" and current_abi == "8":
  525. status.addresult("Your configuration is using stamp files including the sstate hash but your build directory was built with stamp files that do not include this.\nTo continue, either rebuild or switch back to the OEBasic signature handler with BB_SIGNATURE_HANDLER = 'OEBasic'.\n")
  526. elif (abi != current_abi and current_abi == "9"):
  527. status.addresult("The layout of the TMPDIR STAMPS directory has changed. Please clean out TMPDIR and rebuild (sstate will be still be valid and reused)\n")
  528. elif (abi != current_abi and current_abi == "10" and (abi == "8" or abi == "9")):
  529. bb.note("Converting staging layout from version 8/9 to layout version 10")
  530. cmd = d.expand("grep -r -l sysroot-providers/virtual_kernel ${SSTATE_MANIFESTS}")
  531. ret, result = oe.utils.getstatusoutput(cmd)
  532. result = result.split()
  533. for f in result:
  534. bb.note("Uninstalling manifest file %s" % f)
  535. sstate_clean_manifest(f, d)
  536. with open(abifile, "w") as f:
  537. f.write(current_abi)
  538. elif abi == "10" and current_abi == "11":
  539. bb.note("Converting staging layout from version 10 to layout version 11")
  540. # Files in xf86-video-modesetting moved to xserver-xorg and bitbake can't currently handle that:
  541. subprocess.call(d.expand("rm ${TMPDIR}/sysroots/*/usr/lib/xorg/modules/drivers/modesetting_drv.so ${TMPDIR}/sysroots/*/pkgdata/runtime/xf86-video-modesetting* ${TMPDIR}/sysroots/*/pkgdata/runtime-reverse/xf86-video-modesetting* ${TMPDIR}/sysroots/*/pkgdata/shlibs2/xf86-video-modesetting*"), shell=True)
  542. with open(abifile, "w") as f:
  543. f.write(current_abi)
  544. elif abi == "11" and current_abi == "12":
  545. status.addresult("The layout of TMPDIR changed for Recipe Specific Sysroots.\nConversion doesn't make sense and this change will rebuild everything so please start with a clean TMPDIR.\n")
  546. elif (abi != current_abi):
  547. # Code to convert from one ABI to another could go here if possible.
  548. 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))
  549. else:
  550. with open(abifile, "w") as f:
  551. f.write(current_abi)
  552. def check_sanity_sstate_dir_change(sstate_dir, data):
  553. # Sanity checks to be done when the value of SSTATE_DIR changes
  554. # Check that SSTATE_DIR isn't on a filesystem with limited filename length (eg. eCryptFS)
  555. testmsg = ""
  556. if sstate_dir != "":
  557. testmsg = check_create_long_filename(sstate_dir, "SSTATE_DIR")
  558. # If we don't have permissions to SSTATE_DIR, suggest the user set it as an SSTATE_MIRRORS
  559. try:
  560. err = testmsg.split(': ')[1].strip()
  561. if err == "Permission denied.":
  562. testmsg = testmsg + "You could try using %s in SSTATE_MIRRORS rather than as an SSTATE_CACHE.\n" % (sstate_dir)
  563. except IndexError:
  564. pass
  565. return testmsg
  566. def check_sanity_version_change(status, d):
  567. # Sanity checks to be done when SANITY_VERSION or NATIVELSBSTRING changes
  568. # In other words, these tests run once in a given build directory and then
  569. # never again until the sanity version or host distrubution id/version changes.
  570. # Check the python install is complete. glib-2.0-natives requries
  571. # xml.parsers.expat
  572. try:
  573. import xml.parsers.expat
  574. except ImportError:
  575. status.addresult('Your python is not a full install. Please install the module xml.parsers.expat (python-xml on openSUSE and SUSE Linux).\n')
  576. import stat
  577. status.addresult(check_make_version(d))
  578. status.addresult(check_tar_version(d))
  579. status.addresult(check_git_version(d))
  580. status.addresult(check_perl_modules(d))
  581. missing = ""
  582. if not check_app_exists("${MAKE}", d):
  583. missing = missing + "GNU make,"
  584. if not check_app_exists('${BUILD_CC}', d):
  585. missing = missing + "C Compiler (%s)," % d.getVar("BUILD_CC")
  586. if not check_app_exists('${BUILD_CXX}', d):
  587. missing = missing + "C++ Compiler (%s)," % d.getVar("BUILD_CXX")
  588. required_utilities = d.getVar('SANITY_REQUIRED_UTILITIES')
  589. for util in required_utilities.split():
  590. if not check_app_exists(util, d):
  591. missing = missing + "%s," % util
  592. if missing:
  593. missing = missing.rstrip(',')
  594. status.addresult("Please install the following missing utilities: %s\n" % missing)
  595. assume_provided = d.getVar('ASSUME_PROVIDED').split()
  596. # Check user doesn't have ASSUME_PROVIDED = instead of += in local.conf
  597. if "diffstat-native" not in assume_provided:
  598. status.addresult('Please use ASSUME_PROVIDED +=, not ASSUME_PROVIDED = in your local.conf\n')
  599. if "qemu-native" in assume_provided:
  600. if not check_app_exists("qemu-arm", d):
  601. status.addresult("qemu-native was in ASSUME_PROVIDED but the QEMU binaries (qemu-arm) can't be found in PATH")
  602. if "libsdl-native" in assume_provided:
  603. if not check_app_exists("sdl-config", d):
  604. status.addresult("libsdl-native is set to be ASSUME_PROVIDED but sdl-config can't be found in PATH. Please either install it, or configure qemu not to require sdl.")
  605. (result, message) = check_gcc_march(d)
  606. if result and message:
  607. status.addresult("Your gcc version is older than 4.5, please add the following param to local.conf\n \
  608. %s\n" % message)
  609. if not result:
  610. status.addresult("Your gcc version is older than 4.5 or is not working properly. Please verify you can build")
  611. status.addresult(" and link something that uses atomic operations, such as: \n")
  612. status.addresult(" __sync_bool_compare_and_swap (&atomic, 2, 3);\n")
  613. # Check that TMPDIR isn't on a filesystem with limited filename length (eg. eCryptFS)
  614. tmpdir = d.getVar('TMPDIR')
  615. status.addresult(check_create_long_filename(tmpdir, "TMPDIR"))
  616. tmpdirmode = os.stat(tmpdir).st_mode
  617. if (tmpdirmode & stat.S_ISGID):
  618. status.addresult("TMPDIR is setgid, please don't build in a setgid directory")
  619. if (tmpdirmode & stat.S_ISUID):
  620. status.addresult("TMPDIR is setuid, please don't build in a setuid directory")
  621. # Some third-party software apparently relies on chmod etc. being suid root (!!)
  622. import stat
  623. suid_check_bins = "chown chmod mknod".split()
  624. for bin_cmd in suid_check_bins:
  625. bin_path = bb.utils.which(os.environ["PATH"], bin_cmd)
  626. if bin_path:
  627. bin_stat = os.stat(bin_path)
  628. if bin_stat.st_uid == 0 and bin_stat.st_mode & stat.S_ISUID:
  629. 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)
  630. # Check that we can fetch from various network transports
  631. netcheck = check_connectivity(d)
  632. status.addresult(netcheck)
  633. if netcheck:
  634. status.network_error = True
  635. nolibs = d.getVar('NO32LIBS')
  636. if not nolibs:
  637. lib32path = '/lib'
  638. if os.path.exists('/lib64') and ( os.path.islink('/lib64') or os.path.islink('/lib') ):
  639. lib32path = '/lib32'
  640. if os.path.exists('%s/libc.so.6' % lib32path) and not os.path.exists('/usr/include/gnu/stubs-32.h'):
  641. status.addresult("You have a 32-bit libc, but no 32-bit headers. You must install the 32-bit libc headers.\n")
  642. bbpaths = d.getVar('BBPATH').split(":")
  643. if ("." in bbpaths or "./" in bbpaths or "" in bbpaths):
  644. status.addresult("BBPATH references the current directory, either through " \
  645. "an empty entry, a './' or a '.'.\n\t This is unsafe and means your "\
  646. "layer configuration is adding empty elements to BBPATH.\n\t "\
  647. "Please check your layer.conf files and other BBPATH " \
  648. "settings to remove the current working directory " \
  649. "references.\n" \
  650. "Parsed BBPATH is" + str(bbpaths));
  651. oes_bb_conf = d.getVar( 'OES_BITBAKE_CONF')
  652. if not oes_bb_conf:
  653. status.addresult('You are not using the OpenEmbedded version of conf/bitbake.conf. This means your environment is misconfigured, in particular check BBPATH.\n')
  654. # The length of TMPDIR can't be longer than 410
  655. status.addresult(check_path_length(tmpdir, "TMPDIR", 410))
  656. # Check that TMPDIR isn't located on nfs
  657. status.addresult(check_not_nfs(tmpdir, "TMPDIR"))
  658. def sanity_check_locale(d):
  659. """
  660. Currently bitbake switches locale to en_US.UTF-8 so check that this locale actually exists.
  661. """
  662. import locale
  663. try:
  664. locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
  665. except locale.Error:
  666. raise_sanity_error("You system needs to support the en_US.UTF-8 locale.", d)
  667. def check_sanity_everybuild(status, d):
  668. import os, stat
  669. # Sanity tests which test the users environment so need to run at each build (or are so cheap
  670. # it makes sense to always run them.
  671. if 0 == os.getuid():
  672. raise_sanity_error("Do not use Bitbake as root.", d)
  673. # Check the Python version, we now have a minimum of Python 2.7.3
  674. import sys
  675. if sys.hexversion < 0x020703F0:
  676. status.addresult('The system requires at least Python 2.7.3 to run. Please update your Python interpreter.\n')
  677. # Check the bitbake version meets minimum requirements
  678. from distutils.version import LooseVersion
  679. minversion = d.getVar('BB_MIN_VERSION')
  680. if (LooseVersion(bb.__version__) < LooseVersion(minversion)):
  681. status.addresult('Bitbake version %s is required and version %s was found\n' % (minversion, bb.__version__))
  682. sanity_check_locale(d)
  683. paths = d.getVar('PATH').split(":")
  684. if "." in paths or "./" in paths or "" in paths:
  685. status.addresult("PATH contains '.', './' or '' (empty element), which will break the build, please remove this.\nParsed PATH is " + str(paths) + "\n")
  686. # Check that the DISTRO is valid, if set
  687. # need to take into account DISTRO renaming DISTRO
  688. distro = d.getVar('DISTRO')
  689. if distro and distro != "nodistro":
  690. if not ( check_conf_exists("conf/distro/${DISTRO}.conf", d) or check_conf_exists("conf/distro/include/${DISTRO}.inc", d) ):
  691. status.addresult("DISTRO '%s' not found. Please set a valid DISTRO in your local.conf\n" % d.getVar("DISTRO"))
  692. # Check that DL_DIR is set, exists and is writable. In theory, we should never even hit the check if DL_DIR isn't
  693. # set, since so much relies on it being set.
  694. dldir = d.getVar('DL_DIR')
  695. if not dldir:
  696. 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")
  697. if os.path.exists(dldir) and not os.access(dldir, os.W_OK):
  698. status.addresult("DL_DIR: %s exists but you do not appear to have write access to it. \n" % dldir)
  699. check_symlink(dldir, d)
  700. # Check that the MACHINE is valid, if it is set
  701. machinevalid = True
  702. if d.getVar('MACHINE'):
  703. if not check_conf_exists("conf/machine/${MACHINE}.conf", d):
  704. status.addresult('MACHINE=%s is invalid. Please set a valid MACHINE in your local.conf, environment or other configuration file.\n' % (d.getVar('MACHINE')))
  705. machinevalid = False
  706. else:
  707. status.addresult(check_sanity_validmachine(d))
  708. else:
  709. status.addresult('Please set a MACHINE in your local.conf or environment\n')
  710. machinevalid = False
  711. if machinevalid:
  712. status.addresult(check_toolchain(d))
  713. # Check that the SDKMACHINE is valid, if it is set
  714. if d.getVar('SDKMACHINE'):
  715. if not check_conf_exists("conf/machine-sdk/${SDKMACHINE}.conf", d):
  716. status.addresult('Specified SDKMACHINE value is not valid\n')
  717. elif d.getVar('SDK_ARCH', False) == "${BUILD_ARCH}":
  718. 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')
  719. check_supported_distro(d)
  720. omask = os.umask(0o022)
  721. if omask & 0o755:
  722. status.addresult("Please use a umask which allows a+rx and u+rwx\n")
  723. os.umask(omask)
  724. if d.getVar('TARGET_ARCH') == "arm":
  725. # This path is no longer user-readable in modern (very recent) Linux
  726. try:
  727. if os.path.exists("/proc/sys/vm/mmap_min_addr"):
  728. f = open("/proc/sys/vm/mmap_min_addr", "r")
  729. try:
  730. if (int(f.read().strip()) > 65536):
  731. 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")
  732. finally:
  733. f.close()
  734. except:
  735. pass
  736. oeroot = d.getVar('COREBASE')
  737. if oeroot.find('+') != -1:
  738. 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.")
  739. if oeroot.find('@') != -1:
  740. 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.")
  741. if oeroot.find(' ') != -1:
  742. 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.")
  743. # Check the format of MIRRORS, PREMIRRORS and SSTATE_MIRRORS
  744. import re
  745. mirror_vars = ['MIRRORS', 'PREMIRRORS', 'SSTATE_MIRRORS']
  746. protocols = ['http', 'ftp', 'file', 'https', \
  747. 'git', 'gitsm', 'hg', 'osc', 'p4', 'svn', \
  748. 'bzr', 'cvs', 'npm', 'sftp', 'ssh']
  749. for mirror_var in mirror_vars:
  750. mirrors = (d.getVar(mirror_var) or '').replace('\\n', '\n').split('\n')
  751. for mirror_entry in mirrors:
  752. mirror_entry = mirror_entry.strip()
  753. if not mirror_entry:
  754. # ignore blank lines
  755. continue
  756. try:
  757. pattern, mirror = mirror_entry.split()
  758. except ValueError:
  759. bb.warn('Invalid %s: %s, should be 2 members.' % (mirror_var, mirror_entry.strip()))
  760. continue
  761. decoded = bb.fetch2.decodeurl(pattern)
  762. try:
  763. pattern_scheme = re.compile(decoded[0])
  764. except re.error as exc:
  765. bb.warn('Invalid scheme regex (%s) in %s; %s' % (pattern, mirror_var, mirror_entry))
  766. continue
  767. if not any(pattern_scheme.match(protocol) for protocol in protocols):
  768. bb.warn('Invalid protocol (%s) in %s: %s' % (decoded[0], mirror_var, mirror_entry))
  769. continue
  770. if not any(mirror.startswith(protocol + '://') for protocol in protocols):
  771. bb.warn('Invalid protocol in %s: %s' % (mirror_var, mirror_entry))
  772. continue
  773. if mirror.startswith('file://'):
  774. import urllib
  775. check_symlink(urllib.parse.urlparse(mirror).path, d)
  776. # SSTATE_MIRROR ends with a /PATH string
  777. if mirror.endswith('/PATH'):
  778. # remove /PATH$ from SSTATE_MIRROR to get a working
  779. # base directory path
  780. mirror_base = urllib.parse.urlparse(mirror[:-1*len('/PATH')]).path
  781. check_symlink(mirror_base, d)
  782. # Check that TMPDIR hasn't changed location since the last time we were run
  783. tmpdir = d.getVar('TMPDIR')
  784. checkfile = os.path.join(tmpdir, "saved_tmpdir")
  785. if os.path.exists(checkfile):
  786. with open(checkfile, "r") as f:
  787. saved_tmpdir = f.read().strip()
  788. if (saved_tmpdir != tmpdir):
  789. status.addresult("Error, TMPDIR has changed location. You need to either move it back to %s or rebuild\n" % saved_tmpdir)
  790. else:
  791. bb.utils.mkdirhier(tmpdir)
  792. # Remove setuid, setgid and sticky bits from TMPDIR
  793. try:
  794. os.chmod(tmpdir, os.stat(tmpdir).st_mode & ~ stat.S_ISUID)
  795. os.chmod(tmpdir, os.stat(tmpdir).st_mode & ~ stat.S_ISGID)
  796. os.chmod(tmpdir, os.stat(tmpdir).st_mode & ~ stat.S_ISVTX)
  797. except OSError as exc:
  798. bb.warn("Unable to chmod TMPDIR: %s" % exc)
  799. with open(checkfile, "w") as f:
  800. f.write(tmpdir)
  801. # If /bin/sh is a symlink, check that it points to dash or bash
  802. if os.path.islink('/bin/sh'):
  803. real_sh = os.path.realpath('/bin/sh')
  804. if not real_sh.endswith('/dash') and not real_sh.endswith('/bash'):
  805. status.addresult("Error, /bin/sh links to %s, must be dash or bash\n" % real_sh)
  806. def check_sanity(sanity_data):
  807. class SanityStatus(object):
  808. def __init__(self):
  809. self.messages = ""
  810. self.network_error = False
  811. def addresult(self, message):
  812. if message:
  813. self.messages = self.messages + message
  814. status = SanityStatus()
  815. tmpdir = sanity_data.getVar('TMPDIR')
  816. sstate_dir = sanity_data.getVar('SSTATE_DIR')
  817. check_symlink(sstate_dir, sanity_data)
  818. # Check saved sanity info
  819. last_sanity_version = 0
  820. last_tmpdir = ""
  821. last_sstate_dir = ""
  822. last_nativelsbstr = ""
  823. sanityverfile = sanity_data.expand("${TOPDIR}/conf/sanity_info")
  824. if os.path.exists(sanityverfile):
  825. with open(sanityverfile, 'r') as f:
  826. for line in f:
  827. if line.startswith('SANITY_VERSION'):
  828. last_sanity_version = int(line.split()[1])
  829. if line.startswith('TMPDIR'):
  830. last_tmpdir = line.split()[1]
  831. if line.startswith('SSTATE_DIR'):
  832. last_sstate_dir = line.split()[1]
  833. if line.startswith('NATIVELSBSTRING'):
  834. last_nativelsbstr = line.split()[1]
  835. check_sanity_everybuild(status, sanity_data)
  836. sanity_version = int(sanity_data.getVar('SANITY_VERSION') or 1)
  837. network_error = False
  838. # NATIVELSBSTRING var may have been overridden with "universal", so
  839. # get actual host distribution id and version
  840. nativelsbstr = lsb_distro_identifier(sanity_data)
  841. if last_sanity_version < sanity_version or last_nativelsbstr != nativelsbstr:
  842. check_sanity_version_change(status, sanity_data)
  843. status.addresult(check_sanity_sstate_dir_change(sstate_dir, sanity_data))
  844. else:
  845. if last_sstate_dir != sstate_dir:
  846. status.addresult(check_sanity_sstate_dir_change(sstate_dir, sanity_data))
  847. if os.path.exists(os.path.dirname(sanityverfile)) and not status.messages:
  848. with open(sanityverfile, 'w') as f:
  849. f.write("SANITY_VERSION %s\n" % sanity_version)
  850. f.write("TMPDIR %s\n" % tmpdir)
  851. f.write("SSTATE_DIR %s\n" % sstate_dir)
  852. f.write("NATIVELSBSTRING %s\n" % nativelsbstr)
  853. sanity_handle_abichanges(status, sanity_data)
  854. if status.messages != "":
  855. raise_sanity_error(sanity_data.expand(status.messages), sanity_data, status.network_error)
  856. # Create a copy of the datastore and finalise it to ensure appends and
  857. # overrides are set - the datastore has yet to be finalised at ConfigParsed
  858. def copy_data(e):
  859. sanity_data = bb.data.createCopy(e.data)
  860. sanity_data.finalize()
  861. return sanity_data
  862. addhandler config_reparse_eventhandler
  863. config_reparse_eventhandler[eventmask] = "bb.event.ConfigParsed"
  864. python config_reparse_eventhandler() {
  865. sanity_check_conffiles(e.data)
  866. }
  867. addhandler check_sanity_eventhandler
  868. check_sanity_eventhandler[eventmask] = "bb.event.SanityCheck bb.event.NetworkTest"
  869. python check_sanity_eventhandler() {
  870. if bb.event.getName(e) == "SanityCheck":
  871. sanity_data = copy_data(e)
  872. check_sanity(sanity_data)
  873. if e.generateevents:
  874. sanity_data.setVar("SANITY_USE_EVENTS", "1")
  875. bb.event.fire(bb.event.SanityCheckPassed(), e.data)
  876. elif bb.event.getName(e) == "NetworkTest":
  877. sanity_data = copy_data(e)
  878. if e.generateevents:
  879. sanity_data.setVar("SANITY_USE_EVENTS", "1")
  880. bb.event.fire(bb.event.NetworkTestFailed() if check_connectivity(sanity_data) else bb.event.NetworkTestPassed(), e.data)
  881. return
  882. }