sanity.bbclass 42 KB

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