base.bbclass 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. BB_DEFAULT_TASK ?= "build"
  2. CLASSOVERRIDE ?= "class-target"
  3. inherit patch
  4. inherit staging
  5. inherit mirrors
  6. inherit utils
  7. inherit utility-tasks
  8. inherit metadata_scm
  9. inherit logging
  10. OE_EXTRA_IMPORTS ?= ""
  11. OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license ${OE_EXTRA_IMPORTS}"
  12. OE_IMPORTS[type] = "list"
  13. PACKAGECONFIG_CONFARGS ??= ""
  14. def oe_import(d):
  15. import sys
  16. bbpath = d.getVar("BBPATH").split(":")
  17. sys.path[0:0] = [os.path.join(dir, "lib") for dir in bbpath]
  18. def inject(name, value):
  19. """Make a python object accessible from the metadata"""
  20. if hasattr(bb.utils, "_context"):
  21. bb.utils._context[name] = value
  22. else:
  23. __builtins__[name] = value
  24. import oe.data
  25. for toimport in oe.data.typed_value("OE_IMPORTS", d):
  26. try:
  27. imported = __import__(toimport)
  28. inject(toimport.split(".", 1)[0], imported)
  29. except AttributeError as e:
  30. bb.error("Error importing OE modules: %s" % str(e))
  31. return ""
  32. # We need the oe module name space early (before INHERITs get added)
  33. OE_IMPORTED := "${@oe_import(d)}"
  34. def lsb_distro_identifier(d):
  35. adjust = d.getVar('LSB_DISTRO_ADJUST')
  36. adjust_func = None
  37. if adjust:
  38. try:
  39. adjust_func = globals()[adjust]
  40. except KeyError:
  41. pass
  42. return oe.lsb.distro_identifier(adjust_func)
  43. die() {
  44. bbfatal_log "$*"
  45. }
  46. oe_runmake_call() {
  47. bbnote ${MAKE} ${EXTRA_OEMAKE} "$@"
  48. ${MAKE} ${EXTRA_OEMAKE} "$@"
  49. }
  50. oe_runmake() {
  51. oe_runmake_call "$@" || die "oe_runmake failed"
  52. }
  53. def base_dep_prepend(d):
  54. if d.getVar('INHIBIT_DEFAULT_DEPS', False):
  55. return ""
  56. return "${BASE_DEFAULT_DEPS}"
  57. BASE_DEFAULT_DEPS = "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}compilerlibs virtual/libc"
  58. BASEDEPENDS = ""
  59. BASEDEPENDS_class-target = "${@base_dep_prepend(d)}"
  60. BASEDEPENDS_class-nativesdk = "${@base_dep_prepend(d)}"
  61. DEPENDS_prepend="${BASEDEPENDS} "
  62. FILESPATH = "${@base_set_filespath(["${FILE_DIRNAME}/${BP}", "${FILE_DIRNAME}/${BPN}", "${FILE_DIRNAME}/files"], d)}"
  63. # THISDIR only works properly with imediate expansion as it has to run
  64. # in the context of the location its used (:=)
  65. THISDIR = "${@os.path.dirname(d.getVar('FILE'))}"
  66. def extra_path_elements(d):
  67. path = ""
  68. elements = (d.getVar('EXTRANATIVEPATH') or "").split()
  69. for e in elements:
  70. path = path + "${STAGING_BINDIR_NATIVE}/" + e + ":"
  71. return path
  72. PATH_prepend = "${@extra_path_elements(d)}"
  73. def get_lic_checksum_file_list(d):
  74. filelist = []
  75. lic_files = d.getVar("LIC_FILES_CHKSUM") or ''
  76. tmpdir = d.getVar("TMPDIR")
  77. s = d.getVar("S")
  78. b = d.getVar("B")
  79. workdir = d.getVar("WORKDIR")
  80. urls = lic_files.split()
  81. for url in urls:
  82. # We only care about items that are absolute paths since
  83. # any others should be covered by SRC_URI.
  84. try:
  85. (method, host, path, user, pswd, parm) = bb.fetch.decodeurl(url)
  86. if method != "file" or not path:
  87. raise bb.fetch.MalformedUrl(url)
  88. if path[0] == '/':
  89. if path.startswith((tmpdir, s, b, workdir)):
  90. continue
  91. filelist.append(path + ":" + str(os.path.exists(path)))
  92. except bb.fetch.MalformedUrl:
  93. bb.fatal(d.getVar('PN') + ": LIC_FILES_CHKSUM contains an invalid URL: " + url)
  94. return " ".join(filelist)
  95. def setup_hosttools_dir(dest, toolsvar, d, fatal=True):
  96. tools = d.getVar(toolsvar).split()
  97. origbbenv = d.getVar("BB_ORIGENV", False)
  98. path = origbbenv.getVar("PATH")
  99. bb.utils.mkdirhier(dest)
  100. notfound = []
  101. for tool in tools:
  102. desttool = os.path.join(dest, tool)
  103. if not os.path.exists(desttool):
  104. # clean up dead symlink
  105. if os.path.islink(desttool):
  106. os.unlink(desttool)
  107. srctool = bb.utils.which(path, tool, executable=True)
  108. # gcc/g++ may link to ccache on some hosts, e.g.,
  109. # /usr/local/bin/ccache/gcc -> /usr/bin/ccache, then which(gcc)
  110. # would return /usr/local/bin/ccache/gcc, but what we need is
  111. # /usr/bin/gcc, this code can check and fix that.
  112. if "ccache" in srctool:
  113. srctool = bb.utils.which(path, tool, executable=True, direction=1)
  114. if srctool:
  115. os.symlink(srctool, desttool)
  116. else:
  117. notfound.append(tool)
  118. if notfound and fatal:
  119. bb.fatal("The following required tools (as specified by HOSTTOOLS) appear to be unavailable in PATH, please install them in order to proceed:\n %s" % " ".join(notfound))
  120. addtask fetch
  121. do_fetch[dirs] = "${DL_DIR}"
  122. do_fetch[file-checksums] = "${@bb.fetch.get_checksum_file_list(d)}"
  123. do_fetch[file-checksums] += " ${@get_lic_checksum_file_list(d)}"
  124. do_fetch[vardeps] += "SRCREV"
  125. python base_do_fetch() {
  126. src_uri = (d.getVar('SRC_URI') or "").split()
  127. if len(src_uri) == 0:
  128. return
  129. try:
  130. fetcher = bb.fetch2.Fetch(src_uri, d)
  131. fetcher.download()
  132. except bb.fetch2.BBFetchException as e:
  133. bb.fatal(str(e))
  134. }
  135. addtask unpack after do_fetch
  136. do_unpack[dirs] = "${WORKDIR}"
  137. do_unpack[cleandirs] = "${@d.getVar('S') if os.path.normpath(d.getVar('S')) != os.path.normpath(d.getVar('WORKDIR')) else os.path.join('${S}', 'patches')}"
  138. python base_do_unpack() {
  139. src_uri = (d.getVar('SRC_URI') or "").split()
  140. if len(src_uri) == 0:
  141. return
  142. try:
  143. fetcher = bb.fetch2.Fetch(src_uri, d)
  144. fetcher.unpack(d.getVar('WORKDIR'))
  145. except bb.fetch2.BBFetchException as e:
  146. bb.fatal(str(e))
  147. }
  148. def get_layers_branch_rev(d):
  149. layers = (d.getVar("BBLAYERS") or "").split()
  150. layers_branch_rev = ["%-20s = \"%s:%s\"" % (os.path.basename(i), \
  151. base_get_metadata_git_branch(i, None).strip(), \
  152. base_get_metadata_git_revision(i, None)) \
  153. for i in layers]
  154. i = len(layers_branch_rev)-1
  155. p1 = layers_branch_rev[i].find("=")
  156. s1 = layers_branch_rev[i][p1:]
  157. while i > 0:
  158. p2 = layers_branch_rev[i-1].find("=")
  159. s2= layers_branch_rev[i-1][p2:]
  160. if s1 == s2:
  161. layers_branch_rev[i-1] = layers_branch_rev[i-1][0:p2]
  162. i -= 1
  163. else:
  164. i -= 1
  165. p1 = layers_branch_rev[i].find("=")
  166. s1= layers_branch_rev[i][p1:]
  167. return layers_branch_rev
  168. BUILDCFG_FUNCS ??= "buildcfg_vars get_layers_branch_rev buildcfg_neededvars"
  169. BUILDCFG_FUNCS[type] = "list"
  170. def buildcfg_vars(d):
  171. statusvars = oe.data.typed_value('BUILDCFG_VARS', d)
  172. for var in statusvars:
  173. value = d.getVar(var)
  174. if value is not None:
  175. yield '%-20s = "%s"' % (var, value)
  176. def buildcfg_neededvars(d):
  177. needed_vars = oe.data.typed_value("BUILDCFG_NEEDEDVARS", d)
  178. pesteruser = []
  179. for v in needed_vars:
  180. val = d.getVar(v)
  181. if not val or val == 'INVALID':
  182. pesteruser.append(v)
  183. if pesteruser:
  184. bb.fatal('The following variable(s) were not set: %s\nPlease set them directly, or choose a MACHINE or DISTRO that sets them.' % ', '.join(pesteruser))
  185. addhandler base_eventhandler
  186. base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.MultiConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise bb.event.RecipeParsed"
  187. python base_eventhandler() {
  188. import bb.runqueue
  189. if isinstance(e, bb.event.ConfigParsed):
  190. if not d.getVar("NATIVELSBSTRING", False):
  191. d.setVar("NATIVELSBSTRING", lsb_distro_identifier(d))
  192. d.setVar('BB_VERSION', bb.__version__)
  193. # There might be no bb.event.ConfigParsed event if bitbake server is
  194. # running, so check bb.event.BuildStarted too to make sure ${HOSTTOOLS_DIR}
  195. # exists.
  196. if isinstance(e, bb.event.ConfigParsed) or \
  197. (isinstance(e, bb.event.BuildStarted) and not os.path.exists(d.getVar('HOSTTOOLS_DIR'))):
  198. # Works with the line in layer.conf which changes PATH to point here
  199. setup_hosttools_dir(d.getVar('HOSTTOOLS_DIR'), 'HOSTTOOLS', d)
  200. setup_hosttools_dir(d.getVar('HOSTTOOLS_DIR'), 'HOSTTOOLS_NONFATAL', d, fatal=False)
  201. if isinstance(e, bb.event.MultiConfigParsed):
  202. # We need to expand SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS in each of the multiconfig data stores
  203. # own contexts so the variables get expanded correctly for that arch, then inject back into
  204. # the main data store.
  205. deps = []
  206. for config in e.mcdata:
  207. deps.append(e.mcdata[config].getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS"))
  208. deps = " ".join(deps)
  209. e.mcdata[''].setVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", deps)
  210. if isinstance(e, bb.event.BuildStarted):
  211. localdata = bb.data.createCopy(d)
  212. statuslines = []
  213. for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata):
  214. g = globals()
  215. if func not in g:
  216. bb.warn("Build configuration function '%s' does not exist" % func)
  217. else:
  218. flines = g[func](localdata)
  219. if flines:
  220. statuslines.extend(flines)
  221. statusheader = d.getVar('BUILDCFG_HEADER')
  222. if statusheader:
  223. bb.plain('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines)))
  224. # This code is to silence warnings where the SDK variables overwrite the
  225. # target ones and we'd see dulpicate key names overwriting each other
  226. # for various PREFERRED_PROVIDERS
  227. if isinstance(e, bb.event.RecipePreFinalise):
  228. if d.getVar("TARGET_PREFIX") == d.getVar("SDK_PREFIX"):
  229. d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}binutils")
  230. d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc")
  231. d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}g++")
  232. d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}compilerlibs")
  233. if isinstance(e, bb.event.RecipeParsed):
  234. #
  235. # If we have multiple providers of virtual/X and a PREFERRED_PROVIDER_virtual/X is set
  236. # skip parsing for all the other providers which will mean they get uninstalled from the
  237. # sysroot since they're now "unreachable". This makes switching virtual/kernel work in
  238. # particular.
  239. #
  240. pn = d.getVar('PN')
  241. source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False)
  242. if not source_mirror_fetch:
  243. provs = (d.getVar("PROVIDES") or "").split()
  244. multiwhitelist = (d.getVar("MULTI_PROVIDER_WHITELIST") or "").split()
  245. for p in provs:
  246. if p.startswith("virtual/") and p not in multiwhitelist:
  247. profprov = d.getVar("PREFERRED_PROVIDER_" + p)
  248. if profprov and pn != profprov:
  249. raise bb.parse.SkipRecipe("PREFERRED_PROVIDER_%s set to %s, not %s" % (p, profprov, pn))
  250. }
  251. CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
  252. CLEANBROKEN = "0"
  253. addtask configure after do_patch
  254. do_configure[dirs] = "${B}"
  255. base_do_configure() {
  256. if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
  257. if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
  258. cd ${B}
  259. if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
  260. oe_runmake clean
  261. fi
  262. # -ignore_readdir_race does not work correctly with -delete;
  263. # use xargs to avoid spurious build failures
  264. find ${B} -ignore_readdir_race -name \*.la -type f -print0 | xargs -0 rm -f
  265. fi
  266. fi
  267. if [ -n "${CONFIGURESTAMPFILE}" ]; then
  268. mkdir -p `dirname ${CONFIGURESTAMPFILE}`
  269. echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
  270. fi
  271. }
  272. addtask compile after do_configure
  273. do_compile[dirs] = "${B}"
  274. base_do_compile() {
  275. if [ -e Makefile -o -e makefile -o -e GNUmakefile ]; then
  276. oe_runmake || die "make failed"
  277. else
  278. bbnote "nothing to compile"
  279. fi
  280. }
  281. addtask install after do_compile
  282. do_install[dirs] = "${B}"
  283. # Remove and re-create ${D} so that is it guaranteed to be empty
  284. do_install[cleandirs] = "${D}"
  285. base_do_install() {
  286. :
  287. }
  288. base_do_package() {
  289. :
  290. }
  291. addtask build after do_populate_sysroot
  292. do_build[noexec] = "1"
  293. do_build[recrdeptask] += "do_deploy"
  294. do_build () {
  295. :
  296. }
  297. def set_packagetriplet(d):
  298. archs = []
  299. tos = []
  300. tvs = []
  301. archs.append(d.getVar("PACKAGE_ARCHS").split())
  302. tos.append(d.getVar("TARGET_OS"))
  303. tvs.append(d.getVar("TARGET_VENDOR"))
  304. def settriplet(d, varname, archs, tos, tvs):
  305. triplets = []
  306. for i in range(len(archs)):
  307. for arch in archs[i]:
  308. triplets.append(arch + tvs[i] + "-" + tos[i])
  309. triplets.reverse()
  310. d.setVar(varname, " ".join(triplets))
  311. settriplet(d, "PKGTRIPLETS", archs, tos, tvs)
  312. variants = d.getVar("MULTILIB_VARIANTS") or ""
  313. for item in variants.split():
  314. localdata = bb.data.createCopy(d)
  315. overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
  316. localdata.setVar("OVERRIDES", overrides)
  317. archs.append(localdata.getVar("PACKAGE_ARCHS").split())
  318. tos.append(localdata.getVar("TARGET_OS"))
  319. tvs.append(localdata.getVar("TARGET_VENDOR"))
  320. settriplet(d, "PKGMLTRIPLETS", archs, tos, tvs)
  321. python () {
  322. import string, re
  323. # Handle backfilling
  324. oe.utils.features_backfill("DISTRO_FEATURES", d)
  325. oe.utils.features_backfill("MACHINE_FEATURES", d)
  326. if d.getVar("S")[-1] == '/':
  327. bb.warn("Recipe %s sets S variable with trailing slash '%s', remove it" % (d.getVar("PN"), d.getVar("S")))
  328. if d.getVar("B")[-1] == '/':
  329. bb.warn("Recipe %s sets B variable with trailing slash '%s', remove it" % (d.getVar("PN"), d.getVar("B")))
  330. if os.path.normpath(d.getVar("WORKDIR")) != os.path.normpath(d.getVar("S")):
  331. d.appendVar("PSEUDO_IGNORE_PATHS", ",${S}")
  332. if os.path.normpath(d.getVar("WORKDIR")) != os.path.normpath(d.getVar("B")):
  333. d.appendVar("PSEUDO_IGNORE_PATHS", ",${B}")
  334. # Handle PACKAGECONFIG
  335. #
  336. # These take the form:
  337. #
  338. # PACKAGECONFIG ??= "<default options>"
  339. # PACKAGECONFIG[foo] = "--enable-foo,--disable-foo,foo_depends,foo_runtime_depends,foo_runtime_recommends,foo_conflict_packageconfig"
  340. pkgconfigflags = d.getVarFlags("PACKAGECONFIG") or {}
  341. if pkgconfigflags:
  342. pkgconfig = (d.getVar('PACKAGECONFIG') or "").split()
  343. pn = d.getVar("PN")
  344. mlprefix = d.getVar("MLPREFIX")
  345. def expandFilter(appends, extension, prefix):
  346. appends = bb.utils.explode_deps(d.expand(" ".join(appends)))
  347. newappends = []
  348. for a in appends:
  349. if a.endswith("-native") or ("-cross-" in a):
  350. newappends.append(a)
  351. elif a.startswith("virtual/"):
  352. subs = a.split("/", 1)[1]
  353. if subs.startswith(prefix):
  354. newappends.append(a + extension)
  355. else:
  356. newappends.append("virtual/" + prefix + subs + extension)
  357. else:
  358. if a.startswith(prefix):
  359. newappends.append(a + extension)
  360. else:
  361. newappends.append(prefix + a + extension)
  362. return newappends
  363. def appendVar(varname, appends):
  364. if not appends:
  365. return
  366. if varname.find("DEPENDS") != -1:
  367. if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d) :
  368. appends = expandFilter(appends, "", "nativesdk-")
  369. elif bb.data.inherits_class('native', d):
  370. appends = expandFilter(appends, "-native", "")
  371. elif mlprefix:
  372. appends = expandFilter(appends, "", mlprefix)
  373. varname = d.expand(varname)
  374. d.appendVar(varname, " " + " ".join(appends))
  375. extradeps = []
  376. extrardeps = []
  377. extrarrecs = []
  378. extraconf = []
  379. for flag, flagval in sorted(pkgconfigflags.items()):
  380. items = flagval.split(",")
  381. num = len(items)
  382. if num > 6:
  383. bb.error("%s: PACKAGECONFIG[%s] Only enable,disable,depend,rdepend,rrecommend,conflict_packageconfig can be specified!"
  384. % (d.getVar('PN'), flag))
  385. if flag in pkgconfig:
  386. if num >= 3 and items[2]:
  387. extradeps.append(items[2])
  388. if num >= 4 and items[3]:
  389. extrardeps.append(items[3])
  390. if num >= 5 and items[4]:
  391. extrarrecs.append(items[4])
  392. if num >= 1 and items[0]:
  393. extraconf.append(items[0])
  394. elif num >= 2 and items[1]:
  395. extraconf.append(items[1])
  396. if num >= 6 and items[5]:
  397. conflicts = set(items[5].split())
  398. invalid = conflicts.difference(set(pkgconfigflags.keys()))
  399. if invalid:
  400. bb.error("%s: PACKAGECONFIG[%s] Invalid conflict package config%s '%s' specified."
  401. % (d.getVar('PN'), flag, 's' if len(invalid) > 1 else '', ' '.join(invalid)))
  402. if flag in pkgconfig:
  403. intersec = conflicts.intersection(set(pkgconfig))
  404. if intersec:
  405. bb.fatal("%s: PACKAGECONFIG[%s] Conflict package config%s '%s' set in PACKAGECONFIG."
  406. % (d.getVar('PN'), flag, 's' if len(intersec) > 1 else '', ' '.join(intersec)))
  407. appendVar('DEPENDS', extradeps)
  408. appendVar('RDEPENDS_${PN}', extrardeps)
  409. appendVar('RRECOMMENDS_${PN}', extrarrecs)
  410. appendVar('PACKAGECONFIG_CONFARGS', extraconf)
  411. pn = d.getVar('PN')
  412. license = d.getVar('LICENSE')
  413. if license == "INVALID" and pn != "defaultpkgname":
  414. bb.fatal('This recipe does not have the LICENSE field set (%s)' % pn)
  415. if bb.data.inherits_class('license', d):
  416. check_license_format(d)
  417. unmatched_license_flags = check_license_flags(d)
  418. if unmatched_license_flags:
  419. if len(unmatched_license_flags) == 1:
  420. message = "because it has a restricted license '{0}'. Which is not whitelisted in LICENSE_FLAGS_WHITELIST".format(unmatched_license_flags[0])
  421. else:
  422. message = "because it has restricted licenses {0}. Which are not whitelisted in LICENSE_FLAGS_WHITELIST".format(
  423. ", ".join("'{0}'".format(f) for f in unmatched_license_flags))
  424. bb.debug(1, "Skipping %s %s" % (pn, message))
  425. raise bb.parse.SkipRecipe(message)
  426. # If we're building a target package we need to use fakeroot (pseudo)
  427. # in order to capture permissions, owners, groups and special files
  428. if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
  429. d.appendVarFlag('do_prepare_recipe_sysroot', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
  430. d.setVarFlag('do_unpack', 'umask', '022')
  431. d.setVarFlag('do_configure', 'umask', '022')
  432. d.setVarFlag('do_compile', 'umask', '022')
  433. d.appendVarFlag('do_install', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
  434. d.setVarFlag('do_install', 'fakeroot', '1')
  435. d.setVarFlag('do_install', 'umask', '022')
  436. d.appendVarFlag('do_package', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
  437. d.setVarFlag('do_package', 'fakeroot', '1')
  438. d.setVarFlag('do_package', 'umask', '022')
  439. d.setVarFlag('do_package_setscene', 'fakeroot', '1')
  440. d.appendVarFlag('do_package_setscene', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
  441. d.setVarFlag('do_devshell', 'fakeroot', '1')
  442. d.appendVarFlag('do_devshell', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
  443. need_machine = d.getVar('COMPATIBLE_MACHINE')
  444. if need_machine and not d.getVar('PARSE_ALL_RECIPES', False):
  445. import re
  446. compat_machines = (d.getVar('MACHINEOVERRIDES') or "").split(":")
  447. for m in compat_machines:
  448. if re.match(need_machine, m):
  449. break
  450. else:
  451. raise bb.parse.SkipRecipe("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % d.getVar('MACHINE'))
  452. source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False) or d.getVar('PARSE_ALL_RECIPES', False)
  453. if not source_mirror_fetch:
  454. need_host = d.getVar('COMPATIBLE_HOST')
  455. if need_host:
  456. import re
  457. this_host = d.getVar('HOST_SYS')
  458. if not re.match(need_host, this_host):
  459. raise bb.parse.SkipRecipe("incompatible with host %s (not in COMPATIBLE_HOST)" % this_host)
  460. bad_licenses = (d.getVar('INCOMPATIBLE_LICENSE') or "").split()
  461. check_license = False if pn.startswith("nativesdk-") else True
  462. for t in ["-native", "-cross-${TARGET_ARCH}", "-cross-initial-${TARGET_ARCH}",
  463. "-crosssdk-${SDK_SYS}", "-crosssdk-initial-${SDK_SYS}",
  464. "-cross-canadian-${TRANSLATED_TARGET_ARCH}"]:
  465. if pn.endswith(d.expand(t)):
  466. check_license = False
  467. if pn.startswith("gcc-source-"):
  468. check_license = False
  469. if check_license and bad_licenses:
  470. bad_licenses = expand_wildcard_licenses(d, bad_licenses)
  471. whitelist = []
  472. for lic in bad_licenses:
  473. spdx_license = return_spdx(d, lic)
  474. whitelist.extend((d.getVar("WHITELIST_" + lic) or "").split())
  475. if spdx_license:
  476. whitelist.extend((d.getVar("WHITELIST_" + spdx_license) or "").split())
  477. if pn in whitelist:
  478. '''
  479. We need to track what we are whitelisting and why. If pn is
  480. incompatible we need to be able to note that the image that
  481. is created may infact contain incompatible licenses despite
  482. INCOMPATIBLE_LICENSE being set.
  483. '''
  484. bb.note("Including %s as buildable despite it having an incompatible license because it has been whitelisted" % pn)
  485. else:
  486. pkgs = d.getVar('PACKAGES').split()
  487. skipped_pkgs = {}
  488. unskipped_pkgs = []
  489. for pkg in pkgs:
  490. incompatible_lic = incompatible_license(d, bad_licenses, pkg)
  491. if incompatible_lic:
  492. skipped_pkgs[pkg] = incompatible_lic
  493. else:
  494. unskipped_pkgs.append(pkg)
  495. if unskipped_pkgs:
  496. for pkg in skipped_pkgs:
  497. bb.debug(1, "Skipping the package %s at do_rootfs because of incompatible license(s): %s" % (pkg, ' '.join(skipped_pkgs[pkg])))
  498. d.setVar('LICENSE_EXCLUSION-' + pkg, ' '.join(skipped_pkgs[pkg]))
  499. for pkg in unskipped_pkgs:
  500. bb.debug(1, "Including the package %s" % pkg)
  501. else:
  502. incompatible_lic = incompatible_license(d, bad_licenses)
  503. for pkg in skipped_pkgs:
  504. incompatible_lic += skipped_pkgs[pkg]
  505. incompatible_lic = sorted(list(set(incompatible_lic)))
  506. if incompatible_lic:
  507. bb.debug(1, "Skipping recipe %s because of incompatible license(s): %s" % (pn, ' '.join(incompatible_lic)))
  508. raise bb.parse.SkipRecipe("it has incompatible license(s): %s" % ' '.join(incompatible_lic))
  509. needsrcrev = False
  510. srcuri = d.getVar('SRC_URI')
  511. for uri in srcuri.split():
  512. (scheme, _ , path) = bb.fetch.decodeurl(uri)[:3]
  513. # HTTP/FTP use the wget fetcher
  514. if scheme in ("http", "https", "ftp"):
  515. d.appendVarFlag('do_fetch', 'depends', ' wget-native:do_populate_sysroot')
  516. # Svn packages should DEPEND on subversion-native
  517. if scheme == "svn":
  518. needsrcrev = True
  519. d.appendVarFlag('do_fetch', 'depends', ' subversion-native:do_populate_sysroot')
  520. # Git packages should DEPEND on git-native
  521. elif scheme in ("git", "gitsm"):
  522. needsrcrev = True
  523. d.appendVarFlag('do_fetch', 'depends', ' git-native:do_populate_sysroot')
  524. # Mercurial packages should DEPEND on mercurial-native
  525. elif scheme == "hg":
  526. needsrcrev = True
  527. d.appendVar("EXTRANATIVEPATH", ' python3-native ')
  528. d.appendVarFlag('do_fetch', 'depends', ' mercurial-native:do_populate_sysroot')
  529. # Perforce packages support SRCREV = "${AUTOREV}"
  530. elif scheme == "p4":
  531. needsrcrev = True
  532. # OSC packages should DEPEND on osc-native
  533. elif scheme == "osc":
  534. d.appendVarFlag('do_fetch', 'depends', ' osc-native:do_populate_sysroot')
  535. elif scheme == "npm":
  536. d.appendVarFlag('do_fetch', 'depends', ' nodejs-native:do_populate_sysroot')
  537. # *.lz4 should DEPEND on lz4-native for unpacking
  538. if path.endswith('.lz4'):
  539. d.appendVarFlag('do_unpack', 'depends', ' lz4-native:do_populate_sysroot')
  540. # *.lz should DEPEND on lzip-native for unpacking
  541. elif path.endswith('.lz'):
  542. d.appendVarFlag('do_unpack', 'depends', ' lzip-native:do_populate_sysroot')
  543. # *.xz should DEPEND on xz-native for unpacking
  544. elif path.endswith('.xz') or path.endswith('.txz'):
  545. d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
  546. # .zip should DEPEND on unzip-native for unpacking
  547. elif path.endswith('.zip') or path.endswith('.jar'):
  548. d.appendVarFlag('do_unpack', 'depends', ' unzip-native:do_populate_sysroot')
  549. # Some rpm files may be compressed internally using xz (for example, rpms from Fedora)
  550. elif path.endswith('.rpm'):
  551. d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
  552. # *.deb should DEPEND on xz-native for unpacking
  553. elif path.endswith('.deb'):
  554. d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
  555. if needsrcrev:
  556. d.setVar("SRCPV", "${@bb.fetch2.get_srcrev(d)}")
  557. # Gather all named SRCREVs to add to the sstate hash calculation
  558. # This anonymous python snippet is called multiple times so we
  559. # need to be careful to not double up the appends here and cause
  560. # the base hash to mismatch the task hash
  561. for uri in srcuri.split():
  562. parm = bb.fetch.decodeurl(uri)[5]
  563. uri_names = parm.get("name", "").split(",")
  564. for uri_name in filter(None, uri_names):
  565. srcrev_name = "SRCREV_{}".format(uri_name)
  566. if srcrev_name not in (d.getVarFlag("do_fetch", "vardeps") or "").split():
  567. d.appendVarFlag("do_fetch", "vardeps", " {}".format(srcrev_name))
  568. set_packagetriplet(d)
  569. # 'multimachine' handling
  570. mach_arch = d.getVar('MACHINE_ARCH')
  571. pkg_arch = d.getVar('PACKAGE_ARCH')
  572. if (pkg_arch == mach_arch):
  573. # Already machine specific - nothing further to do
  574. return
  575. #
  576. # We always try to scan SRC_URI for urls with machine overrides
  577. # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
  578. #
  579. override = d.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH')
  580. if override != '0':
  581. paths = []
  582. fpaths = (d.getVar('FILESPATH') or '').split(':')
  583. machine = d.getVar('MACHINE')
  584. for p in fpaths:
  585. if os.path.basename(p) == machine and os.path.isdir(p):
  586. paths.append(p)
  587. if len(paths) != 0:
  588. for s in srcuri.split():
  589. if not s.startswith("file://"):
  590. continue
  591. fetcher = bb.fetch2.Fetch([s], d)
  592. local = fetcher.localpath(s)
  593. for mp in paths:
  594. if local.startswith(mp):
  595. #bb.note("overriding PACKAGE_ARCH from %s to %s for %s" % (pkg_arch, mach_arch, pn))
  596. d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
  597. return
  598. packages = d.getVar('PACKAGES').split()
  599. for pkg in packages:
  600. pkgarch = d.getVar("PACKAGE_ARCH_%s" % pkg)
  601. # We could look for != PACKAGE_ARCH here but how to choose
  602. # if multiple differences are present?
  603. # Look through PACKAGE_ARCHS for the priority order?
  604. if pkgarch and pkgarch == mach_arch:
  605. d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
  606. bb.warn("Recipe %s is marked as only being architecture specific but seems to have machine specific packages?! The recipe may as well mark itself as machine specific directly." % d.getVar("PN"))
  607. }
  608. addtask cleansstate after do_clean
  609. python do_cleansstate() {
  610. sstate_clean_cachefiles(d)
  611. }
  612. addtask cleanall after do_cleansstate
  613. do_cleansstate[nostamp] = "1"
  614. python do_cleanall() {
  615. src_uri = (d.getVar('SRC_URI') or "").split()
  616. if len(src_uri) == 0:
  617. return
  618. try:
  619. fetcher = bb.fetch2.Fetch(src_uri, d)
  620. fetcher.clean()
  621. except bb.fetch2.BBFetchException as e:
  622. bb.fatal(str(e))
  623. }
  624. do_cleanall[nostamp] = "1"
  625. EXPORT_FUNCTIONS do_fetch do_unpack do_configure do_compile do_install do_package