blob: 5f4956a1d31b2f6ddf8a80f299d461ecce5c5e5f [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001BB_DEFAULT_TASK ?= "build"
2CLASSOVERRIDE ?= "class-target"
3
4inherit patch
5inherit staging
6
7inherit mirrors
8inherit utils
9inherit utility-tasks
10inherit metadata_scm
11inherit logging
12
Brad Bishop15ae2502019-06-18 21:44:24 -040013OE_EXTRA_IMPORTS ?= ""
14
Andrew Geisslereff27472021-10-29 15:35:00 -050015OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license oe.qa oe.reproducible ${OE_EXTRA_IMPORTS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016OE_IMPORTS[type] = "list"
17
Brad Bishopf3fd2882019-06-21 08:06:37 -040018PACKAGECONFIG_CONFARGS ??= ""
19
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020def oe_import(d):
21 import sys
22
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 bbpath = d.getVar("BBPATH").split(":")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024 sys.path[0:0] = [os.path.join(dir, "lib") for dir in bbpath]
25
26 def inject(name, value):
27 """Make a python object accessible from the metadata"""
28 if hasattr(bb.utils, "_context"):
29 bb.utils._context[name] = value
30 else:
31 __builtins__[name] = value
32
33 import oe.data
34 for toimport in oe.data.typed_value("OE_IMPORTS", d):
Brad Bishop00e122a2019-10-05 11:10:57 -040035 try:
36 imported = __import__(toimport)
37 inject(toimport.split(".", 1)[0], imported)
38 except AttributeError as e:
39 bb.error("Error importing OE modules: %s" % str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 return ""
41
42# We need the oe module name space early (before INHERITs get added)
43OE_IMPORTED := "${@oe_import(d)}"
44
45def lsb_distro_identifier(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 adjust = d.getVar('LSB_DISTRO_ADJUST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047 adjust_func = None
48 if adjust:
49 try:
50 adjust_func = globals()[adjust]
51 except KeyError:
52 pass
53 return oe.lsb.distro_identifier(adjust_func)
54
55die() {
56 bbfatal_log "$*"
57}
58
59oe_runmake_call() {
60 bbnote ${MAKE} ${EXTRA_OEMAKE} "$@"
61 ${MAKE} ${EXTRA_OEMAKE} "$@"
62}
63
64oe_runmake() {
65 oe_runmake_call "$@" || die "oe_runmake failed"
66}
67
68
Patrick Williams213cb262021-08-07 19:21:33 -050069def get_base_dep(d):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070 if d.getVar('INHIBIT_DEFAULT_DEPS', False):
71 return ""
72 return "${BASE_DEFAULT_DEPS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
Brad Bishopd7bf8c12018-02-25 22:55:05 -050074BASE_DEFAULT_DEPS = "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}compilerlibs virtual/libc"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076BASEDEPENDS = ""
Patrick Williams213cb262021-08-07 19:21:33 -050077BASEDEPENDS:class-target = "${@get_base_dep(d)}"
78BASEDEPENDS:class-nativesdk = "${@get_base_dep(d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079
Patrick Williams213cb262021-08-07 19:21:33 -050080DEPENDS:prepend="${BASEDEPENDS} "
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081
82FILESPATH = "${@base_set_filespath(["${FILE_DIRNAME}/${BP}", "${FILE_DIRNAME}/${BPN}", "${FILE_DIRNAME}/files"], d)}"
83# THISDIR only works properly with imediate expansion as it has to run
84# in the context of the location its used (:=)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050085THISDIR = "${@os.path.dirname(d.getVar('FILE'))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086
87def extra_path_elements(d):
88 path = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050089 elements = (d.getVar('EXTRANATIVEPATH') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050090 for e in elements:
91 path = path + "${STAGING_BINDIR_NATIVE}/" + e + ":"
92 return path
93
Patrick Williams213cb262021-08-07 19:21:33 -050094PATH:prepend = "${@extra_path_elements(d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095
96def get_lic_checksum_file_list(d):
97 filelist = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 lic_files = d.getVar("LIC_FILES_CHKSUM") or ''
99 tmpdir = d.getVar("TMPDIR")
100 s = d.getVar("S")
101 b = d.getVar("B")
102 workdir = d.getVar("WORKDIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103
104 urls = lic_files.split()
105 for url in urls:
106 # We only care about items that are absolute paths since
107 # any others should be covered by SRC_URI.
108 try:
Brad Bishop220d5532018-08-14 00:59:39 +0100109 (method, host, path, user, pswd, parm) = bb.fetch.decodeurl(url)
110 if method != "file" or not path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600111 raise bb.fetch.MalformedUrl(url)
112
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 if path[0] == '/':
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500114 if path.startswith((tmpdir, s, b, workdir)):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 continue
116 filelist.append(path + ":" + str(os.path.exists(path)))
117 except bb.fetch.MalformedUrl:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118 bb.fatal(d.getVar('PN') + ": LIC_FILES_CHKSUM contains an invalid URL: " + url)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 return " ".join(filelist)
120
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500121def setup_hosttools_dir(dest, toolsvar, d, fatal=True):
122 tools = d.getVar(toolsvar).split()
123 origbbenv = d.getVar("BB_ORIGENV", False)
124 path = origbbenv.getVar("PATH")
125 bb.utils.mkdirhier(dest)
126 notfound = []
127 for tool in tools:
128 desttool = os.path.join(dest, tool)
129 if not os.path.exists(desttool):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500130 # clean up dead symlink
131 if os.path.islink(desttool):
132 os.unlink(desttool)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500133 srctool = bb.utils.which(path, tool, executable=True)
Brad Bishop19323692019-04-05 15:28:33 -0400134 # gcc/g++ may link to ccache on some hosts, e.g.,
135 # /usr/local/bin/ccache/gcc -> /usr/bin/ccache, then which(gcc)
136 # would return /usr/local/bin/ccache/gcc, but what we need is
137 # /usr/bin/gcc, this code can check and fix that.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138 if "ccache" in srctool:
139 srctool = bb.utils.which(path, tool, executable=True, direction=1)
140 if srctool:
141 os.symlink(srctool, desttool)
142 else:
143 notfound.append(tool)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800144
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500145 if notfound and fatal:
146 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))
147
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148addtask fetch
149do_fetch[dirs] = "${DL_DIR}"
150do_fetch[file-checksums] = "${@bb.fetch.get_checksum_file_list(d)}"
151do_fetch[file-checksums] += " ${@get_lic_checksum_file_list(d)}"
152do_fetch[vardeps] += "SRCREV"
Andrew Geissler595f6302022-01-24 19:11:47 +0000153do_fetch[network] = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154python base_do_fetch() {
155
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500156 src_uri = (d.getVar('SRC_URI') or "").split()
Andrew Geisslereff27472021-10-29 15:35:00 -0500157 if not src_uri:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158 return
159
160 try:
161 fetcher = bb.fetch2.Fetch(src_uri, d)
162 fetcher.download()
163 except bb.fetch2.BBFetchException as e:
Andrew Geisslereff27472021-10-29 15:35:00 -0500164 bb.fatal("Bitbake Fetcher Error: " + repr(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165}
166
167addtask unpack after do_fetch
168do_unpack[dirs] = "${WORKDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600169
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800170do_unpack[cleandirs] = "${@d.getVar('S') if os.path.normpath(d.getVar('S')) != os.path.normpath(d.getVar('WORKDIR')) else os.path.join('${S}', 'patches')}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400171
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172python base_do_unpack() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500173 src_uri = (d.getVar('SRC_URI') or "").split()
Andrew Geisslereff27472021-10-29 15:35:00 -0500174 if not src_uri:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175 return
176
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500177 try:
178 fetcher = bb.fetch2.Fetch(src_uri, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500179 fetcher.unpack(d.getVar('WORKDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500180 except bb.fetch2.BBFetchException as e:
Andrew Geisslereff27472021-10-29 15:35:00 -0500181 bb.fatal("Bitbake Fetcher Error: " + repr(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182}
183
Andrew Geisslereff27472021-10-29 15:35:00 -0500184SSTATETASKS += "do_deploy_source_date_epoch"
185
186do_deploy_source_date_epoch () {
187 mkdir -p ${SDE_DEPLOYDIR}
188 if [ -e ${SDE_FILE} ]; then
189 echo "Deploying SDE from ${SDE_FILE} -> ${SDE_DEPLOYDIR}."
190 cp -p ${SDE_FILE} ${SDE_DEPLOYDIR}/__source_date_epoch.txt
191 else
192 echo "${SDE_FILE} not found!"
193 fi
194}
195
196python do_deploy_source_date_epoch_setscene () {
197 sstate_setscene(d)
198 bb.utils.mkdirhier(d.getVar('SDE_DIR'))
199 sde_file = os.path.join(d.getVar('SDE_DEPLOYDIR'), '__source_date_epoch.txt')
200 if os.path.exists(sde_file):
201 target = d.getVar('SDE_FILE')
202 bb.debug(1, "Moving setscene SDE file %s -> %s" % (sde_file, target))
203 bb.utils.rename(sde_file, target)
204 else:
205 bb.debug(1, "%s not found!" % sde_file)
206}
207
208do_deploy_source_date_epoch[dirs] = "${SDE_DEPLOYDIR}"
209do_deploy_source_date_epoch[sstate-plaindirs] = "${SDE_DEPLOYDIR}"
210addtask do_deploy_source_date_epoch_setscene
211addtask do_deploy_source_date_epoch before do_configure after do_patch
212
213python create_source_date_epoch_stamp() {
214 source_date_epoch = oe.reproducible.get_source_date_epoch(d, d.getVar('S'))
215 oe.reproducible.epochfile_write(source_date_epoch, d.getVar('SDE_FILE'), d)
216}
217do_unpack[postfuncs] += "create_source_date_epoch_stamp"
218
219def get_source_date_epoch_value(d):
220 return oe.reproducible.epochfile_read(d.getVar('SDE_FILE'), d)
221
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222def get_layers_branch_rev(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500223 layers = (d.getVar("BBLAYERS") or "").split()
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500224 layers_branch_rev = ["%-20s = \"%s:%s\"" % (os.path.basename(i), \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500225 base_get_metadata_git_branch(i, None).strip(), \
226 base_get_metadata_git_revision(i, None)) \
227 for i in layers]
228 i = len(layers_branch_rev)-1
229 p1 = layers_branch_rev[i].find("=")
230 s1 = layers_branch_rev[i][p1:]
231 while i > 0:
232 p2 = layers_branch_rev[i-1].find("=")
233 s2= layers_branch_rev[i-1][p2:]
234 if s1 == s2:
235 layers_branch_rev[i-1] = layers_branch_rev[i-1][0:p2]
236 i -= 1
237 else:
238 i -= 1
239 p1 = layers_branch_rev[i].find("=")
240 s1= layers_branch_rev[i][p1:]
241 return layers_branch_rev
242
243
244BUILDCFG_FUNCS ??= "buildcfg_vars get_layers_branch_rev buildcfg_neededvars"
245BUILDCFG_FUNCS[type] = "list"
246
247def buildcfg_vars(d):
248 statusvars = oe.data.typed_value('BUILDCFG_VARS', d)
249 for var in statusvars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500250 value = d.getVar(var)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251 if value is not None:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500252 yield '%-20s = "%s"' % (var, value)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253
254def buildcfg_neededvars(d):
255 needed_vars = oe.data.typed_value("BUILDCFG_NEEDEDVARS", d)
256 pesteruser = []
257 for v in needed_vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500258 val = d.getVar(v)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500259 if not val or val == 'INVALID':
260 pesteruser.append(v)
261
262 if pesteruser:
263 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))
264
265addhandler base_eventhandler
Brad Bishop19323692019-04-05 15:28:33 -0400266base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.MultiConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise bb.event.RecipeParsed"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267python base_eventhandler() {
268 import bb.runqueue
269
270 if isinstance(e, bb.event.ConfigParsed):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400271 if not d.getVar("NATIVELSBSTRING", False):
272 d.setVar("NATIVELSBSTRING", lsb_distro_identifier(d))
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600273 d.setVar("ORIGNATIVELSBSTRING", d.getVar("NATIVELSBSTRING", False))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400274 d.setVar('BB_VERSION', bb.__version__)
Brad Bishop19323692019-04-05 15:28:33 -0400275
276 # There might be no bb.event.ConfigParsed event if bitbake server is
277 # running, so check bb.event.BuildStarted too to make sure ${HOSTTOOLS_DIR}
278 # exists.
279 if isinstance(e, bb.event.ConfigParsed) or \
280 (isinstance(e, bb.event.BuildStarted) and not os.path.exists(d.getVar('HOSTTOOLS_DIR'))):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500281 # Works with the line in layer.conf which changes PATH to point here
282 setup_hosttools_dir(d.getVar('HOSTTOOLS_DIR'), 'HOSTTOOLS', d)
283 setup_hosttools_dir(d.getVar('HOSTTOOLS_DIR'), 'HOSTTOOLS_NONFATAL', d, fatal=False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500285 if isinstance(e, bb.event.MultiConfigParsed):
286 # We need to expand SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS in each of the multiconfig data stores
287 # own contexts so the variables get expanded correctly for that arch, then inject back into
288 # the main data store.
289 deps = []
290 for config in e.mcdata:
291 deps.append(e.mcdata[config].getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS"))
292 deps = " ".join(deps)
293 e.mcdata[''].setVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", deps)
294
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500295 if isinstance(e, bb.event.BuildStarted):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400296 localdata = bb.data.createCopy(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500297 statuslines = []
298 for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata):
299 g = globals()
300 if func not in g:
301 bb.warn("Build configuration function '%s' does not exist" % func)
302 else:
303 flines = g[func](localdata)
304 if flines:
305 statuslines.extend(flines)
306
Brad Bishop316dfdd2018-06-25 12:45:53 -0400307 statusheader = d.getVar('BUILDCFG_HEADER')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500308 if statusheader:
309 bb.plain('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310
311 # This code is to silence warnings where the SDK variables overwrite the
312 # target ones and we'd see dulpicate key names overwriting each other
313 # for various PREFERRED_PROVIDERS
314 if isinstance(e, bb.event.RecipePreFinalise):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400315 if d.getVar("TARGET_PREFIX") == d.getVar("SDK_PREFIX"):
316 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}binutils")
Brad Bishop316dfdd2018-06-25 12:45:53 -0400317 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc")
318 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}g++")
319 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}compilerlibs")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500321 if isinstance(e, bb.event.RecipeParsed):
322 #
323 # If we have multiple providers of virtual/X and a PREFERRED_PROVIDER_virtual/X is set
324 # skip parsing for all the other providers which will mean they get uninstalled from the
325 # sysroot since they're now "unreachable". This makes switching virtual/kernel work in
326 # particular.
327 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500328 pn = d.getVar('PN')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500329 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False)
330 if not source_mirror_fetch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500331 provs = (d.getVar("PROVIDES") or "").split()
332 multiwhitelist = (d.getVar("MULTI_PROVIDER_WHITELIST") or "").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500333 for p in provs:
334 if p.startswith("virtual/") and p not in multiwhitelist:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500335 profprov = d.getVar("PREFERRED_PROVIDER_" + p)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500336 if profprov and pn != profprov:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400337 raise bb.parse.SkipRecipe("PREFERRED_PROVIDER_%s set to %s, not %s" % (p, profprov, pn))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338}
339
340CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
341CLEANBROKEN = "0"
342
343addtask configure after do_patch
344do_configure[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500345base_do_configure() {
346 if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
347 if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
348 cd ${B}
349 if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
350 oe_runmake clean
351 fi
Brad Bishopc4ea0752018-11-15 14:30:15 -0800352 # -ignore_readdir_race does not work correctly with -delete;
353 # use xargs to avoid spurious build failures
354 find ${B} -ignore_readdir_race -name \*.la -type f -print0 | xargs -0 rm -f
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500355 fi
356 fi
357 if [ -n "${CONFIGURESTAMPFILE}" ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500358 mkdir -p `dirname ${CONFIGURESTAMPFILE}`
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500359 echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
360 fi
361}
362
363addtask compile after do_configure
364do_compile[dirs] = "${B}"
365base_do_compile() {
366 if [ -e Makefile -o -e makefile -o -e GNUmakefile ]; then
367 oe_runmake || die "make failed"
368 else
369 bbnote "nothing to compile"
370 fi
371}
372
373addtask install after do_compile
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600374do_install[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500375# Remove and re-create ${D} so that is it guaranteed to be empty
376do_install[cleandirs] = "${D}"
377
378base_do_install() {
379 :
380}
381
382base_do_package() {
383 :
384}
385
386addtask build after do_populate_sysroot
387do_build[noexec] = "1"
388do_build[recrdeptask] += "do_deploy"
389do_build () {
390 :
391}
392
393def set_packagetriplet(d):
394 archs = []
395 tos = []
396 tvs = []
397
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500398 archs.append(d.getVar("PACKAGE_ARCHS").split())
399 tos.append(d.getVar("TARGET_OS"))
400 tvs.append(d.getVar("TARGET_VENDOR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500401
402 def settriplet(d, varname, archs, tos, tvs):
403 triplets = []
404 for i in range(len(archs)):
405 for arch in archs[i]:
406 triplets.append(arch + tvs[i] + "-" + tos[i])
407 triplets.reverse()
408 d.setVar(varname, " ".join(triplets))
409
410 settriplet(d, "PKGTRIPLETS", archs, tos, tvs)
411
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500412 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500413 for item in variants.split():
414 localdata = bb.data.createCopy(d)
415 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
416 localdata.setVar("OVERRIDES", overrides)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500417
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500418 archs.append(localdata.getVar("PACKAGE_ARCHS").split())
419 tos.append(localdata.getVar("TARGET_OS"))
420 tvs.append(localdata.getVar("TARGET_VENDOR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500421
422 settriplet(d, "PKGMLTRIPLETS", archs, tos, tvs)
423
424python () {
425 import string, re
426
Brad Bishop316dfdd2018-06-25 12:45:53 -0400427 # Handle backfilling
428 oe.utils.features_backfill("DISTRO_FEATURES", d)
429 oe.utils.features_backfill("MACHINE_FEATURES", d)
430
Andrew Geisslerf0343792020-11-18 10:42:21 -0600431 if d.getVar("S")[-1] == '/':
432 bb.warn("Recipe %s sets S variable with trailing slash '%s', remove it" % (d.getVar("PN"), d.getVar("S")))
433 if d.getVar("B")[-1] == '/':
434 bb.warn("Recipe %s sets B variable with trailing slash '%s', remove it" % (d.getVar("PN"), d.getVar("B")))
435
436 if os.path.normpath(d.getVar("WORKDIR")) != os.path.normpath(d.getVar("S")):
437 d.appendVar("PSEUDO_IGNORE_PATHS", ",${S}")
438 if os.path.normpath(d.getVar("WORKDIR")) != os.path.normpath(d.getVar("B")):
439 d.appendVar("PSEUDO_IGNORE_PATHS", ",${B}")
440
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500441 # Handle PACKAGECONFIG
442 #
443 # These take the form:
444 #
445 # PACKAGECONFIG ??= "<default options>"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500446 # PACKAGECONFIG[foo] = "--enable-foo,--disable-foo,foo_depends,foo_runtime_depends,foo_runtime_recommends,foo_conflict_packageconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500447 pkgconfigflags = d.getVarFlags("PACKAGECONFIG") or {}
448 if pkgconfigflags:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500449 pkgconfig = (d.getVar('PACKAGECONFIG') or "").split()
450 pn = d.getVar("PN")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500451
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500452 mlprefix = d.getVar("MLPREFIX")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500453
454 def expandFilter(appends, extension, prefix):
455 appends = bb.utils.explode_deps(d.expand(" ".join(appends)))
456 newappends = []
457 for a in appends:
458 if a.endswith("-native") or ("-cross-" in a):
459 newappends.append(a)
460 elif a.startswith("virtual/"):
461 subs = a.split("/", 1)[1]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500462 if subs.startswith(prefix):
463 newappends.append(a + extension)
464 else:
465 newappends.append("virtual/" + prefix + subs + extension)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500466 else:
467 if a.startswith(prefix):
468 newappends.append(a + extension)
469 else:
470 newappends.append(prefix + a + extension)
471 return newappends
472
473 def appendVar(varname, appends):
474 if not appends:
475 return
476 if varname.find("DEPENDS") != -1:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500477 if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d) :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500478 appends = expandFilter(appends, "", "nativesdk-")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500479 elif bb.data.inherits_class('native', d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500480 appends = expandFilter(appends, "-native", "")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500481 elif mlprefix:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500482 appends = expandFilter(appends, "", mlprefix)
483 varname = d.expand(varname)
484 d.appendVar(varname, " " + " ".join(appends))
485
486 extradeps = []
487 extrardeps = []
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500488 extrarrecs = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500489 extraconf = []
490 for flag, flagval in sorted(pkgconfigflags.items()):
491 items = flagval.split(",")
492 num = len(items)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500493 if num > 6:
494 bb.error("%s: PACKAGECONFIG[%s] Only enable,disable,depend,rdepend,rrecommend,conflict_packageconfig can be specified!"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500495 % (d.getVar('PN'), flag))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500496
497 if flag in pkgconfig:
498 if num >= 3 and items[2]:
499 extradeps.append(items[2])
500 if num >= 4 and items[3]:
501 extrardeps.append(items[3])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500502 if num >= 5 and items[4]:
503 extrarrecs.append(items[4])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500504 if num >= 1 and items[0]:
505 extraconf.append(items[0])
506 elif num >= 2 and items[1]:
507 extraconf.append(items[1])
Andrew Geissler82c905d2020-04-13 13:39:40 -0500508
509 if num >= 6 and items[5]:
510 conflicts = set(items[5].split())
511 invalid = conflicts.difference(set(pkgconfigflags.keys()))
512 if invalid:
513 bb.error("%s: PACKAGECONFIG[%s] Invalid conflict package config%s '%s' specified."
514 % (d.getVar('PN'), flag, 's' if len(invalid) > 1 else '', ' '.join(invalid)))
515
516 if flag in pkgconfig:
517 intersec = conflicts.intersection(set(pkgconfig))
518 if intersec:
519 bb.fatal("%s: PACKAGECONFIG[%s] Conflict package config%s '%s' set in PACKAGECONFIG."
520 % (d.getVar('PN'), flag, 's' if len(intersec) > 1 else '', ' '.join(intersec)))
521
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500522 appendVar('DEPENDS', extradeps)
Patrick Williams213cb262021-08-07 19:21:33 -0500523 appendVar('RDEPENDS:${PN}', extrardeps)
524 appendVar('RRECOMMENDS:${PN}', extrarrecs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500525 appendVar('PACKAGECONFIG_CONFARGS', extraconf)
526
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500527 pn = d.getVar('PN')
528 license = d.getVar('LICENSE')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400529 if license == "INVALID" and pn != "defaultpkgname":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500530 bb.fatal('This recipe does not have the LICENSE field set (%s)' % pn)
531
532 if bb.data.inherits_class('license', d):
533 check_license_format(d)
Brad Bishop19323692019-04-05 15:28:33 -0400534 unmatched_license_flags = check_license_flags(d)
535 if unmatched_license_flags:
536 if len(unmatched_license_flags) == 1:
537 message = "because it has a restricted license '{0}'. Which is not whitelisted in LICENSE_FLAGS_WHITELIST".format(unmatched_license_flags[0])
538 else:
539 message = "because it has restricted licenses {0}. Which are not whitelisted in LICENSE_FLAGS_WHITELIST".format(
540 ", ".join("'{0}'".format(f) for f in unmatched_license_flags))
541 bb.debug(1, "Skipping %s %s" % (pn, message))
542 raise bb.parse.SkipRecipe(message)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500543
544 # If we're building a target package we need to use fakeroot (pseudo)
545 # in order to capture permissions, owners, groups and special files
546 if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
Brad Bishop64c979e2019-11-04 13:55:29 -0500547 d.appendVarFlag('do_prepare_recipe_sysroot', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500548 d.appendVarFlag('do_install', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500549 d.setVarFlag('do_install', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500550 d.appendVarFlag('do_package', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500551 d.setVarFlag('do_package', 'fakeroot', '1')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500552 d.setVarFlag('do_package_setscene', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500553 d.appendVarFlag('do_package_setscene', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500554 d.setVarFlag('do_devshell', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500555 d.appendVarFlag('do_devshell', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500556
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500557 need_machine = d.getVar('COMPATIBLE_MACHINE')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500558 if need_machine and not d.getVar('PARSE_ALL_RECIPES', False):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500559 import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500560 compat_machines = (d.getVar('MACHINEOVERRIDES') or "").split(":")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500561 for m in compat_machines:
562 if re.match(need_machine, m):
563 break
564 else:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400565 raise bb.parse.SkipRecipe("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % d.getVar('MACHINE'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500566
Andrew Geissler82c905d2020-04-13 13:39:40 -0500567 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False) or d.getVar('PARSE_ALL_RECIPES', False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500568 if not source_mirror_fetch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500569 need_host = d.getVar('COMPATIBLE_HOST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500570 if need_host:
571 import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500572 this_host = d.getVar('HOST_SYS')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500573 if not re.match(need_host, this_host):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400574 raise bb.parse.SkipRecipe("incompatible with host %s (not in COMPATIBLE_HOST)" % this_host)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500575
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500576 bad_licenses = (d.getVar('INCOMPATIBLE_LICENSE') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500577
578 check_license = False if pn.startswith("nativesdk-") else True
579 for t in ["-native", "-cross-${TARGET_ARCH}", "-cross-initial-${TARGET_ARCH}",
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600580 "-crosssdk-${SDK_SYS}", "-crosssdk-initial-${SDK_SYS}",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500581 "-cross-canadian-${TRANSLATED_TARGET_ARCH}"]:
582 if pn.endswith(d.expand(t)):
583 check_license = False
584 if pn.startswith("gcc-source-"):
585 check_license = False
586
587 if check_license and bad_licenses:
588 bad_licenses = expand_wildcard_licenses(d, bad_licenses)
589
590 whitelist = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500591 for lic in bad_licenses:
592 spdx_license = return_spdx(d, lic)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800593 whitelist.extend((d.getVar("WHITELIST_" + lic) or "").split())
594 if spdx_license:
595 whitelist.extend((d.getVar("WHITELIST_" + spdx_license) or "").split())
Andrew Geissler82c905d2020-04-13 13:39:40 -0500596
597 if pn in whitelist:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800598 '''
599 We need to track what we are whitelisting and why. If pn is
600 incompatible we need to be able to note that the image that
601 is created may infact contain incompatible licenses despite
602 INCOMPATIBLE_LICENSE being set.
603 '''
Andrew Geissler82c905d2020-04-13 13:39:40 -0500604 bb.note("Including %s as buildable despite it having an incompatible license because it has been whitelisted" % pn)
605 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500606 pkgs = d.getVar('PACKAGES').split()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500607 skipped_pkgs = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500608 unskipped_pkgs = []
609 for pkg in pkgs:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500610 incompatible_lic = incompatible_license(d, bad_licenses, pkg)
611 if incompatible_lic:
612 skipped_pkgs[pkg] = incompatible_lic
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500613 else:
614 unskipped_pkgs.append(pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500615 if unskipped_pkgs:
616 for pkg in skipped_pkgs:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500617 bb.debug(1, "Skipping the package %s at do_rootfs because of incompatible license(s): %s" % (pkg, ' '.join(skipped_pkgs[pkg])))
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500618 d.setVar('LICENSE_EXCLUSION-' + pkg, ' '.join(skipped_pkgs[pkg]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500619 for pkg in unskipped_pkgs:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500620 bb.debug(1, "Including the package %s" % pkg)
621 else:
622 incompatible_lic = incompatible_license(d, bad_licenses)
623 for pkg in skipped_pkgs:
624 incompatible_lic += skipped_pkgs[pkg]
625 incompatible_lic = sorted(list(set(incompatible_lic)))
626
627 if incompatible_lic:
628 bb.debug(1, "Skipping recipe %s because of incompatible license(s): %s" % (pn, ' '.join(incompatible_lic)))
629 raise bb.parse.SkipRecipe("it has incompatible license(s): %s" % ' '.join(incompatible_lic))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500630
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500631 needsrcrev = False
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500632 srcuri = d.getVar('SRC_URI')
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600633 for uri_string in srcuri.split():
634 uri = bb.fetch.URI(uri_string)
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500635 # Also check downloadfilename as the URL path might not be useful for sniffing
636 path = uri.params.get("downloadfilename", uri.path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500637
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500638 # HTTP/FTP use the wget fetcher
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600639 if uri.scheme in ("http", "https", "ftp"):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500640 d.appendVarFlag('do_fetch', 'depends', ' wget-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500641
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500642 # Svn packages should DEPEND on subversion-native
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600643 if uri.scheme == "svn":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500644 needsrcrev = True
645 d.appendVarFlag('do_fetch', 'depends', ' subversion-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500646
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500647 # Git packages should DEPEND on git-native
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600648 elif uri.scheme in ("git", "gitsm"):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500649 needsrcrev = True
650 d.appendVarFlag('do_fetch', 'depends', ' git-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500651
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500652 # Mercurial packages should DEPEND on mercurial-native
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600653 elif uri.scheme == "hg":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500654 needsrcrev = True
Andrew Geissler82c905d2020-04-13 13:39:40 -0500655 d.appendVar("EXTRANATIVEPATH", ' python3-native ')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500656 d.appendVarFlag('do_fetch', 'depends', ' mercurial-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500657
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600658 # Perforce packages support SRCREV = "${AUTOREV}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600659 elif uri.scheme == "p4":
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600660 needsrcrev = True
661
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500662 # OSC packages should DEPEND on osc-native
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600663 elif uri.scheme == "osc":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500664 d.appendVarFlag('do_fetch', 'depends', ' osc-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500665
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600666 elif uri.scheme == "npm":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500667 d.appendVarFlag('do_fetch', 'depends', ' nodejs-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500668
Andrew Geissler595f6302022-01-24 19:11:47 +0000669 elif uri.scheme == "repo":
670 needsrcrev = True
671 d.appendVarFlag('do_fetch', 'depends', ' repo-native:do_populate_sysroot')
672
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500673 # *.lz4 should DEPEND on lz4-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500674 if path.endswith('.lz4'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500675 d.appendVarFlag('do_unpack', 'depends', ' lz4-native:do_populate_sysroot')
676
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500677 # *.zst should DEPEND on zstd-native for unpacking
678 elif path.endswith('.zst'):
679 d.appendVarFlag('do_unpack', 'depends', ' zstd-native:do_populate_sysroot')
680
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500681 # *.lz should DEPEND on lzip-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500682 elif path.endswith('.lz'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500683 d.appendVarFlag('do_unpack', 'depends', ' lzip-native:do_populate_sysroot')
684
685 # *.xz should DEPEND on xz-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500686 elif path.endswith('.xz') or path.endswith('.txz'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500687 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
688
689 # .zip should DEPEND on unzip-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500690 elif path.endswith('.zip') or path.endswith('.jar'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500691 d.appendVarFlag('do_unpack', 'depends', ' unzip-native:do_populate_sysroot')
692
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800693 # Some rpm files may be compressed internally using xz (for example, rpms from Fedora)
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500694 elif path.endswith('.rpm'):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500695 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500696
Brad Bishop316dfdd2018-06-25 12:45:53 -0400697 # *.deb should DEPEND on xz-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500698 elif path.endswith('.deb'):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400699 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
700
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500701 if needsrcrev:
702 d.setVar("SRCPV", "${@bb.fetch2.get_srcrev(d)}")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500703
Brad Bishop15ae2502019-06-18 21:44:24 -0400704 # Gather all named SRCREVs to add to the sstate hash calculation
705 # This anonymous python snippet is called multiple times so we
706 # need to be careful to not double up the appends here and cause
707 # the base hash to mismatch the task hash
708 for uri in srcuri.split():
709 parm = bb.fetch.decodeurl(uri)[5]
710 uri_names = parm.get("name", "").split(",")
711 for uri_name in filter(None, uri_names):
712 srcrev_name = "SRCREV_{}".format(uri_name)
713 if srcrev_name not in (d.getVarFlag("do_fetch", "vardeps") or "").split():
714 d.appendVarFlag("do_fetch", "vardeps", " {}".format(srcrev_name))
715
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500716 set_packagetriplet(d)
717
718 # 'multimachine' handling
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500719 mach_arch = d.getVar('MACHINE_ARCH')
720 pkg_arch = d.getVar('PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500721
722 if (pkg_arch == mach_arch):
723 # Already machine specific - nothing further to do
724 return
725
726 #
727 # We always try to scan SRC_URI for urls with machine overrides
728 # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
729 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500730 override = d.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500731 if override != '0':
732 paths = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500733 fpaths = (d.getVar('FILESPATH') or '').split(':')
734 machine = d.getVar('MACHINE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500735 for p in fpaths:
736 if os.path.basename(p) == machine and os.path.isdir(p):
737 paths.append(p)
738
Andrew Geisslereff27472021-10-29 15:35:00 -0500739 if paths:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500740 for s in srcuri.split():
741 if not s.startswith("file://"):
742 continue
743 fetcher = bb.fetch2.Fetch([s], d)
744 local = fetcher.localpath(s)
745 for mp in paths:
746 if local.startswith(mp):
747 #bb.note("overriding PACKAGE_ARCH from %s to %s for %s" % (pkg_arch, mach_arch, pn))
748 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
749 return
750
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500751 packages = d.getVar('PACKAGES').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500752 for pkg in packages:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500753 pkgarch = d.getVar("PACKAGE_ARCH_%s" % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500754
755 # We could look for != PACKAGE_ARCH here but how to choose
756 # if multiple differences are present?
757 # Look through PACKAGE_ARCHS for the priority order?
758 if pkgarch and pkgarch == mach_arch:
759 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500760 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"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500761}
762
763addtask cleansstate after do_clean
764python do_cleansstate() {
765 sstate_clean_cachefiles(d)
766}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500767addtask cleanall after do_cleansstate
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500768do_cleansstate[nostamp] = "1"
769
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500770python do_cleanall() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500771 src_uri = (d.getVar('SRC_URI') or "").split()
Andrew Geisslereff27472021-10-29 15:35:00 -0500772 if not src_uri:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500773 return
774
775 try:
776 fetcher = bb.fetch2.Fetch(src_uri, d)
777 fetcher.clean()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600778 except bb.fetch2.BBFetchException as e:
779 bb.fatal(str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500780}
781do_cleanall[nostamp] = "1"
782
783
784EXPORT_FUNCTIONS do_fetch do_unpack do_configure do_compile do_install do_package