base.bbclass 27 KB

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