base.bbclass 28 KB

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