blob: 3515720bf95ff8cdf1e3b05770c8abf7c9915009 [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 Jefferyecdf5f12022-03-01 01:09:46 +103015OE_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.rust ${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
Patrick Williams45852732022-04-02 08:58:32 -050023 bbpath = [os.path.join(dir, "lib") for dir in d.getVar("BBPATH").split(":")]
24 sys.path[0:0] = [dir for dir in bbpath if dir not in sys.path]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025
26 import oe.data
27 for toimport in oe.data.typed_value("OE_IMPORTS", d):
Brad Bishop00e122a2019-10-05 11:10:57 -040028 try:
Patrick Williams45852732022-04-02 08:58:32 -050029 # Make a python object accessible from the metadata
30 bb.utils._context[toimport.split(".", 1)[0]] = __import__(toimport)
Brad Bishop00e122a2019-10-05 11:10:57 -040031 except AttributeError as e:
32 bb.error("Error importing OE modules: %s" % str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 return ""
34
35# We need the oe module name space early (before INHERITs get added)
36OE_IMPORTED := "${@oe_import(d)}"
37
38def lsb_distro_identifier(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050039 adjust = d.getVar('LSB_DISTRO_ADJUST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 adjust_func = None
41 if adjust:
42 try:
43 adjust_func = globals()[adjust]
44 except KeyError:
45 pass
46 return oe.lsb.distro_identifier(adjust_func)
47
48die() {
49 bbfatal_log "$*"
50}
51
52oe_runmake_call() {
53 bbnote ${MAKE} ${EXTRA_OEMAKE} "$@"
54 ${MAKE} ${EXTRA_OEMAKE} "$@"
55}
56
57oe_runmake() {
58 oe_runmake_call "$@" || die "oe_runmake failed"
59}
60
61
Patrick Williams213cb262021-08-07 19:21:33 -050062def get_base_dep(d):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063 if d.getVar('INHIBIT_DEFAULT_DEPS', False):
64 return ""
65 return "${BASE_DEFAULT_DEPS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000067BASE_DEFAULT_DEPS = "virtual/${HOST_PREFIX}gcc virtual/${HOST_PREFIX}compilerlibs virtual/libc"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068
Brad Bishopd7bf8c12018-02-25 22:55:05 -050069BASEDEPENDS = ""
Patrick Williams213cb262021-08-07 19:21:33 -050070BASEDEPENDS:class-target = "${@get_base_dep(d)}"
71BASEDEPENDS:class-nativesdk = "${@get_base_dep(d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072
Patrick Williams213cb262021-08-07 19:21:33 -050073DEPENDS:prepend="${BASEDEPENDS} "
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074
75FILESPATH = "${@base_set_filespath(["${FILE_DIRNAME}/${BP}", "${FILE_DIRNAME}/${BPN}", "${FILE_DIRNAME}/files"], d)}"
76# THISDIR only works properly with imediate expansion as it has to run
77# in the context of the location its used (:=)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050078THISDIR = "${@os.path.dirname(d.getVar('FILE'))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079
80def extra_path_elements(d):
81 path = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050082 elements = (d.getVar('EXTRANATIVEPATH') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083 for e in elements:
84 path = path + "${STAGING_BINDIR_NATIVE}/" + e + ":"
85 return path
86
Patrick Williams213cb262021-08-07 19:21:33 -050087PATH:prepend = "${@extra_path_elements(d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088
89def get_lic_checksum_file_list(d):
90 filelist = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -050091 lic_files = d.getVar("LIC_FILES_CHKSUM") or ''
92 tmpdir = d.getVar("TMPDIR")
93 s = d.getVar("S")
94 b = d.getVar("B")
95 workdir = d.getVar("WORKDIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096
97 urls = lic_files.split()
98 for url in urls:
99 # We only care about items that are absolute paths since
100 # any others should be covered by SRC_URI.
101 try:
Brad Bishop220d5532018-08-14 00:59:39 +0100102 (method, host, path, user, pswd, parm) = bb.fetch.decodeurl(url)
103 if method != "file" or not path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600104 raise bb.fetch.MalformedUrl(url)
105
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500106 if path[0] == '/':
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500107 if path.startswith((tmpdir, s, b, workdir)):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108 continue
109 filelist.append(path + ":" + str(os.path.exists(path)))
110 except bb.fetch.MalformedUrl:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500111 bb.fatal(d.getVar('PN') + ": LIC_FILES_CHKSUM contains an invalid URL: " + url)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 return " ".join(filelist)
113
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500114def setup_hosttools_dir(dest, toolsvar, d, fatal=True):
115 tools = d.getVar(toolsvar).split()
116 origbbenv = d.getVar("BB_ORIGENV", False)
117 path = origbbenv.getVar("PATH")
118 bb.utils.mkdirhier(dest)
119 notfound = []
120 for tool in tools:
121 desttool = os.path.join(dest, tool)
122 if not os.path.exists(desttool):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500123 # clean up dead symlink
124 if os.path.islink(desttool):
125 os.unlink(desttool)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500126 srctool = bb.utils.which(path, tool, executable=True)
Brad Bishop19323692019-04-05 15:28:33 -0400127 # gcc/g++ may link to ccache on some hosts, e.g.,
128 # /usr/local/bin/ccache/gcc -> /usr/bin/ccache, then which(gcc)
129 # would return /usr/local/bin/ccache/gcc, but what we need is
130 # /usr/bin/gcc, this code can check and fix that.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500131 if "ccache" in srctool:
132 srctool = bb.utils.which(path, tool, executable=True, direction=1)
133 if srctool:
134 os.symlink(srctool, desttool)
135 else:
136 notfound.append(tool)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800137
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138 if notfound and fatal:
139 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))
140
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141addtask fetch
142do_fetch[dirs] = "${DL_DIR}"
143do_fetch[file-checksums] = "${@bb.fetch.get_checksum_file_list(d)}"
144do_fetch[file-checksums] += " ${@get_lic_checksum_file_list(d)}"
145do_fetch[vardeps] += "SRCREV"
Andrew Geissler595f6302022-01-24 19:11:47 +0000146do_fetch[network] = "1"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147python base_do_fetch() {
148
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500149 src_uri = (d.getVar('SRC_URI') or "").split()
Andrew Geisslereff27472021-10-29 15:35:00 -0500150 if not src_uri:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151 return
152
153 try:
154 fetcher = bb.fetch2.Fetch(src_uri, d)
155 fetcher.download()
156 except bb.fetch2.BBFetchException as e:
Andrew Geisslereff27472021-10-29 15:35:00 -0500157 bb.fatal("Bitbake Fetcher Error: " + repr(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158}
159
160addtask unpack after do_fetch
161do_unpack[dirs] = "${WORKDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600162
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800163do_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 -0400164
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165python base_do_unpack() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500166 src_uri = (d.getVar('SRC_URI') or "").split()
Andrew Geisslereff27472021-10-29 15:35:00 -0500167 if not src_uri:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168 return
169
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500170 try:
171 fetcher = bb.fetch2.Fetch(src_uri, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500172 fetcher.unpack(d.getVar('WORKDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500173 except bb.fetch2.BBFetchException as e:
Andrew Geisslereff27472021-10-29 15:35:00 -0500174 bb.fatal("Bitbake Fetcher Error: " + repr(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175}
176
Andrew Geisslereff27472021-10-29 15:35:00 -0500177SSTATETASKS += "do_deploy_source_date_epoch"
178
179do_deploy_source_date_epoch () {
180 mkdir -p ${SDE_DEPLOYDIR}
181 if [ -e ${SDE_FILE} ]; then
182 echo "Deploying SDE from ${SDE_FILE} -> ${SDE_DEPLOYDIR}."
183 cp -p ${SDE_FILE} ${SDE_DEPLOYDIR}/__source_date_epoch.txt
184 else
185 echo "${SDE_FILE} not found!"
186 fi
187}
188
189python do_deploy_source_date_epoch_setscene () {
190 sstate_setscene(d)
191 bb.utils.mkdirhier(d.getVar('SDE_DIR'))
192 sde_file = os.path.join(d.getVar('SDE_DEPLOYDIR'), '__source_date_epoch.txt')
193 if os.path.exists(sde_file):
194 target = d.getVar('SDE_FILE')
195 bb.debug(1, "Moving setscene SDE file %s -> %s" % (sde_file, target))
196 bb.utils.rename(sde_file, target)
197 else:
198 bb.debug(1, "%s not found!" % sde_file)
199}
200
201do_deploy_source_date_epoch[dirs] = "${SDE_DEPLOYDIR}"
202do_deploy_source_date_epoch[sstate-plaindirs] = "${SDE_DEPLOYDIR}"
203addtask do_deploy_source_date_epoch_setscene
204addtask do_deploy_source_date_epoch before do_configure after do_patch
205
206python create_source_date_epoch_stamp() {
207 source_date_epoch = oe.reproducible.get_source_date_epoch(d, d.getVar('S'))
208 oe.reproducible.epochfile_write(source_date_epoch, d.getVar('SDE_FILE'), d)
209}
210do_unpack[postfuncs] += "create_source_date_epoch_stamp"
211
212def get_source_date_epoch_value(d):
213 return oe.reproducible.epochfile_read(d.getVar('SDE_FILE'), d)
214
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215def get_layers_branch_rev(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 layers = (d.getVar("BBLAYERS") or "").split()
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500217 layers_branch_rev = ["%-20s = \"%s:%s\"" % (os.path.basename(i), \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218 base_get_metadata_git_branch(i, None).strip(), \
219 base_get_metadata_git_revision(i, None)) \
220 for i in layers]
221 i = len(layers_branch_rev)-1
222 p1 = layers_branch_rev[i].find("=")
223 s1 = layers_branch_rev[i][p1:]
224 while i > 0:
225 p2 = layers_branch_rev[i-1].find("=")
226 s2= layers_branch_rev[i-1][p2:]
227 if s1 == s2:
228 layers_branch_rev[i-1] = layers_branch_rev[i-1][0:p2]
229 i -= 1
230 else:
231 i -= 1
232 p1 = layers_branch_rev[i].find("=")
233 s1= layers_branch_rev[i][p1:]
234 return layers_branch_rev
235
236
237BUILDCFG_FUNCS ??= "buildcfg_vars get_layers_branch_rev buildcfg_neededvars"
238BUILDCFG_FUNCS[type] = "list"
239
240def buildcfg_vars(d):
241 statusvars = oe.data.typed_value('BUILDCFG_VARS', d)
242 for var in statusvars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500243 value = d.getVar(var)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 if value is not None:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500245 yield '%-20s = "%s"' % (var, value)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246
247def buildcfg_neededvars(d):
248 needed_vars = oe.data.typed_value("BUILDCFG_NEEDEDVARS", d)
249 pesteruser = []
250 for v in needed_vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500251 val = d.getVar(v)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500252 if not val or val == 'INVALID':
253 pesteruser.append(v)
254
255 if pesteruser:
256 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))
257
258addhandler base_eventhandler
Brad Bishop19323692019-04-05 15:28:33 -0400259base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.MultiConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise bb.event.RecipeParsed"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260python base_eventhandler() {
261 import bb.runqueue
262
263 if isinstance(e, bb.event.ConfigParsed):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400264 if not d.getVar("NATIVELSBSTRING", False):
265 d.setVar("NATIVELSBSTRING", lsb_distro_identifier(d))
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600266 d.setVar("ORIGNATIVELSBSTRING", d.getVar("NATIVELSBSTRING", False))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400267 d.setVar('BB_VERSION', bb.__version__)
Brad Bishop19323692019-04-05 15:28:33 -0400268
269 # There might be no bb.event.ConfigParsed event if bitbake server is
270 # running, so check bb.event.BuildStarted too to make sure ${HOSTTOOLS_DIR}
271 # exists.
272 if isinstance(e, bb.event.ConfigParsed) or \
273 (isinstance(e, bb.event.BuildStarted) and not os.path.exists(d.getVar('HOSTTOOLS_DIR'))):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500274 # Works with the line in layer.conf which changes PATH to point here
275 setup_hosttools_dir(d.getVar('HOSTTOOLS_DIR'), 'HOSTTOOLS', d)
276 setup_hosttools_dir(d.getVar('HOSTTOOLS_DIR'), 'HOSTTOOLS_NONFATAL', d, fatal=False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500277
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500278 if isinstance(e, bb.event.MultiConfigParsed):
279 # We need to expand SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS in each of the multiconfig data stores
280 # own contexts so the variables get expanded correctly for that arch, then inject back into
281 # the main data store.
282 deps = []
283 for config in e.mcdata:
284 deps.append(e.mcdata[config].getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS"))
285 deps = " ".join(deps)
286 e.mcdata[''].setVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", deps)
287
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288 if isinstance(e, bb.event.BuildStarted):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400289 localdata = bb.data.createCopy(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290 statuslines = []
291 for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata):
292 g = globals()
293 if func not in g:
294 bb.warn("Build configuration function '%s' does not exist" % func)
295 else:
296 flines = g[func](localdata)
297 if flines:
298 statuslines.extend(flines)
299
Brad Bishop316dfdd2018-06-25 12:45:53 -0400300 statusheader = d.getVar('BUILDCFG_HEADER')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500301 if statusheader:
302 bb.plain('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500303
304 # This code is to silence warnings where the SDK variables overwrite the
305 # target ones and we'd see dulpicate key names overwriting each other
306 # for various PREFERRED_PROVIDERS
307 if isinstance(e, bb.event.RecipePreFinalise):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400308 if d.getVar("TARGET_PREFIX") == d.getVar("SDK_PREFIX"):
309 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}binutils")
Brad Bishop316dfdd2018-06-25 12:45:53 -0400310 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc")
311 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}g++")
312 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}compilerlibs")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500313
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500314 if isinstance(e, bb.event.RecipeParsed):
315 #
316 # If we have multiple providers of virtual/X and a PREFERRED_PROVIDER_virtual/X is set
317 # skip parsing for all the other providers which will mean they get uninstalled from the
318 # sysroot since they're now "unreachable". This makes switching virtual/kernel work in
319 # particular.
320 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500321 pn = d.getVar('PN')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500322 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False)
323 if not source_mirror_fetch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500324 provs = (d.getVar("PROVIDES") or "").split()
Andrew Geissler9aee5002022-03-30 16:27:02 +0000325 multiprovidersallowed = (d.getVar("BB_MULTI_PROVIDER_ALLOWED") or "").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500326 for p in provs:
Andrew Geissler9aee5002022-03-30 16:27:02 +0000327 if p.startswith("virtual/") and p not in multiprovidersallowed:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500328 profprov = d.getVar("PREFERRED_PROVIDER_" + p)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500329 if profprov and pn != profprov:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400330 raise bb.parse.SkipRecipe("PREFERRED_PROVIDER_%s set to %s, not %s" % (p, profprov, pn))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331}
332
333CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
334CLEANBROKEN = "0"
335
336addtask configure after do_patch
337do_configure[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338base_do_configure() {
339 if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
340 if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
341 cd ${B}
342 if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
343 oe_runmake clean
344 fi
Brad Bishopc4ea0752018-11-15 14:30:15 -0800345 # -ignore_readdir_race does not work correctly with -delete;
346 # use xargs to avoid spurious build failures
347 find ${B} -ignore_readdir_race -name \*.la -type f -print0 | xargs -0 rm -f
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500348 fi
349 fi
350 if [ -n "${CONFIGURESTAMPFILE}" ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500351 mkdir -p `dirname ${CONFIGURESTAMPFILE}`
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352 echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
353 fi
354}
355
356addtask compile after do_configure
357do_compile[dirs] = "${B}"
358base_do_compile() {
359 if [ -e Makefile -o -e makefile -o -e GNUmakefile ]; then
360 oe_runmake || die "make failed"
361 else
362 bbnote "nothing to compile"
363 fi
364}
365
366addtask install after do_compile
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600367do_install[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500368# Remove and re-create ${D} so that is it guaranteed to be empty
369do_install[cleandirs] = "${D}"
370
371base_do_install() {
372 :
373}
374
375base_do_package() {
376 :
377}
378
379addtask build after do_populate_sysroot
380do_build[noexec] = "1"
381do_build[recrdeptask] += "do_deploy"
382do_build () {
383 :
384}
385
386def set_packagetriplet(d):
387 archs = []
388 tos = []
389 tvs = []
390
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500391 archs.append(d.getVar("PACKAGE_ARCHS").split())
392 tos.append(d.getVar("TARGET_OS"))
393 tvs.append(d.getVar("TARGET_VENDOR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500394
395 def settriplet(d, varname, archs, tos, tvs):
396 triplets = []
397 for i in range(len(archs)):
398 for arch in archs[i]:
399 triplets.append(arch + tvs[i] + "-" + tos[i])
400 triplets.reverse()
401 d.setVar(varname, " ".join(triplets))
402
403 settriplet(d, "PKGTRIPLETS", archs, tos, tvs)
404
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500405 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500406 for item in variants.split():
407 localdata = bb.data.createCopy(d)
408 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
409 localdata.setVar("OVERRIDES", overrides)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500410
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 archs.append(localdata.getVar("PACKAGE_ARCHS").split())
412 tos.append(localdata.getVar("TARGET_OS"))
413 tvs.append(localdata.getVar("TARGET_VENDOR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500414
415 settriplet(d, "PKGMLTRIPLETS", archs, tos, tvs)
416
417python () {
418 import string, re
419
Brad Bishop316dfdd2018-06-25 12:45:53 -0400420 # Handle backfilling
421 oe.utils.features_backfill("DISTRO_FEATURES", d)
422 oe.utils.features_backfill("MACHINE_FEATURES", d)
423
Andrew Geisslerf0343792020-11-18 10:42:21 -0600424 if d.getVar("S")[-1] == '/':
425 bb.warn("Recipe %s sets S variable with trailing slash '%s', remove it" % (d.getVar("PN"), d.getVar("S")))
426 if d.getVar("B")[-1] == '/':
427 bb.warn("Recipe %s sets B variable with trailing slash '%s', remove it" % (d.getVar("PN"), d.getVar("B")))
428
429 if os.path.normpath(d.getVar("WORKDIR")) != os.path.normpath(d.getVar("S")):
430 d.appendVar("PSEUDO_IGNORE_PATHS", ",${S}")
431 if os.path.normpath(d.getVar("WORKDIR")) != os.path.normpath(d.getVar("B")):
432 d.appendVar("PSEUDO_IGNORE_PATHS", ",${B}")
433
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000434 # To add a recipe to the skip list , set:
435 # SKIP_RECIPE[pn] = "message"
436 pn = d.getVar('PN')
437 skip_msg = d.getVarFlag('SKIP_RECIPE', pn)
438 if skip_msg:
439 bb.debug(1, "Skipping %s %s" % (pn, skip_msg))
440 raise bb.parse.SkipRecipe("Recipe will be skipped because: %s" % (skip_msg))
441
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500442 # Handle PACKAGECONFIG
443 #
444 # These take the form:
445 #
446 # PACKAGECONFIG ??= "<default options>"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500447 # PACKAGECONFIG[foo] = "--enable-foo,--disable-foo,foo_depends,foo_runtime_depends,foo_runtime_recommends,foo_conflict_packageconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500448 pkgconfigflags = d.getVarFlags("PACKAGECONFIG") or {}
449 if pkgconfigflags:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500450 pkgconfig = (d.getVar('PACKAGECONFIG') or "").split()
451 pn = d.getVar("PN")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500452
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500453 mlprefix = d.getVar("MLPREFIX")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500454
455 def expandFilter(appends, extension, prefix):
456 appends = bb.utils.explode_deps(d.expand(" ".join(appends)))
457 newappends = []
458 for a in appends:
459 if a.endswith("-native") or ("-cross-" in a):
460 newappends.append(a)
461 elif a.startswith("virtual/"):
462 subs = a.split("/", 1)[1]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500463 if subs.startswith(prefix):
464 newappends.append(a + extension)
465 else:
466 newappends.append("virtual/" + prefix + subs + extension)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500467 else:
468 if a.startswith(prefix):
469 newappends.append(a + extension)
470 else:
471 newappends.append(prefix + a + extension)
472 return newappends
473
474 def appendVar(varname, appends):
475 if not appends:
476 return
477 if varname.find("DEPENDS") != -1:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500478 if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d) :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500479 appends = expandFilter(appends, "", "nativesdk-")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500480 elif bb.data.inherits_class('native', d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500481 appends = expandFilter(appends, "-native", "")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500482 elif mlprefix:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500483 appends = expandFilter(appends, "", mlprefix)
484 varname = d.expand(varname)
485 d.appendVar(varname, " " + " ".join(appends))
486
487 extradeps = []
488 extrardeps = []
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500489 extrarrecs = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500490 extraconf = []
491 for flag, flagval in sorted(pkgconfigflags.items()):
492 items = flagval.split(",")
493 num = len(items)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500494 if num > 6:
495 bb.error("%s: PACKAGECONFIG[%s] Only enable,disable,depend,rdepend,rrecommend,conflict_packageconfig can be specified!"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500496 % (d.getVar('PN'), flag))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500497
498 if flag in pkgconfig:
499 if num >= 3 and items[2]:
500 extradeps.append(items[2])
501 if num >= 4 and items[3]:
502 extrardeps.append(items[3])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500503 if num >= 5 and items[4]:
504 extrarrecs.append(items[4])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500505 if num >= 1 and items[0]:
506 extraconf.append(items[0])
507 elif num >= 2 and items[1]:
508 extraconf.append(items[1])
Andrew Geissler82c905d2020-04-13 13:39:40 -0500509
510 if num >= 6 and items[5]:
511 conflicts = set(items[5].split())
512 invalid = conflicts.difference(set(pkgconfigflags.keys()))
513 if invalid:
514 bb.error("%s: PACKAGECONFIG[%s] Invalid conflict package config%s '%s' specified."
515 % (d.getVar('PN'), flag, 's' if len(invalid) > 1 else '', ' '.join(invalid)))
516
517 if flag in pkgconfig:
518 intersec = conflicts.intersection(set(pkgconfig))
519 if intersec:
520 bb.fatal("%s: PACKAGECONFIG[%s] Conflict package config%s '%s' set in PACKAGECONFIG."
521 % (d.getVar('PN'), flag, 's' if len(intersec) > 1 else '', ' '.join(intersec)))
522
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500523 appendVar('DEPENDS', extradeps)
Patrick Williams213cb262021-08-07 19:21:33 -0500524 appendVar('RDEPENDS:${PN}', extrardeps)
525 appendVar('RRECOMMENDS:${PN}', extrarrecs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500526 appendVar('PACKAGECONFIG_CONFARGS', extraconf)
527
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500528 pn = d.getVar('PN')
529 license = d.getVar('LICENSE')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400530 if license == "INVALID" and pn != "defaultpkgname":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500531 bb.fatal('This recipe does not have the LICENSE field set (%s)' % pn)
532
533 if bb.data.inherits_class('license', d):
534 check_license_format(d)
Brad Bishop19323692019-04-05 15:28:33 -0400535 unmatched_license_flags = check_license_flags(d)
536 if unmatched_license_flags:
537 if len(unmatched_license_flags) == 1:
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000538 message = "because it has a restricted license '{0}'. Which is not listed in LICENSE_FLAGS_ACCEPTED".format(unmatched_license_flags[0])
Brad Bishop19323692019-04-05 15:28:33 -0400539 else:
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000540 message = "because it has restricted licenses {0}. Which are not listed in LICENSE_FLAGS_ACCEPTED".format(
Brad Bishop19323692019-04-05 15:28:33 -0400541 ", ".join("'{0}'".format(f) for f in unmatched_license_flags))
542 bb.debug(1, "Skipping %s %s" % (pn, message))
543 raise bb.parse.SkipRecipe(message)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500544
545 # If we're building a target package we need to use fakeroot (pseudo)
546 # in order to capture permissions, owners, groups and special files
547 if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
Brad Bishop64c979e2019-11-04 13:55:29 -0500548 d.appendVarFlag('do_prepare_recipe_sysroot', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500549 d.appendVarFlag('do_install', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500550 d.setVarFlag('do_install', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500551 d.appendVarFlag('do_package', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500552 d.setVarFlag('do_package', 'fakeroot', '1')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500553 d.setVarFlag('do_package_setscene', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500554 d.appendVarFlag('do_package_setscene', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500555 d.setVarFlag('do_devshell', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500556 d.appendVarFlag('do_devshell', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500557
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500558 need_machine = d.getVar('COMPATIBLE_MACHINE')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500559 if need_machine and not d.getVar('PARSE_ALL_RECIPES', False):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500560 import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500561 compat_machines = (d.getVar('MACHINEOVERRIDES') or "").split(":")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500562 for m in compat_machines:
563 if re.match(need_machine, m):
564 break
565 else:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400566 raise bb.parse.SkipRecipe("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % d.getVar('MACHINE'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500567
Andrew Geissler82c905d2020-04-13 13:39:40 -0500568 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False) or d.getVar('PARSE_ALL_RECIPES', False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500569 if not source_mirror_fetch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500570 need_host = d.getVar('COMPATIBLE_HOST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500571 if need_host:
572 import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500573 this_host = d.getVar('HOST_SYS')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500574 if not re.match(need_host, this_host):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400575 raise bb.parse.SkipRecipe("incompatible with host %s (not in COMPATIBLE_HOST)" % this_host)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500576
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500577 bad_licenses = (d.getVar('INCOMPATIBLE_LICENSE') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500578
579 check_license = False if pn.startswith("nativesdk-") else True
580 for t in ["-native", "-cross-${TARGET_ARCH}", "-cross-initial-${TARGET_ARCH}",
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600581 "-crosssdk-${SDK_SYS}", "-crosssdk-initial-${SDK_SYS}",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500582 "-cross-canadian-${TRANSLATED_TARGET_ARCH}"]:
583 if pn.endswith(d.expand(t)):
584 check_license = False
585 if pn.startswith("gcc-source-"):
586 check_license = False
587
588 if check_license and bad_licenses:
589 bad_licenses = expand_wildcard_licenses(d, bad_licenses)
590
Andrew Geissler9aee5002022-03-30 16:27:02 +0000591 exceptions = (d.getVar("INCOMPATIBLE_LICENSE_EXCEPTIONS") or "").split()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500592
Andrew Geissler9aee5002022-03-30 16:27:02 +0000593 for lic_exception in exceptions:
594 if ":" in lic_exception:
595 lic_exception.split(":")[0]
596 if lic_exception in oe.license.obsolete_license_list():
597 bb.fatal("Invalid license %s used in INCOMPATIBLE_LICENSE_EXCEPTIONS" % lic_exception)
598
599 pkgs = d.getVar('PACKAGES').split()
600 skipped_pkgs = {}
601 unskipped_pkgs = []
602 for pkg in pkgs:
603 remaining_bad_licenses = oe.license.apply_pkg_license_exception(pkg, bad_licenses, exceptions)
604
605 incompatible_lic = incompatible_license(d, remaining_bad_licenses, pkg)
606 if incompatible_lic:
607 skipped_pkgs[pkg] = incompatible_lic
Andrew Geissler82c905d2020-04-13 13:39:40 -0500608 else:
Andrew Geissler9aee5002022-03-30 16:27:02 +0000609 unskipped_pkgs.append(pkg)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500610
Andrew Geissler9aee5002022-03-30 16:27:02 +0000611 if unskipped_pkgs:
612 for pkg in skipped_pkgs:
613 bb.debug(1, "Skipping the package %s at do_rootfs because of incompatible license(s): %s" % (pkg, ' '.join(skipped_pkgs[pkg])))
614 d.setVar('_exclude_incompatible-' + pkg, ' '.join(skipped_pkgs[pkg]))
615 for pkg in unskipped_pkgs:
616 bb.debug(1, "Including the package %s" % pkg)
617 else:
618 incompatible_lic = incompatible_license(d, bad_licenses)
619 for pkg in skipped_pkgs:
620 incompatible_lic += skipped_pkgs[pkg]
621 incompatible_lic = sorted(list(set(incompatible_lic)))
622
623 if incompatible_lic:
624 bb.debug(1, "Skipping recipe %s because of incompatible license(s): %s" % (pn, ' '.join(incompatible_lic)))
625 raise bb.parse.SkipRecipe("it has incompatible license(s): %s" % ' '.join(incompatible_lic))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500626
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500627 needsrcrev = False
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500628 srcuri = d.getVar('SRC_URI')
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600629 for uri_string in srcuri.split():
630 uri = bb.fetch.URI(uri_string)
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500631 # Also check downloadfilename as the URL path might not be useful for sniffing
632 path = uri.params.get("downloadfilename", uri.path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500633
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500634 # HTTP/FTP use the wget fetcher
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600635 if uri.scheme in ("http", "https", "ftp"):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500636 d.appendVarFlag('do_fetch', 'depends', ' wget-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500637
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500638 # Svn packages should DEPEND on subversion-native
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600639 if uri.scheme == "svn":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500640 needsrcrev = True
641 d.appendVarFlag('do_fetch', 'depends', ' subversion-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500642
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500643 # Git packages should DEPEND on git-native
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600644 elif uri.scheme in ("git", "gitsm"):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500645 needsrcrev = True
646 d.appendVarFlag('do_fetch', 'depends', ' git-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500647
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500648 # Mercurial packages should DEPEND on mercurial-native
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600649 elif uri.scheme == "hg":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500650 needsrcrev = True
Andrew Geissler82c905d2020-04-13 13:39:40 -0500651 d.appendVar("EXTRANATIVEPATH", ' python3-native ')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500652 d.appendVarFlag('do_fetch', 'depends', ' mercurial-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500653
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600654 # Perforce packages support SRCREV = "${AUTOREV}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600655 elif uri.scheme == "p4":
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600656 needsrcrev = True
657
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500658 # OSC packages should DEPEND on osc-native
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600659 elif uri.scheme == "osc":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500660 d.appendVarFlag('do_fetch', 'depends', ' osc-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500661
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600662 elif uri.scheme == "npm":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500663 d.appendVarFlag('do_fetch', 'depends', ' nodejs-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500664
Andrew Geissler595f6302022-01-24 19:11:47 +0000665 elif uri.scheme == "repo":
666 needsrcrev = True
667 d.appendVarFlag('do_fetch', 'depends', ' repo-native:do_populate_sysroot')
668
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500669 # *.lz4 should DEPEND on lz4-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500670 if path.endswith('.lz4'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500671 d.appendVarFlag('do_unpack', 'depends', ' lz4-native:do_populate_sysroot')
672
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500673 # *.zst should DEPEND on zstd-native for unpacking
674 elif path.endswith('.zst'):
675 d.appendVarFlag('do_unpack', 'depends', ' zstd-native:do_populate_sysroot')
676
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500677 # *.lz should DEPEND on lzip-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500678 elif path.endswith('.lz'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500679 d.appendVarFlag('do_unpack', 'depends', ' lzip-native:do_populate_sysroot')
680
681 # *.xz should DEPEND on xz-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500682 elif path.endswith('.xz') or path.endswith('.txz'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500683 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
684
685 # .zip should DEPEND on unzip-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500686 elif path.endswith('.zip') or path.endswith('.jar'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500687 d.appendVarFlag('do_unpack', 'depends', ' unzip-native:do_populate_sysroot')
688
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800689 # Some rpm files may be compressed internally using xz (for example, rpms from Fedora)
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500690 elif path.endswith('.rpm'):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500691 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500692
Brad Bishop316dfdd2018-06-25 12:45:53 -0400693 # *.deb should DEPEND on xz-native for unpacking
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500694 elif path.endswith('.deb'):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400695 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
696
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500697 if needsrcrev:
698 d.setVar("SRCPV", "${@bb.fetch2.get_srcrev(d)}")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500699
Brad Bishop15ae2502019-06-18 21:44:24 -0400700 # Gather all named SRCREVs to add to the sstate hash calculation
701 # This anonymous python snippet is called multiple times so we
702 # need to be careful to not double up the appends here and cause
703 # the base hash to mismatch the task hash
704 for uri in srcuri.split():
705 parm = bb.fetch.decodeurl(uri)[5]
706 uri_names = parm.get("name", "").split(",")
707 for uri_name in filter(None, uri_names):
708 srcrev_name = "SRCREV_{}".format(uri_name)
709 if srcrev_name not in (d.getVarFlag("do_fetch", "vardeps") or "").split():
710 d.appendVarFlag("do_fetch", "vardeps", " {}".format(srcrev_name))
711
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500712 set_packagetriplet(d)
713
714 # 'multimachine' handling
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500715 mach_arch = d.getVar('MACHINE_ARCH')
716 pkg_arch = d.getVar('PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500717
718 if (pkg_arch == mach_arch):
719 # Already machine specific - nothing further to do
720 return
721
722 #
723 # We always try to scan SRC_URI for urls with machine overrides
724 # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
725 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500726 override = d.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500727 if override != '0':
728 paths = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500729 fpaths = (d.getVar('FILESPATH') or '').split(':')
730 machine = d.getVar('MACHINE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500731 for p in fpaths:
732 if os.path.basename(p) == machine and os.path.isdir(p):
733 paths.append(p)
734
Andrew Geisslereff27472021-10-29 15:35:00 -0500735 if paths:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500736 for s in srcuri.split():
737 if not s.startswith("file://"):
738 continue
739 fetcher = bb.fetch2.Fetch([s], d)
740 local = fetcher.localpath(s)
741 for mp in paths:
742 if local.startswith(mp):
743 #bb.note("overriding PACKAGE_ARCH from %s to %s for %s" % (pkg_arch, mach_arch, pn))
744 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
745 return
746
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500747 packages = d.getVar('PACKAGES').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500748 for pkg in packages:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500749 pkgarch = d.getVar("PACKAGE_ARCH_%s" % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500750
751 # We could look for != PACKAGE_ARCH here but how to choose
752 # if multiple differences are present?
753 # Look through PACKAGE_ARCHS for the priority order?
754 if pkgarch and pkgarch == mach_arch:
755 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500756 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 -0500757}
758
759addtask cleansstate after do_clean
760python do_cleansstate() {
761 sstate_clean_cachefiles(d)
762}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500763addtask cleanall after do_cleansstate
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500764do_cleansstate[nostamp] = "1"
765
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500766python do_cleanall() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500767 src_uri = (d.getVar('SRC_URI') or "").split()
Andrew Geisslereff27472021-10-29 15:35:00 -0500768 if not src_uri:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500769 return
770
771 try:
772 fetcher = bb.fetch2.Fetch(src_uri, d)
773 fetcher.clean()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600774 except bb.fetch2.BBFetchException as e:
775 bb.fatal(str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500776}
777do_cleanall[nostamp] = "1"
778
779
780EXPORT_FUNCTIONS do_fetch do_unpack do_configure do_compile do_install do_package