summaryrefslogtreecommitdiffstats
path: root/meta/classes/base.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/base.bbclass')
-rw-r--r--meta/classes/base.bbclass566
1 files changed, 566 insertions, 0 deletions
diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
new file mode 100644
index 0000000000..ff8c63394f
--- /dev/null
+++ b/meta/classes/base.bbclass
@@ -0,0 +1,566 @@
1BB_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
13OE_IMPORTS += "os sys time oe.path oe.utils oe.data oe.package oe.packagegroup oe.sstatesig oe.lsb oe.cachedpath"
14OE_IMPORTS[type] = "list"
15
16def oe_import(d):
17 import sys
18
19 bbpath = d.getVar("BBPATH", True).split(":")
20 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):
40 adjust = d.getVar('LSB_DISTRO_ADJUST', True)
41 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 "$*"
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):
64 #
65 # Ideally this will check a flag so we will operate properly in
66 # the case where host == build == target, for now we don't work in
67 # that case though.
68 #
69
70 deps = ""
71 # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not
72 # we need that built is the responsibility of the patch function / class, not
73 # the application.
74 if not d.getVar('INHIBIT_DEFAULT_DEPS'):
75 if (d.getVar('HOST_SYS', True) != d.getVar('BUILD_SYS', True)):
76 deps += " virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}compilerlibs virtual/libc "
77 return deps
78
79BASEDEPENDS = "${@base_dep_prepend(d)}"
80
81DEPENDS_prepend="${BASEDEPENDS} "
82
83FILESPATH = "${@base_set_filespath(["${FILE_DIRNAME}/${BP}", "${FILE_DIRNAME}/${BPN}", "${FILE_DIRNAME}/files"], d)}"
84# THISDIR only works properly with imediate expansion as it has to run
85# in the context of the location its used (:=)
86THISDIR = "${@os.path.dirname(d.getVar('FILE', True))}"
87
88def extra_path_elements(d):
89 path = ""
90 elements = (d.getVar('EXTRANATIVEPATH', True) or "").split()
91 for e in elements:
92 path = path + "${STAGING_BINDIR_NATIVE}/" + e + ":"
93 return path
94
95PATH_prepend = "${@extra_path_elements(d)}"
96
97addtask fetch
98do_fetch[dirs] = "${DL_DIR}"
99do_fetch[file-checksums] = "${@bb.fetch.get_checksum_file_list(d)}"
100do_fetch[vardeps] += "SRCREV"
101python base_do_fetch() {
102
103 src_uri = (d.getVar('SRC_URI', True) or "").split()
104 if len(src_uri) == 0:
105 return
106
107 try:
108 fetcher = bb.fetch2.Fetch(src_uri, d)
109 fetcher.download()
110 except bb.fetch2.BBFetchException as e:
111 raise bb.build.FuncFailed(e)
112}
113
114addtask unpack after do_fetch
115do_unpack[dirs] = "${WORKDIR}"
116do_unpack[cleandirs] = "${S}/patches"
117python base_do_unpack() {
118 src_uri = (d.getVar('SRC_URI', True) or "").split()
119 if len(src_uri) == 0:
120 return
121
122 rootdir = d.getVar('WORKDIR', True)
123
124 try:
125 fetcher = bb.fetch2.Fetch(src_uri, d)
126 fetcher.unpack(rootdir)
127 except bb.fetch2.BBFetchException as e:
128 raise bb.build.FuncFailed(e)
129}
130
131def pkgarch_mapping(d):
132 # Compatibility mappings of TUNE_PKGARCH (opt in)
133 if d.getVar("PKGARCHCOMPAT_ARMV7A", True):
134 if d.getVar("TUNE_PKGARCH", True) == "armv7a-vfp-neon":
135 d.setVar("TUNE_PKGARCH", "armv7a")
136
137def get_layers_branch_rev(d):
138 layers = (d.getVar("BBLAYERS", True) or "").split()
139 layers_branch_rev = ["%-17s = \"%s:%s\"" % (os.path.basename(i), \
140 base_get_metadata_git_branch(i, None).strip(), \
141 base_get_metadata_git_revision(i, None)) \
142 for i in layers]
143 i = len(layers_branch_rev)-1
144 p1 = layers_branch_rev[i].find("=")
145 s1 = layers_branch_rev[i][p1:]
146 while i > 0:
147 p2 = layers_branch_rev[i-1].find("=")
148 s2= layers_branch_rev[i-1][p2:]
149 if s1 == s2:
150 layers_branch_rev[i-1] = layers_branch_rev[i-1][0:p2]
151 i -= 1
152 else:
153 i -= 1
154 p1 = layers_branch_rev[i].find("=")
155 s1= layers_branch_rev[i][p1:]
156 return layers_branch_rev
157
158
159BUILDCFG_FUNCS ??= "buildcfg_vars get_layers_branch_rev buildcfg_neededvars"
160BUILDCFG_FUNCS[type] = "list"
161
162def buildcfg_vars(d):
163 statusvars = oe.data.typed_value('BUILDCFG_VARS', d)
164 for var in statusvars:
165 value = d.getVar(var, True)
166 if value is not None:
167 yield '%-17s = "%s"' % (var, value)
168
169def buildcfg_neededvars(d):
170 needed_vars = oe.data.typed_value("BUILDCFG_NEEDEDVARS", d)
171 pesteruser = []
172 for v in needed_vars:
173 val = d.getVar(v, True)
174 if not val or val == 'INVALID':
175 pesteruser.append(v)
176
177 if pesteruser:
178 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))
179
180addhandler base_eventhandler
181base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise"
182python base_eventhandler() {
183 if isinstance(e, bb.event.ConfigParsed):
184 e.data.setVar("NATIVELSBSTRING", lsb_distro_identifier(e.data))
185 e.data.setVar('BB_VERSION', bb.__version__)
186 pkgarch_mapping(e.data)
187 oe.utils.features_backfill("DISTRO_FEATURES", e.data)
188 oe.utils.features_backfill("MACHINE_FEATURES", e.data)
189
190 if isinstance(e, bb.event.BuildStarted):
191 localdata = bb.data.createCopy(e.data)
192 bb.data.update_data(localdata)
193 statuslines = []
194 for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata):
195 g = globals()
196 if func not in g:
197 bb.warn("Build configuration function '%s' does not exist" % func)
198 else:
199 flines = g[func](localdata)
200 if flines:
201 statuslines.extend(flines)
202
203 statusheader = e.data.getVar('BUILDCFG_HEADER', True)
204 bb.plain('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines)))
205
206 # This code is to silence warnings where the SDK variables overwrite the
207 # target ones and we'd see dulpicate key names overwriting each other
208 # for various PREFERRED_PROVIDERS
209 if isinstance(e, bb.event.RecipePreFinalise):
210 if e.data.getVar("TARGET_PREFIX", True) == e.data.getVar("SDK_PREFIX", True):
211 e.data.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}binutils")
212 e.data.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc-initial")
213 e.data.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc")
214 e.data.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}g++")
215 e.data.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}compilerlibs")
216
217}
218
219addtask configure after do_patch
220do_configure[dirs] = "${S} ${B}"
221do_configure[deptask] = "do_populate_sysroot"
222base_do_configure() {
223 :
224}
225
226addtask compile after do_configure
227do_compile[dirs] = "${S} ${B}"
228base_do_compile() {
229 if [ -e Makefile -o -e makefile -o -e GNUmakefile ]; then
230 oe_runmake || die "make failed"
231 else
232 bbnote "nothing to compile"
233 fi
234}
235
236addtask install after do_compile
237do_install[dirs] = "${D} ${S} ${B}"
238# Remove and re-create ${D} so that is it guaranteed to be empty
239do_install[cleandirs] = "${D}"
240
241base_do_install() {
242 :
243}
244
245base_do_package() {
246 :
247}
248
249addtask build after do_populate_sysroot
250do_build[noexec] = "1"
251do_build[recrdeptask] += "do_deploy"
252do_build () {
253 :
254}
255
256def set_packagetriplet(d):
257 archs = []
258 tos = []
259 tvs = []
260
261 archs.append(d.getVar("PACKAGE_ARCHS", True).split())
262 tos.append(d.getVar("TARGET_OS", True))
263 tvs.append(d.getVar("TARGET_VENDOR", True))
264
265 def settriplet(d, varname, archs, tos, tvs):
266 triplets = []
267 for i in range(len(archs)):
268 for arch in archs[i]:
269 triplets.append(arch + tvs[i] + "-" + tos[i])
270 triplets.reverse()
271 d.setVar(varname, " ".join(triplets))
272
273 settriplet(d, "PKGTRIPLETS", archs, tos, tvs)
274
275 variants = d.getVar("MULTILIB_VARIANTS", True) or ""
276 for item in variants.split():
277 localdata = bb.data.createCopy(d)
278 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
279 localdata.setVar("OVERRIDES", overrides)
280 bb.data.update_data(localdata)
281
282 archs.append(localdata.getVar("PACKAGE_ARCHS", True).split())
283 tos.append(localdata.getVar("TARGET_OS", True))
284 tvs.append(localdata.getVar("TARGET_VENDOR", True))
285
286 settriplet(d, "PKGMLTRIPLETS", archs, tos, tvs)
287
288python () {
289 import string, re
290
291 # Handle PACKAGECONFIG
292 #
293 # These take the form:
294 #
295 # PACKAGECONFIG ??= "<default options>"
296 # PACKAGECONFIG[foo] = "--enable-foo,--disable-foo,foo_depends,foo_runtime_depends"
297 pkgconfigflags = d.getVarFlags("PACKAGECONFIG") or {}
298 if pkgconfigflags:
299 pkgconfig = (d.getVar('PACKAGECONFIG', True) or "").split()
300 pn = d.getVar("PN", True)
301 mlprefix = d.getVar("MLPREFIX", True)
302
303 def expandFilter(appends, extension, prefix):
304 appends = bb.utils.explode_deps(d.expand(" ".join(appends)))
305 newappends = []
306 for a in appends:
307 if a.endswith("-native") or ("-cross-" in a):
308 newappends.append(a)
309 elif a.startswith("virtual/"):
310 subs = a.split("/", 1)[1]
311 newappends.append("virtual/" + prefix + subs + extension)
312 else:
313 if a.startswith(prefix):
314 newappends.append(a + extension)
315 else:
316 newappends.append(prefix + a + extension)
317 return newappends
318
319 def appendVar(varname, appends):
320 if not appends:
321 return
322 if varname.find("DEPENDS") != -1:
323 if pn.startswith("nativesdk-"):
324 appends = expandFilter(appends, "", "nativesdk-")
325 if pn.endswith("-native"):
326 appends = expandFilter(appends, "-native", "")
327 if mlprefix:
328 appends = expandFilter(appends, "", mlprefix)
329 varname = d.expand(varname)
330 d.appendVar(varname, " " + " ".join(appends))
331
332 extradeps = []
333 extrardeps = []
334 extraconf = []
335 for flag, flagval in sorted(pkgconfigflags.items()):
336 if flag == "defaultval":
337 continue
338 items = flagval.split(",")
339 num = len(items)
340 if num > 4:
341 bb.error("Only enable,disable,depend,rdepend can be specified!")
342
343 if flag in pkgconfig:
344 if num >= 3 and items[2]:
345 extradeps.append(items[2])
346 if num >= 4 and items[3]:
347 extrardeps.append(items[3])
348 if num >= 1 and items[0]:
349 extraconf.append(items[0])
350 elif num >= 2 and items[1]:
351 extraconf.append(items[1])
352 appendVar('DEPENDS', extradeps)
353 appendVar('RDEPENDS_${PN}', extrardeps)
354 if bb.data.inherits_class('cmake', d):
355 appendVar('EXTRA_OECMAKE', extraconf)
356 else:
357 appendVar('EXTRA_OECONF', extraconf)
358
359 # If PRINC is set, try and increase the PR value by the amount specified
360 # The PR server is now the preferred way to handle PR changes based on
361 # the checksum of the recipe (including bbappend). The PRINC is now
362 # obsolete. Return a warning to the user.
363 princ = d.getVar('PRINC', True)
364 if princ and princ != "0":
365 bb.warn("Use of PRINC %s was detected in the recipe %s (or one of its .bbappends)\nUse of PRINC is deprecated. The PR server should be used to automatically increment the PR. See: https://wiki.yoctoproject.org/wiki/PR_Service." % (princ, d.getVar("FILE", True)))
366 pr = d.getVar('PR', True)
367 pr_prefix = re.search("\D+",pr)
368 prval = re.search("\d+",pr)
369 if pr_prefix is None or prval is None:
370 bb.error("Unable to analyse format of PR variable: %s" % pr)
371 nval = int(prval.group(0)) + int(princ)
372 pr = pr_prefix.group(0) + str(nval) + pr[prval.end():]
373 d.setVar('PR', pr)
374
375 pn = d.getVar('PN', True)
376 license = d.getVar('LICENSE', True)
377 if license == "INVALID":
378 bb.fatal('This recipe does not have the LICENSE field set (%s)' % pn)
379
380 if bb.data.inherits_class('license', d):
381 unmatched_license_flag = check_license_flags(d)
382 if unmatched_license_flag:
383 bb.debug(1, "Skipping %s because it has a restricted license not"
384 " whitelisted in LICENSE_FLAGS_WHITELIST" % pn)
385 raise bb.parse.SkipPackage("because it has a restricted license not"
386 " whitelisted in LICENSE_FLAGS_WHITELIST")
387
388 # If we're building a target package we need to use fakeroot (pseudo)
389 # in order to capture permissions, owners, groups and special files
390 if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
391 d.setVarFlag('do_unpack', 'umask', '022')
392 d.setVarFlag('do_configure', 'umask', '022')
393 d.setVarFlag('do_compile', 'umask', '022')
394 d.appendVarFlag('do_install', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
395 d.setVarFlag('do_install', 'fakeroot', 1)
396 d.setVarFlag('do_install', 'umask', '022')
397 d.appendVarFlag('do_package', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
398 d.setVarFlag('do_package', 'fakeroot', 1)
399 d.setVarFlag('do_package', 'umask', '022')
400 d.setVarFlag('do_package_setscene', 'fakeroot', 1)
401 d.appendVarFlag('do_package_setscene', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
402 d.setVarFlag('do_devshell', 'fakeroot', 1)
403 d.appendVarFlag('do_devshell', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
404 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', 0)
405 if not source_mirror_fetch:
406 need_host = d.getVar('COMPATIBLE_HOST', True)
407 if need_host:
408 import re
409 this_host = d.getVar('HOST_SYS', True)
410 if not re.match(need_host, this_host):
411 raise bb.parse.SkipPackage("incompatible with host %s (not in COMPATIBLE_HOST)" % this_host)
412
413 need_machine = d.getVar('COMPATIBLE_MACHINE', True)
414 if need_machine:
415 import re
416 compat_machines = (d.getVar('MACHINEOVERRIDES', True) or "").split(":")
417 for m in compat_machines:
418 if re.match(need_machine, m):
419 break
420 else:
421 raise bb.parse.SkipPackage("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % d.getVar('MACHINE', True))
422
423
424 bad_licenses = (d.getVar('INCOMPATIBLE_LICENSE', True) or "").split()
425
426 check_license = False if pn.startswith("nativesdk-") else True
427 for t in ["-native", "-cross-${TARGET_ARCH}", "-cross-initial-${TARGET_ARCH}",
428 "-crosssdk-${SDK_ARCH}", "-crosssdk-initial-${SDK_ARCH}",
429 "-cross-canadian-${TRANSLATED_TARGET_ARCH}"]:
430 if pn.endswith(d.expand(t)):
431 check_license = False
432
433 if check_license and bad_licenses:
434 bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses)
435
436 whitelist = []
437 for lic in bad_licenses:
438 for w in ["HOSTTOOLS_WHITELIST_", "LGPLv2_WHITELIST_", "WHITELIST_"]:
439 whitelist.extend((d.getVar(w + lic, True) or "").split())
440 spdx_license = return_spdx(d, lic)
441 if spdx_license:
442 whitelist.extend((d.getVar('HOSTTOOLS_WHITELIST_%s' % spdx_license, True) or "").split())
443 if not pn in whitelist:
444 recipe_license = d.getVar('LICENSE', True)
445 pkgs = d.getVar('PACKAGES', True).split()
446 skipped_pkgs = []
447 unskipped_pkgs = []
448 for pkg in pkgs:
449 if incompatible_license(d, bad_licenses, pkg):
450 skipped_pkgs.append(pkg)
451 else:
452 unskipped_pkgs.append(pkg)
453 all_skipped = skipped_pkgs and not unskipped_pkgs
454 if unskipped_pkgs:
455 for pkg in skipped_pkgs:
456 bb.debug(1, "SKIPPING the package " + pkg + " at do_rootfs because it's " + recipe_license)
457 d.setVar('LICENSE_EXCLUSION-' + pkg, 1)
458 for pkg in unskipped_pkgs:
459 bb.debug(1, "INCLUDING the package " + pkg)
460 elif all_skipped or incompatible_license(d, bad_licenses):
461 bb.debug(1, "SKIPPING recipe %s because it's %s" % (pn, recipe_license))
462 raise bb.parse.SkipPackage("incompatible with license %s" % recipe_license)
463
464 srcuri = d.getVar('SRC_URI', True)
465 # Svn packages should DEPEND on subversion-native
466 if "svn://" in srcuri:
467 d.appendVarFlag('do_fetch', 'depends', ' subversion-native:do_populate_sysroot')
468
469 # Git packages should DEPEND on git-native
470 if "git://" in srcuri:
471 d.appendVarFlag('do_fetch', 'depends', ' git-native:do_populate_sysroot')
472
473 # Mercurial packages should DEPEND on mercurial-native
474 elif "hg://" in srcuri:
475 d.appendVarFlag('do_fetch', 'depends', ' mercurial-native:do_populate_sysroot')
476
477 # OSC packages should DEPEND on osc-native
478 elif "osc://" in srcuri:
479 d.appendVarFlag('do_fetch', 'depends', ' osc-native:do_populate_sysroot')
480
481 # *.lz4 should depends on lz4-native for unpacking
482 # Not endswith because of "*.patch.lz4;patch=1". Need bb.fetch.decodeurl in future
483 if '.lz4' in srcuri:
484 d.appendVarFlag('do_unpack', 'depends', ' lz4-native:do_populate_sysroot')
485
486 # *.xz should depends on xz-native for unpacking
487 # Not endswith because of "*.patch.xz;patch=1". Need bb.fetch.decodeurl in future
488 if '.xz' in srcuri:
489 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
490
491 # unzip-native should already be staged before unpacking ZIP recipes
492 if ".zip" in srcuri:
493 d.appendVarFlag('do_unpack', 'depends', ' unzip-native:do_populate_sysroot')
494
495 # file is needed by rpm2cpio.sh
496 if ".src.rpm" in srcuri:
497 d.appendVarFlag('do_unpack', 'depends', ' file-native:do_populate_sysroot')
498
499 set_packagetriplet(d)
500
501 # 'multimachine' handling
502 mach_arch = d.getVar('MACHINE_ARCH', True)
503 pkg_arch = d.getVar('PACKAGE_ARCH', True)
504
505 if (pkg_arch == mach_arch):
506 # Already machine specific - nothing further to do
507 return
508
509 #
510 # We always try to scan SRC_URI for urls with machine overrides
511 # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
512 #
513 override = d.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH', True)
514 if override != '0':
515 paths = []
516 fpaths = (d.getVar('FILESPATH', True) or '').split(':')
517 machine = d.getVar('MACHINE', True)
518 for p in fpaths:
519 if os.path.basename(p) == machine and os.path.isdir(p):
520 paths.append(p)
521
522 if len(paths) != 0:
523 for s in srcuri.split():
524 if not s.startswith("file://"):
525 continue
526 fetcher = bb.fetch2.Fetch([s], d)
527 local = fetcher.localpath(s)
528 for mp in paths:
529 if local.startswith(mp):
530 #bb.note("overriding PACKAGE_ARCH from %s to %s for %s" % (pkg_arch, mach_arch, pn))
531 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
532 return
533
534 packages = d.getVar('PACKAGES', True).split()
535 for pkg in packages:
536 pkgarch = d.getVar("PACKAGE_ARCH_%s" % pkg, True)
537
538 # We could look for != PACKAGE_ARCH here but how to choose
539 # if multiple differences are present?
540 # Look through PACKAGE_ARCHS for the priority order?
541 if pkgarch and pkgarch == mach_arch:
542 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
543 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", True))
544}
545
546addtask cleansstate after do_clean
547python do_cleansstate() {
548 sstate_clean_cachefiles(d)
549}
550
551addtask cleanall after do_cleansstate
552python do_cleanall() {
553 src_uri = (d.getVar('SRC_URI', True) or "").split()
554 if len(src_uri) == 0:
555 return
556
557 try:
558 fetcher = bb.fetch2.Fetch(src_uri, d)
559 fetcher.clean()
560 except bb.fetch2.BBFetchException, e:
561 raise bb.build.FuncFailed(e)
562}
563do_cleanall[nostamp] = "1"
564
565
566EXPORT_FUNCTIONS do_fetch do_unpack do_configure do_compile do_install do_package