blob: 1636c6ef93832022ba313d82e34b7c6b4762b057 [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 Bishop6e60e8b2018-02-01 10:27:11 -050013OE_IMPORTS += "os sys time oe.path oe.utils oe.types oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath oe.license"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014OE_IMPORTS[type] = "list"
15
16def oe_import(d):
17 import sys
18
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019 bbpath = d.getVar("BBPATH").split(":")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020 sys.path[0:0] = [os.path.join(dir, "lib") for dir in bbpath]
21
22 def inject(name, value):
23 """Make a python object accessible from the metadata"""
24 if hasattr(bb.utils, "_context"):
25 bb.utils._context[name] = value
26 else:
27 __builtins__[name] = value
28
29 import oe.data
30 for toimport in oe.data.typed_value("OE_IMPORTS", d):
31 imported = __import__(toimport)
32 inject(toimport.split(".", 1)[0], imported)
33
34 return ""
35
36# We need the oe module name space early (before INHERITs get added)
37OE_IMPORTED := "${@oe_import(d)}"
38
39def lsb_distro_identifier(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 adjust = d.getVar('LSB_DISTRO_ADJUST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041 adjust_func = None
42 if adjust:
43 try:
44 adjust_func = globals()[adjust]
45 except KeyError:
46 pass
47 return oe.lsb.distro_identifier(adjust_func)
48
49die() {
50 bbfatal_log "$*"
51}
52
53oe_runmake_call() {
54 bbnote ${MAKE} ${EXTRA_OEMAKE} "$@"
55 ${MAKE} ${EXTRA_OEMAKE} "$@"
56}
57
58oe_runmake() {
59 oe_runmake_call "$@" || die "oe_runmake failed"
60}
61
62
63def base_dep_prepend(d):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050064 if d.getVar('INHIBIT_DEFAULT_DEPS', False):
65 return ""
66 return "${BASE_DEFAULT_DEPS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067
Brad Bishopd7bf8c12018-02-25 22:55:05 -050068BASE_DEFAULT_DEPS = "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}compilerlibs virtual/libc"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070BASEDEPENDS = ""
71BASEDEPENDS_class-target = "${@base_dep_prepend(d)}"
72BASEDEPENDS_class-nativesdk = "${@base_dep_prepend(d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
74DEPENDS_prepend="${BASEDEPENDS} "
75
76FILESPATH = "${@base_set_filespath(["${FILE_DIRNAME}/${BP}", "${FILE_DIRNAME}/${BPN}", "${FILE_DIRNAME}/files"], d)}"
77# THISDIR only works properly with imediate expansion as it has to run
78# in the context of the location its used (:=)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050079THISDIR = "${@os.path.dirname(d.getVar('FILE'))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080
81def extra_path_elements(d):
82 path = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050083 elements = (d.getVar('EXTRANATIVEPATH') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 for e in elements:
85 path = path + "${STAGING_BINDIR_NATIVE}/" + e + ":"
86 return path
87
88PATH_prepend = "${@extra_path_elements(d)}"
89
90def get_lic_checksum_file_list(d):
91 filelist = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -050092 lic_files = d.getVar("LIC_FILES_CHKSUM") or ''
93 tmpdir = d.getVar("TMPDIR")
94 s = d.getVar("S")
95 b = d.getVar("B")
96 workdir = d.getVar("WORKDIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097
98 urls = lic_files.split()
99 for url in urls:
100 # We only care about items that are absolute paths since
101 # any others should be covered by SRC_URI.
102 try:
Brad Bishop220d5532018-08-14 00:59:39 +0100103 (method, host, path, user, pswd, parm) = bb.fetch.decodeurl(url)
104 if method != "file" or not path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600105 raise bb.fetch.MalformedUrl(url)
106
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 if path[0] == '/':
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500108 if path.startswith((tmpdir, s, b, workdir)):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 continue
110 filelist.append(path + ":" + str(os.path.exists(path)))
111 except bb.fetch.MalformedUrl:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 bb.fatal(d.getVar('PN') + ": LIC_FILES_CHKSUM contains an invalid URL: " + url)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 return " ".join(filelist)
114
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500115def setup_hosttools_dir(dest, toolsvar, d, fatal=True):
116 tools = d.getVar(toolsvar).split()
117 origbbenv = d.getVar("BB_ORIGENV", False)
118 path = origbbenv.getVar("PATH")
119 bb.utils.mkdirhier(dest)
120 notfound = []
121 for tool in tools:
122 desttool = os.path.join(dest, tool)
123 if not os.path.exists(desttool):
124 srctool = bb.utils.which(path, tool, executable=True)
Brad Bishop19323692019-04-05 15:28:33 -0400125 # gcc/g++ may link to ccache on some hosts, e.g.,
126 # /usr/local/bin/ccache/gcc -> /usr/bin/ccache, then which(gcc)
127 # would return /usr/local/bin/ccache/gcc, but what we need is
128 # /usr/bin/gcc, this code can check and fix that.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500129 if "ccache" in srctool:
130 srctool = bb.utils.which(path, tool, executable=True, direction=1)
131 if srctool:
132 os.symlink(srctool, desttool)
133 else:
134 notfound.append(tool)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800135 # Force "python" -> "python2"
136 desttool = os.path.join(dest, "python")
137 if not os.path.exists(desttool):
138 srctool = "python2"
139 os.symlink(srctool, desttool)
140
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500141 if notfound and fatal:
142 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))
143
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144addtask fetch
145do_fetch[dirs] = "${DL_DIR}"
146do_fetch[file-checksums] = "${@bb.fetch.get_checksum_file_list(d)}"
147do_fetch[file-checksums] += " ${@get_lic_checksum_file_list(d)}"
148do_fetch[vardeps] += "SRCREV"
149python base_do_fetch() {
150
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500151 src_uri = (d.getVar('SRC_URI') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152 if len(src_uri) == 0:
153 return
154
155 try:
156 fetcher = bb.fetch2.Fetch(src_uri, d)
157 fetcher.download()
158 except bb.fetch2.BBFetchException as e:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600159 bb.fatal(str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160}
161
162addtask unpack after do_fetch
163do_unpack[dirs] = "${WORKDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600164
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800165do_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 -0400166
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167python base_do_unpack() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500168 src_uri = (d.getVar('SRC_URI') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169 if len(src_uri) == 0:
170 return
171
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172 try:
173 fetcher = bb.fetch2.Fetch(src_uri, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500174 fetcher.unpack(d.getVar('WORKDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175 except bb.fetch2.BBFetchException as e:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600176 bb.fatal(str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500177}
178
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179def get_layers_branch_rev(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500180 layers = (d.getVar("BBLAYERS") or "").split()
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500181 layers_branch_rev = ["%-20s = \"%s:%s\"" % (os.path.basename(i), \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182 base_get_metadata_git_branch(i, None).strip(), \
183 base_get_metadata_git_revision(i, None)) \
184 for i in layers]
185 i = len(layers_branch_rev)-1
186 p1 = layers_branch_rev[i].find("=")
187 s1 = layers_branch_rev[i][p1:]
188 while i > 0:
189 p2 = layers_branch_rev[i-1].find("=")
190 s2= layers_branch_rev[i-1][p2:]
191 if s1 == s2:
192 layers_branch_rev[i-1] = layers_branch_rev[i-1][0:p2]
193 i -= 1
194 else:
195 i -= 1
196 p1 = layers_branch_rev[i].find("=")
197 s1= layers_branch_rev[i][p1:]
198 return layers_branch_rev
199
200
201BUILDCFG_FUNCS ??= "buildcfg_vars get_layers_branch_rev buildcfg_neededvars"
202BUILDCFG_FUNCS[type] = "list"
203
204def buildcfg_vars(d):
205 statusvars = oe.data.typed_value('BUILDCFG_VARS', d)
206 for var in statusvars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500207 value = d.getVar(var)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500208 if value is not None:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500209 yield '%-20s = "%s"' % (var, value)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210
211def buildcfg_neededvars(d):
212 needed_vars = oe.data.typed_value("BUILDCFG_NEEDEDVARS", d)
213 pesteruser = []
214 for v in needed_vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500215 val = d.getVar(v)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500216 if not val or val == 'INVALID':
217 pesteruser.append(v)
218
219 if pesteruser:
220 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))
221
222addhandler base_eventhandler
Brad Bishop19323692019-04-05 15:28:33 -0400223base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.MultiConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise bb.event.RecipeParsed"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224python base_eventhandler() {
225 import bb.runqueue
226
227 if isinstance(e, bb.event.ConfigParsed):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400228 if not d.getVar("NATIVELSBSTRING", False):
229 d.setVar("NATIVELSBSTRING", lsb_distro_identifier(d))
230 d.setVar('BB_VERSION', bb.__version__)
Brad Bishop19323692019-04-05 15:28:33 -0400231
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'))):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500237 # 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)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500241 if isinstance(e, bb.event.MultiConfigParsed):
242 # We need to expand SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS in each of the multiconfig data stores
243 # own contexts so the variables get expanded correctly for that arch, then inject back into
244 # the main data store.
245 deps = []
246 for config in e.mcdata:
247 deps.append(e.mcdata[config].getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS"))
248 deps = " ".join(deps)
249 e.mcdata[''].setVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", deps)
250
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251 if isinstance(e, bb.event.BuildStarted):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400252 localdata = bb.data.createCopy(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253 statuslines = []
254 for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata):
255 g = globals()
256 if func not in g:
257 bb.warn("Build configuration function '%s' does not exist" % func)
258 else:
259 flines = g[func](localdata)
260 if flines:
261 statuslines.extend(flines)
262
Brad Bishop316dfdd2018-06-25 12:45:53 -0400263 statusheader = d.getVar('BUILDCFG_HEADER')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500264 if statusheader:
265 bb.plain('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266
267 # This code is to silence warnings where the SDK variables overwrite the
268 # target ones and we'd see dulpicate key names overwriting each other
269 # for various PREFERRED_PROVIDERS
270 if isinstance(e, bb.event.RecipePreFinalise):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400271 if d.getVar("TARGET_PREFIX") == d.getVar("SDK_PREFIX"):
272 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}binutils")
Brad Bishop316dfdd2018-06-25 12:45:53 -0400273 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc")
274 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}g++")
275 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}compilerlibs")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500276
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500277 if isinstance(e, bb.event.RecipeParsed):
278 #
279 # If we have multiple providers of virtual/X and a PREFERRED_PROVIDER_virtual/X is set
280 # skip parsing for all the other providers which will mean they get uninstalled from the
281 # sysroot since they're now "unreachable". This makes switching virtual/kernel work in
282 # particular.
283 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500284 pn = d.getVar('PN')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500285 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False)
286 if not source_mirror_fetch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500287 provs = (d.getVar("PROVIDES") or "").split()
288 multiwhitelist = (d.getVar("MULTI_PROVIDER_WHITELIST") or "").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500289 for p in provs:
290 if p.startswith("virtual/") and p not in multiwhitelist:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500291 profprov = d.getVar("PREFERRED_PROVIDER_" + p)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500292 if profprov and pn != profprov:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400293 raise bb.parse.SkipRecipe("PREFERRED_PROVIDER_%s set to %s, not %s" % (p, profprov, pn))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500294}
295
296CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
297CLEANBROKEN = "0"
298
299addtask configure after do_patch
300do_configure[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500301base_do_configure() {
302 if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
303 if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
304 cd ${B}
305 if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
306 oe_runmake clean
307 fi
Brad Bishopc4ea0752018-11-15 14:30:15 -0800308 # -ignore_readdir_race does not work correctly with -delete;
309 # use xargs to avoid spurious build failures
310 find ${B} -ignore_readdir_race -name \*.la -type f -print0 | xargs -0 rm -f
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500311 fi
312 fi
313 if [ -n "${CONFIGURESTAMPFILE}" ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500314 mkdir -p `dirname ${CONFIGURESTAMPFILE}`
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500315 echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
316 fi
317}
318
319addtask compile after do_configure
320do_compile[dirs] = "${B}"
321base_do_compile() {
322 if [ -e Makefile -o -e makefile -o -e GNUmakefile ]; then
323 oe_runmake || die "make failed"
324 else
325 bbnote "nothing to compile"
326 fi
327}
328
329addtask install after do_compile
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600330do_install[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331# Remove and re-create ${D} so that is it guaranteed to be empty
332do_install[cleandirs] = "${D}"
333
334base_do_install() {
335 :
336}
337
338base_do_package() {
339 :
340}
341
342addtask build after do_populate_sysroot
343do_build[noexec] = "1"
344do_build[recrdeptask] += "do_deploy"
345do_build () {
346 :
347}
348
349def set_packagetriplet(d):
350 archs = []
351 tos = []
352 tvs = []
353
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500354 archs.append(d.getVar("PACKAGE_ARCHS").split())
355 tos.append(d.getVar("TARGET_OS"))
356 tvs.append(d.getVar("TARGET_VENDOR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357
358 def settriplet(d, varname, archs, tos, tvs):
359 triplets = []
360 for i in range(len(archs)):
361 for arch in archs[i]:
362 triplets.append(arch + tvs[i] + "-" + tos[i])
363 triplets.reverse()
364 d.setVar(varname, " ".join(triplets))
365
366 settriplet(d, "PKGTRIPLETS", archs, tos, tvs)
367
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500368 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500369 for item in variants.split():
370 localdata = bb.data.createCopy(d)
371 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
372 localdata.setVar("OVERRIDES", overrides)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500373
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500374 archs.append(localdata.getVar("PACKAGE_ARCHS").split())
375 tos.append(localdata.getVar("TARGET_OS"))
376 tvs.append(localdata.getVar("TARGET_VENDOR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500377
378 settriplet(d, "PKGMLTRIPLETS", archs, tos, tvs)
379
380python () {
381 import string, re
382
Brad Bishop316dfdd2018-06-25 12:45:53 -0400383 # Handle backfilling
384 oe.utils.features_backfill("DISTRO_FEATURES", d)
385 oe.utils.features_backfill("MACHINE_FEATURES", d)
386
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500387 # Handle PACKAGECONFIG
388 #
389 # These take the form:
390 #
391 # PACKAGECONFIG ??= "<default options>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500392 # PACKAGECONFIG[foo] = "--enable-foo,--disable-foo,foo_depends,foo_runtime_depends,foo_runtime_recommends"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500393 pkgconfigflags = d.getVarFlags("PACKAGECONFIG") or {}
394 if pkgconfigflags:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500395 pkgconfig = (d.getVar('PACKAGECONFIG') or "").split()
396 pn = d.getVar("PN")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500397
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500398 mlprefix = d.getVar("MLPREFIX")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500399
400 def expandFilter(appends, extension, prefix):
401 appends = bb.utils.explode_deps(d.expand(" ".join(appends)))
402 newappends = []
403 for a in appends:
404 if a.endswith("-native") or ("-cross-" in a):
405 newappends.append(a)
406 elif a.startswith("virtual/"):
407 subs = a.split("/", 1)[1]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500408 if subs.startswith(prefix):
409 newappends.append(a + extension)
410 else:
411 newappends.append("virtual/" + prefix + subs + extension)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500412 else:
413 if a.startswith(prefix):
414 newappends.append(a + extension)
415 else:
416 newappends.append(prefix + a + extension)
417 return newappends
418
419 def appendVar(varname, appends):
420 if not appends:
421 return
422 if varname.find("DEPENDS") != -1:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500423 if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d) :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500424 appends = expandFilter(appends, "", "nativesdk-")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500425 elif bb.data.inherits_class('native', d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500426 appends = expandFilter(appends, "-native", "")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500427 elif mlprefix:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500428 appends = expandFilter(appends, "", mlprefix)
429 varname = d.expand(varname)
430 d.appendVar(varname, " " + " ".join(appends))
431
432 extradeps = []
433 extrardeps = []
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500434 extrarrecs = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500435 extraconf = []
436 for flag, flagval in sorted(pkgconfigflags.items()):
437 items = flagval.split(",")
438 num = len(items)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500439 if num > 5:
440 bb.error("%s: PACKAGECONFIG[%s] Only enable,disable,depend,rdepend,rrecommend can be specified!"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500441 % (d.getVar('PN'), flag))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500442
443 if flag in pkgconfig:
444 if num >= 3 and items[2]:
445 extradeps.append(items[2])
446 if num >= 4 and items[3]:
447 extrardeps.append(items[3])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500448 if num >= 5 and items[4]:
449 extrarrecs.append(items[4])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500450 if num >= 1 and items[0]:
451 extraconf.append(items[0])
452 elif num >= 2 and items[1]:
453 extraconf.append(items[1])
454 appendVar('DEPENDS', extradeps)
455 appendVar('RDEPENDS_${PN}', extrardeps)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500456 appendVar('RRECOMMENDS_${PN}', extrarrecs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500457 appendVar('PACKAGECONFIG_CONFARGS', extraconf)
458
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500459 pn = d.getVar('PN')
460 license = d.getVar('LICENSE')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400461 if license == "INVALID" and pn != "defaultpkgname":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500462 bb.fatal('This recipe does not have the LICENSE field set (%s)' % pn)
463
464 if bb.data.inherits_class('license', d):
465 check_license_format(d)
Brad Bishop19323692019-04-05 15:28:33 -0400466 unmatched_license_flags = check_license_flags(d)
467 if unmatched_license_flags:
468 if len(unmatched_license_flags) == 1:
469 message = "because it has a restricted license '{0}'. Which is not whitelisted in LICENSE_FLAGS_WHITELIST".format(unmatched_license_flags[0])
470 else:
471 message = "because it has restricted licenses {0}. Which are not whitelisted in LICENSE_FLAGS_WHITELIST".format(
472 ", ".join("'{0}'".format(f) for f in unmatched_license_flags))
473 bb.debug(1, "Skipping %s %s" % (pn, message))
474 raise bb.parse.SkipRecipe(message)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500475
476 # If we're building a target package we need to use fakeroot (pseudo)
477 # in order to capture permissions, owners, groups and special files
478 if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
479 d.setVarFlag('do_unpack', 'umask', '022')
480 d.setVarFlag('do_configure', 'umask', '022')
481 d.setVarFlag('do_compile', 'umask', '022')
482 d.appendVarFlag('do_install', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500483 d.setVarFlag('do_install', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500484 d.setVarFlag('do_install', 'umask', '022')
485 d.appendVarFlag('do_package', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500486 d.setVarFlag('do_package', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500487 d.setVarFlag('do_package', 'umask', '022')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500488 d.setVarFlag('do_package_setscene', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500489 d.appendVarFlag('do_package_setscene', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500490 d.setVarFlag('do_devshell', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500491 d.appendVarFlag('do_devshell', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500492
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500493 need_machine = d.getVar('COMPATIBLE_MACHINE')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500494 if need_machine:
495 import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500496 compat_machines = (d.getVar('MACHINEOVERRIDES') or "").split(":")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500497 for m in compat_machines:
498 if re.match(need_machine, m):
499 break
500 else:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400501 raise bb.parse.SkipRecipe("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % d.getVar('MACHINE'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500502
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600503 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500504 if not source_mirror_fetch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500505 need_host = d.getVar('COMPATIBLE_HOST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500506 if need_host:
507 import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500508 this_host = d.getVar('HOST_SYS')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500509 if not re.match(need_host, this_host):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400510 raise bb.parse.SkipRecipe("incompatible with host %s (not in COMPATIBLE_HOST)" % this_host)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500511
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500512 bad_licenses = (d.getVar('INCOMPATIBLE_LICENSE') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500513
514 check_license = False if pn.startswith("nativesdk-") else True
515 for t in ["-native", "-cross-${TARGET_ARCH}", "-cross-initial-${TARGET_ARCH}",
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600516 "-crosssdk-${SDK_SYS}", "-crosssdk-initial-${SDK_SYS}",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500517 "-cross-canadian-${TRANSLATED_TARGET_ARCH}"]:
518 if pn.endswith(d.expand(t)):
519 check_license = False
520 if pn.startswith("gcc-source-"):
521 check_license = False
522
523 if check_license and bad_licenses:
524 bad_licenses = expand_wildcard_licenses(d, bad_licenses)
525
526 whitelist = []
527 incompatwl = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500528 for lic in bad_licenses:
529 spdx_license = return_spdx(d, lic)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800530 whitelist.extend((d.getVar("WHITELIST_" + lic) or "").split())
531 if spdx_license:
532 whitelist.extend((d.getVar("WHITELIST_" + spdx_license) or "").split())
533 '''
534 We need to track what we are whitelisting and why. If pn is
535 incompatible we need to be able to note that the image that
536 is created may infact contain incompatible licenses despite
537 INCOMPATIBLE_LICENSE being set.
538 '''
539 incompatwl.extend((d.getVar("WHITELIST_" + lic) or "").split())
540 if spdx_license:
541 incompatwl.extend((d.getVar("WHITELIST_" + spdx_license) or "").split())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500542
543 if not pn in whitelist:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500544 pkgs = d.getVar('PACKAGES').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500545 skipped_pkgs = []
546 unskipped_pkgs = []
547 for pkg in pkgs:
548 if incompatible_license(d, bad_licenses, pkg):
549 skipped_pkgs.append(pkg)
550 else:
551 unskipped_pkgs.append(pkg)
552 all_skipped = skipped_pkgs and not unskipped_pkgs
553 if unskipped_pkgs:
554 for pkg in skipped_pkgs:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500555 bb.debug(1, "SKIPPING the package " + pkg + " at do_rootfs because it's " + license)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500556 mlprefix = d.getVar('MLPREFIX')
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500557 d.setVar('LICENSE_EXCLUSION-' + mlprefix + pkg, 1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500558 for pkg in unskipped_pkgs:
559 bb.debug(1, "INCLUDING the package " + pkg)
560 elif all_skipped or incompatible_license(d, bad_licenses):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500561 bb.debug(1, "SKIPPING recipe %s because it's %s" % (pn, license))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400562 raise bb.parse.SkipRecipe("it has an incompatible license: %s" % license)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500563 elif pn in whitelist:
564 if pn in incompatwl:
565 bb.note("INCLUDING " + pn + " as buildable despite INCOMPATIBLE_LICENSE because it has been whitelisted")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500566
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600567 # Try to verify per-package (LICENSE_<pkg>) values. LICENSE should be a
568 # superset of all per-package licenses. We do not do advanced (pattern)
569 # matching of license expressions - just check that all license strings
570 # in LICENSE_<pkg> are found in LICENSE.
571 license_set = oe.license.list_licenses(license)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500572 for pkg in d.getVar('PACKAGES').split():
573 pkg_license = d.getVar('LICENSE_' + pkg)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600574 if pkg_license:
575 unlisted = oe.license.list_licenses(pkg_license) - license_set
576 if unlisted:
577 bb.warn("LICENSE_%s includes licenses (%s) that are not "
578 "listed in LICENSE" % (pkg, ' '.join(unlisted)))
579
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500580 needsrcrev = False
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500581 srcuri = d.getVar('SRC_URI')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500582 for uri in srcuri.split():
583 (scheme, _ , path) = bb.fetch.decodeurl(uri)[:3]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500584
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500585 # HTTP/FTP use the wget fetcher
586 if scheme in ("http", "https", "ftp"):
587 d.appendVarFlag('do_fetch', 'depends', ' wget-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500588
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500589 # Svn packages should DEPEND on subversion-native
590 if scheme == "svn":
591 needsrcrev = True
592 d.appendVarFlag('do_fetch', 'depends', ' subversion-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500593
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500594 # Git packages should DEPEND on git-native
595 elif scheme in ("git", "gitsm"):
596 needsrcrev = True
597 d.appendVarFlag('do_fetch', 'depends', ' git-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500598
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500599 # Mercurial packages should DEPEND on mercurial-native
600 elif scheme == "hg":
601 needsrcrev = True
602 d.appendVarFlag('do_fetch', 'depends', ' mercurial-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500603
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600604 # Perforce packages support SRCREV = "${AUTOREV}"
605 elif scheme == "p4":
606 needsrcrev = True
607
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500608 # OSC packages should DEPEND on osc-native
609 elif scheme == "osc":
610 d.appendVarFlag('do_fetch', 'depends', ' osc-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500611
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500612 elif scheme == "npm":
613 d.appendVarFlag('do_fetch', 'depends', ' nodejs-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500614
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500615 # *.lz4 should DEPEND on lz4-native for unpacking
616 if path.endswith('.lz4'):
617 d.appendVarFlag('do_unpack', 'depends', ' lz4-native:do_populate_sysroot')
618
619 # *.lz should DEPEND on lzip-native for unpacking
620 elif path.endswith('.lz'):
621 d.appendVarFlag('do_unpack', 'depends', ' lzip-native:do_populate_sysroot')
622
623 # *.xz should DEPEND on xz-native for unpacking
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500624 elif path.endswith('.xz') or path.endswith('.txz'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500625 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
626
627 # .zip should DEPEND on unzip-native for unpacking
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500628 elif path.endswith('.zip') or path.endswith('.jar'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500629 d.appendVarFlag('do_unpack', 'depends', ' unzip-native:do_populate_sysroot')
630
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800631 # Some rpm files may be compressed internally using xz (for example, rpms from Fedora)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500632 elif path.endswith('.rpm'):
633 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500634
Brad Bishop316dfdd2018-06-25 12:45:53 -0400635 # *.deb should DEPEND on xz-native for unpacking
636 elif path.endswith('.deb'):
637 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
638
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500639 if needsrcrev:
640 d.setVar("SRCPV", "${@bb.fetch2.get_srcrev(d)}")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500641
642 set_packagetriplet(d)
643
644 # 'multimachine' handling
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500645 mach_arch = d.getVar('MACHINE_ARCH')
646 pkg_arch = d.getVar('PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500647
648 if (pkg_arch == mach_arch):
649 # Already machine specific - nothing further to do
650 return
651
652 #
653 # We always try to scan SRC_URI for urls with machine overrides
654 # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
655 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500656 override = d.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500657 if override != '0':
658 paths = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500659 fpaths = (d.getVar('FILESPATH') or '').split(':')
660 machine = d.getVar('MACHINE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500661 for p in fpaths:
662 if os.path.basename(p) == machine and os.path.isdir(p):
663 paths.append(p)
664
665 if len(paths) != 0:
666 for s in srcuri.split():
667 if not s.startswith("file://"):
668 continue
669 fetcher = bb.fetch2.Fetch([s], d)
670 local = fetcher.localpath(s)
671 for mp in paths:
672 if local.startswith(mp):
673 #bb.note("overriding PACKAGE_ARCH from %s to %s for %s" % (pkg_arch, mach_arch, pn))
674 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
675 return
676
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500677 packages = d.getVar('PACKAGES').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500678 for pkg in packages:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500679 pkgarch = d.getVar("PACKAGE_ARCH_%s" % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500680
681 # We could look for != PACKAGE_ARCH here but how to choose
682 # if multiple differences are present?
683 # Look through PACKAGE_ARCHS for the priority order?
684 if pkgarch and pkgarch == mach_arch:
685 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500686 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 -0500687}
688
689addtask cleansstate after do_clean
690python do_cleansstate() {
691 sstate_clean_cachefiles(d)
692}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693addtask cleanall after do_cleansstate
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500694do_cleansstate[nostamp] = "1"
695
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500696python do_cleanall() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500697 src_uri = (d.getVar('SRC_URI') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500698 if len(src_uri) == 0:
699 return
700
701 try:
702 fetcher = bb.fetch2.Fetch(src_uri, d)
703 fetcher.clean()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600704 except bb.fetch2.BBFetchException as e:
705 bb.fatal(str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500706}
707do_cleanall[nostamp] = "1"
708
709
710EXPORT_FUNCTIONS do_fetch do_unpack do_configure do_compile do_install do_package