blob: 2a6a6cb6d7c25697c1f0cac0109f0642153b4267 [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)
125 if "ccache" in srctool:
126 srctool = bb.utils.which(path, tool, executable=True, direction=1)
127 if srctool:
128 os.symlink(srctool, desttool)
129 else:
130 notfound.append(tool)
131 if notfound and fatal:
132 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))
133
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134addtask fetch
135do_fetch[dirs] = "${DL_DIR}"
136do_fetch[file-checksums] = "${@bb.fetch.get_checksum_file_list(d)}"
137do_fetch[file-checksums] += " ${@get_lic_checksum_file_list(d)}"
138do_fetch[vardeps] += "SRCREV"
139python base_do_fetch() {
140
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500141 src_uri = (d.getVar('SRC_URI') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500142 if len(src_uri) == 0:
143 return
144
145 try:
146 fetcher = bb.fetch2.Fetch(src_uri, d)
147 fetcher.download()
148 except bb.fetch2.BBFetchException as e:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600149 bb.fatal(str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150}
151
152addtask unpack after do_fetch
153do_unpack[dirs] = "${WORKDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600154
Brad Bishop316dfdd2018-06-25 12:45:53 -0400155do_unpack[cleandirs] = "${@d.getVar('S') if d.getVar('S') != d.getVar('WORKDIR') else os.path.join('${S}', 'patches')}"
156
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157python base_do_unpack() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500158 src_uri = (d.getVar('SRC_URI') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159 if len(src_uri) == 0:
160 return
161
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 try:
163 fetcher = bb.fetch2.Fetch(src_uri, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500164 fetcher.unpack(d.getVar('WORKDIR'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165 except bb.fetch2.BBFetchException as e:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600166 bb.fatal(str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167}
168
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169def get_layers_branch_rev(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500170 layers = (d.getVar("BBLAYERS") or "").split()
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500171 layers_branch_rev = ["%-20s = \"%s:%s\"" % (os.path.basename(i), \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172 base_get_metadata_git_branch(i, None).strip(), \
173 base_get_metadata_git_revision(i, None)) \
174 for i in layers]
175 i = len(layers_branch_rev)-1
176 p1 = layers_branch_rev[i].find("=")
177 s1 = layers_branch_rev[i][p1:]
178 while i > 0:
179 p2 = layers_branch_rev[i-1].find("=")
180 s2= layers_branch_rev[i-1][p2:]
181 if s1 == s2:
182 layers_branch_rev[i-1] = layers_branch_rev[i-1][0:p2]
183 i -= 1
184 else:
185 i -= 1
186 p1 = layers_branch_rev[i].find("=")
187 s1= layers_branch_rev[i][p1:]
188 return layers_branch_rev
189
190
191BUILDCFG_FUNCS ??= "buildcfg_vars get_layers_branch_rev buildcfg_neededvars"
192BUILDCFG_FUNCS[type] = "list"
193
194def buildcfg_vars(d):
195 statusvars = oe.data.typed_value('BUILDCFG_VARS', d)
196 for var in statusvars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500197 value = d.getVar(var)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198 if value is not None:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500199 yield '%-20s = "%s"' % (var, value)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200
201def buildcfg_neededvars(d):
202 needed_vars = oe.data.typed_value("BUILDCFG_NEEDEDVARS", d)
203 pesteruser = []
204 for v in needed_vars:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500205 val = d.getVar(v)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 if not val or val == 'INVALID':
207 pesteruser.append(v)
208
209 if pesteruser:
210 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))
211
212addhandler base_eventhandler
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500213base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.MultiConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise bb.runqueue.sceneQueueComplete bb.event.RecipeParsed"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500214python base_eventhandler() {
215 import bb.runqueue
216
217 if isinstance(e, bb.event.ConfigParsed):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400218 if not d.getVar("NATIVELSBSTRING", False):
219 d.setVar("NATIVELSBSTRING", lsb_distro_identifier(d))
220 d.setVar('BB_VERSION', bb.__version__)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500221 # Works with the line in layer.conf which changes PATH to point here
222 setup_hosttools_dir(d.getVar('HOSTTOOLS_DIR'), 'HOSTTOOLS', d)
223 setup_hosttools_dir(d.getVar('HOSTTOOLS_DIR'), 'HOSTTOOLS_NONFATAL', d, fatal=False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500225 if isinstance(e, bb.event.MultiConfigParsed):
226 # We need to expand SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS in each of the multiconfig data stores
227 # own contexts so the variables get expanded correctly for that arch, then inject back into
228 # the main data store.
229 deps = []
230 for config in e.mcdata:
231 deps.append(e.mcdata[config].getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS"))
232 deps = " ".join(deps)
233 e.mcdata[''].setVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", deps)
234
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500235 if isinstance(e, bb.event.BuildStarted):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400236 localdata = bb.data.createCopy(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237 statuslines = []
238 for func in oe.data.typed_value('BUILDCFG_FUNCS', localdata):
239 g = globals()
240 if func not in g:
241 bb.warn("Build configuration function '%s' does not exist" % func)
242 else:
243 flines = g[func](localdata)
244 if flines:
245 statuslines.extend(flines)
246
Brad Bishop316dfdd2018-06-25 12:45:53 -0400247 statusheader = d.getVar('BUILDCFG_HEADER')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500248 if statusheader:
249 bb.plain('\n%s\n%s\n' % (statusheader, '\n'.join(statuslines)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500250
251 # This code is to silence warnings where the SDK variables overwrite the
252 # target ones and we'd see dulpicate key names overwriting each other
253 # for various PREFERRED_PROVIDERS
254 if isinstance(e, bb.event.RecipePreFinalise):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400255 if d.getVar("TARGET_PREFIX") == d.getVar("SDK_PREFIX"):
256 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}binutils")
257 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc-initial")
258 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}gcc")
259 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}g++")
260 d.delVar("PREFERRED_PROVIDER_virtual/${TARGET_PREFIX}compilerlibs")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500261
262 if isinstance(e, bb.runqueue.sceneQueueComplete):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400263 completions = d.expand("${STAGING_DIR}/sstatecompletions")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500264 if os.path.exists(completions):
265 cmds = set()
266 with open(completions, "r") as f:
267 cmds = set(f)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400268 d.setVar("completion_function", "\n".join(cmds))
269 d.setVarFlag("completion_function", "func", "1")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500270 bb.debug(1, "Executing SceneQueue Completion commands: %s" % "\n".join(cmds))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400271 bb.build.exec_func("completion_function", d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500272 os.remove(completions)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500273
274 if isinstance(e, bb.event.RecipeParsed):
275 #
276 # If we have multiple providers of virtual/X and a PREFERRED_PROVIDER_virtual/X is set
277 # skip parsing for all the other providers which will mean they get uninstalled from the
278 # sysroot since they're now "unreachable". This makes switching virtual/kernel work in
279 # particular.
280 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500281 pn = d.getVar('PN')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500282 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False)
283 if not source_mirror_fetch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500284 provs = (d.getVar("PROVIDES") or "").split()
285 multiwhitelist = (d.getVar("MULTI_PROVIDER_WHITELIST") or "").split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500286 for p in provs:
287 if p.startswith("virtual/") and p not in multiwhitelist:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500288 profprov = d.getVar("PREFERRED_PROVIDER_" + p)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500289 if profprov and pn != profprov:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400290 raise bb.parse.SkipRecipe("PREFERRED_PROVIDER_%s set to %s, not %s" % (p, profprov, pn))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291}
292
293CONFIGURESTAMPFILE = "${WORKDIR}/configure.sstate"
294CLEANBROKEN = "0"
295
296addtask configure after do_patch
297do_configure[dirs] = "${B}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500298do_prepare_recipe_sysroot[deptask] = "do_populate_sysroot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500299base_do_configure() {
300 if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
301 if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" ]; then
302 cd ${B}
303 if [ "${CLEANBROKEN}" != "1" -a \( -e Makefile -o -e makefile -o -e GNUmakefile \) ]; then
304 oe_runmake clean
305 fi
Brad Bishopc4ea0752018-11-15 14:30:15 -0800306 # -ignore_readdir_race does not work correctly with -delete;
307 # use xargs to avoid spurious build failures
308 find ${B} -ignore_readdir_race -name \*.la -type f -print0 | xargs -0 rm -f
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 fi
310 fi
311 if [ -n "${CONFIGURESTAMPFILE}" ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500312 mkdir -p `dirname ${CONFIGURESTAMPFILE}`
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500313 echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
314 fi
315}
316
317addtask compile after do_configure
318do_compile[dirs] = "${B}"
319base_do_compile() {
320 if [ -e Makefile -o -e makefile -o -e GNUmakefile ]; then
321 oe_runmake || die "make failed"
322 else
323 bbnote "nothing to compile"
324 fi
325}
326
327addtask install after do_compile
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600328do_install[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500329# Remove and re-create ${D} so that is it guaranteed to be empty
330do_install[cleandirs] = "${D}"
331
332base_do_install() {
333 :
334}
335
336base_do_package() {
337 :
338}
339
340addtask build after do_populate_sysroot
341do_build[noexec] = "1"
342do_build[recrdeptask] += "do_deploy"
343do_build () {
344 :
345}
346
347def set_packagetriplet(d):
348 archs = []
349 tos = []
350 tvs = []
351
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500352 archs.append(d.getVar("PACKAGE_ARCHS").split())
353 tos.append(d.getVar("TARGET_OS"))
354 tvs.append(d.getVar("TARGET_VENDOR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500355
356 def settriplet(d, varname, archs, tos, tvs):
357 triplets = []
358 for i in range(len(archs)):
359 for arch in archs[i]:
360 triplets.append(arch + tvs[i] + "-" + tos[i])
361 triplets.reverse()
362 d.setVar(varname, " ".join(triplets))
363
364 settriplet(d, "PKGTRIPLETS", archs, tos, tvs)
365
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500366 variants = d.getVar("MULTILIB_VARIANTS") or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500367 for item in variants.split():
368 localdata = bb.data.createCopy(d)
369 overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item
370 localdata.setVar("OVERRIDES", overrides)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500371
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500372 archs.append(localdata.getVar("PACKAGE_ARCHS").split())
373 tos.append(localdata.getVar("TARGET_OS"))
374 tvs.append(localdata.getVar("TARGET_VENDOR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500375
376 settriplet(d, "PKGMLTRIPLETS", archs, tos, tvs)
377
378python () {
379 import string, re
380
Brad Bishop316dfdd2018-06-25 12:45:53 -0400381 # Handle backfilling
382 oe.utils.features_backfill("DISTRO_FEATURES", d)
383 oe.utils.features_backfill("MACHINE_FEATURES", d)
384
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500385 # Handle PACKAGECONFIG
386 #
387 # These take the form:
388 #
389 # PACKAGECONFIG ??= "<default options>"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500390 # PACKAGECONFIG[foo] = "--enable-foo,--disable-foo,foo_depends,foo_runtime_depends,foo_runtime_recommends"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500391 pkgconfigflags = d.getVarFlags("PACKAGECONFIG") or {}
392 if pkgconfigflags:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500393 pkgconfig = (d.getVar('PACKAGECONFIG') or "").split()
394 pn = d.getVar("PN")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500395
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500396 mlprefix = d.getVar("MLPREFIX")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500397
398 def expandFilter(appends, extension, prefix):
399 appends = bb.utils.explode_deps(d.expand(" ".join(appends)))
400 newappends = []
401 for a in appends:
402 if a.endswith("-native") or ("-cross-" in a):
403 newappends.append(a)
404 elif a.startswith("virtual/"):
405 subs = a.split("/", 1)[1]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500406 if subs.startswith(prefix):
407 newappends.append(a + extension)
408 else:
409 newappends.append("virtual/" + prefix + subs + extension)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500410 else:
411 if a.startswith(prefix):
412 newappends.append(a + extension)
413 else:
414 newappends.append(prefix + a + extension)
415 return newappends
416
417 def appendVar(varname, appends):
418 if not appends:
419 return
420 if varname.find("DEPENDS") != -1:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500421 if bb.data.inherits_class('nativesdk', d) or bb.data.inherits_class('cross-canadian', d) :
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500422 appends = expandFilter(appends, "", "nativesdk-")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500423 elif bb.data.inherits_class('native', d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500424 appends = expandFilter(appends, "-native", "")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500425 elif mlprefix:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500426 appends = expandFilter(appends, "", mlprefix)
427 varname = d.expand(varname)
428 d.appendVar(varname, " " + " ".join(appends))
429
430 extradeps = []
431 extrardeps = []
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500432 extrarrecs = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500433 extraconf = []
434 for flag, flagval in sorted(pkgconfigflags.items()):
435 items = flagval.split(",")
436 num = len(items)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500437 if num > 5:
438 bb.error("%s: PACKAGECONFIG[%s] Only enable,disable,depend,rdepend,rrecommend can be specified!"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500439 % (d.getVar('PN'), flag))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500440
441 if flag in pkgconfig:
442 if num >= 3 and items[2]:
443 extradeps.append(items[2])
444 if num >= 4 and items[3]:
445 extrardeps.append(items[3])
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500446 if num >= 5 and items[4]:
447 extrarrecs.append(items[4])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500448 if num >= 1 and items[0]:
449 extraconf.append(items[0])
450 elif num >= 2 and items[1]:
451 extraconf.append(items[1])
452 appendVar('DEPENDS', extradeps)
453 appendVar('RDEPENDS_${PN}', extrardeps)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500454 appendVar('RRECOMMENDS_${PN}', extrarrecs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500455 appendVar('PACKAGECONFIG_CONFARGS', extraconf)
456
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500457 pn = d.getVar('PN')
458 license = d.getVar('LICENSE')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400459 if license == "INVALID" and pn != "defaultpkgname":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500460 bb.fatal('This recipe does not have the LICENSE field set (%s)' % pn)
461
462 if bb.data.inherits_class('license', d):
463 check_license_format(d)
464 unmatched_license_flag = check_license_flags(d)
465 if unmatched_license_flag:
466 bb.debug(1, "Skipping %s because it has a restricted license not"
467 " whitelisted in LICENSE_FLAGS_WHITELIST" % pn)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400468 raise bb.parse.SkipRecipe("because it has a restricted license not"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500469 " whitelisted in LICENSE_FLAGS_WHITELIST")
470
471 # If we're building a target package we need to use fakeroot (pseudo)
472 # in order to capture permissions, owners, groups and special files
473 if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('cross', d):
474 d.setVarFlag('do_unpack', 'umask', '022')
475 d.setVarFlag('do_configure', 'umask', '022')
476 d.setVarFlag('do_compile', 'umask', '022')
477 d.appendVarFlag('do_install', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500478 d.setVarFlag('do_install', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500479 d.setVarFlag('do_install', 'umask', '022')
480 d.appendVarFlag('do_package', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500481 d.setVarFlag('do_package', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500482 d.setVarFlag('do_package', 'umask', '022')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500483 d.setVarFlag('do_package_setscene', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500484 d.appendVarFlag('do_package_setscene', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500485 d.setVarFlag('do_devshell', 'fakeroot', '1')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500486 d.appendVarFlag('do_devshell', 'depends', ' virtual/fakeroot-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500487
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500488 need_machine = d.getVar('COMPATIBLE_MACHINE')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500489 if need_machine:
490 import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500491 compat_machines = (d.getVar('MACHINEOVERRIDES') or "").split(":")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500492 for m in compat_machines:
493 if re.match(need_machine, m):
494 break
495 else:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400496 raise bb.parse.SkipRecipe("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % d.getVar('MACHINE'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500497
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600498 source_mirror_fetch = d.getVar('SOURCE_MIRROR_FETCH', False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500499 if not source_mirror_fetch:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500500 need_host = d.getVar('COMPATIBLE_HOST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500501 if need_host:
502 import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500503 this_host = d.getVar('HOST_SYS')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500504 if not re.match(need_host, this_host):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400505 raise bb.parse.SkipRecipe("incompatible with host %s (not in COMPATIBLE_HOST)" % this_host)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500506
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500507 bad_licenses = (d.getVar('INCOMPATIBLE_LICENSE') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500508
509 check_license = False if pn.startswith("nativesdk-") else True
510 for t in ["-native", "-cross-${TARGET_ARCH}", "-cross-initial-${TARGET_ARCH}",
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600511 "-crosssdk-${SDK_SYS}", "-crosssdk-initial-${SDK_SYS}",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500512 "-cross-canadian-${TRANSLATED_TARGET_ARCH}"]:
513 if pn.endswith(d.expand(t)):
514 check_license = False
515 if pn.startswith("gcc-source-"):
516 check_license = False
517
518 if check_license and bad_licenses:
519 bad_licenses = expand_wildcard_licenses(d, bad_licenses)
520
521 whitelist = []
522 incompatwl = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500523 for lic in bad_licenses:
524 spdx_license = return_spdx(d, lic)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500525 for w in ["LGPLv2_WHITELIST_", "WHITELIST_"]:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500526 whitelist.extend((d.getVar(w + lic) or "").split())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500527 if spdx_license:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500528 whitelist.extend((d.getVar(w + spdx_license) or "").split())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500529 '''
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500530 We need to track what we are whitelisting and why. If pn is
531 incompatible we need to be able to note that the image that
532 is created may infact contain incompatible licenses despite
533 INCOMPATIBLE_LICENSE being set.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500534 '''
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500535 incompatwl.extend((d.getVar(w + lic) or "").split())
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500536 if spdx_license:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500537 incompatwl.extend((d.getVar(w + spdx_license) or "").split())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500538
539 if not pn in whitelist:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500540 pkgs = d.getVar('PACKAGES').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500541 skipped_pkgs = []
542 unskipped_pkgs = []
543 for pkg in pkgs:
544 if incompatible_license(d, bad_licenses, pkg):
545 skipped_pkgs.append(pkg)
546 else:
547 unskipped_pkgs.append(pkg)
548 all_skipped = skipped_pkgs and not unskipped_pkgs
549 if unskipped_pkgs:
550 for pkg in skipped_pkgs:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500551 bb.debug(1, "SKIPPING the package " + pkg + " at do_rootfs because it's " + license)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500552 mlprefix = d.getVar('MLPREFIX')
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500553 d.setVar('LICENSE_EXCLUSION-' + mlprefix + pkg, 1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500554 for pkg in unskipped_pkgs:
555 bb.debug(1, "INCLUDING the package " + pkg)
556 elif all_skipped or incompatible_license(d, bad_licenses):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500557 bb.debug(1, "SKIPPING recipe %s because it's %s" % (pn, license))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400558 raise bb.parse.SkipRecipe("it has an incompatible license: %s" % license)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500559 elif pn in whitelist:
560 if pn in incompatwl:
561 bb.note("INCLUDING " + pn + " as buildable despite INCOMPATIBLE_LICENSE because it has been whitelisted")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500562
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600563 # Try to verify per-package (LICENSE_<pkg>) values. LICENSE should be a
564 # superset of all per-package licenses. We do not do advanced (pattern)
565 # matching of license expressions - just check that all license strings
566 # in LICENSE_<pkg> are found in LICENSE.
567 license_set = oe.license.list_licenses(license)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500568 for pkg in d.getVar('PACKAGES').split():
569 pkg_license = d.getVar('LICENSE_' + pkg)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600570 if pkg_license:
571 unlisted = oe.license.list_licenses(pkg_license) - license_set
572 if unlisted:
573 bb.warn("LICENSE_%s includes licenses (%s) that are not "
574 "listed in LICENSE" % (pkg, ' '.join(unlisted)))
575
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500576 needsrcrev = False
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500577 srcuri = d.getVar('SRC_URI')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500578 for uri in srcuri.split():
579 (scheme, _ , path) = bb.fetch.decodeurl(uri)[:3]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500580
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500581 # HTTP/FTP use the wget fetcher
582 if scheme in ("http", "https", "ftp"):
583 d.appendVarFlag('do_fetch', 'depends', ' wget-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500584
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500585 # Svn packages should DEPEND on subversion-native
586 if scheme == "svn":
587 needsrcrev = True
588 d.appendVarFlag('do_fetch', 'depends', ' subversion-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500589
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500590 # Git packages should DEPEND on git-native
591 elif scheme in ("git", "gitsm"):
592 needsrcrev = True
593 d.appendVarFlag('do_fetch', 'depends', ' git-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500594
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500595 # Mercurial packages should DEPEND on mercurial-native
596 elif scheme == "hg":
597 needsrcrev = True
598 d.appendVarFlag('do_fetch', 'depends', ' mercurial-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500599
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600600 # Perforce packages support SRCREV = "${AUTOREV}"
601 elif scheme == "p4":
602 needsrcrev = True
603
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500604 # OSC packages should DEPEND on osc-native
605 elif scheme == "osc":
606 d.appendVarFlag('do_fetch', 'depends', ' osc-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500607
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500608 elif scheme == "npm":
609 d.appendVarFlag('do_fetch', 'depends', ' nodejs-native:do_populate_sysroot')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500610
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500611 # *.lz4 should DEPEND on lz4-native for unpacking
612 if path.endswith('.lz4'):
613 d.appendVarFlag('do_unpack', 'depends', ' lz4-native:do_populate_sysroot')
614
615 # *.lz should DEPEND on lzip-native for unpacking
616 elif path.endswith('.lz'):
617 d.appendVarFlag('do_unpack', 'depends', ' lzip-native:do_populate_sysroot')
618
619 # *.xz should DEPEND on xz-native for unpacking
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500620 elif path.endswith('.xz') or path.endswith('.txz'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500621 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
622
623 # .zip should DEPEND on unzip-native for unpacking
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500624 elif path.endswith('.zip') or path.endswith('.jar'):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500625 d.appendVarFlag('do_unpack', 'depends', ' unzip-native:do_populate_sysroot')
626
627 # file is needed by rpm2cpio.sh
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500628 elif path.endswith('.rpm'):
629 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500630
Brad Bishop316dfdd2018-06-25 12:45:53 -0400631 # *.deb should DEPEND on xz-native for unpacking
632 elif path.endswith('.deb'):
633 d.appendVarFlag('do_unpack', 'depends', ' xz-native:do_populate_sysroot')
634
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500635 if needsrcrev:
636 d.setVar("SRCPV", "${@bb.fetch2.get_srcrev(d)}")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500637
638 set_packagetriplet(d)
639
640 # 'multimachine' handling
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500641 mach_arch = d.getVar('MACHINE_ARCH')
642 pkg_arch = d.getVar('PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500643
644 if (pkg_arch == mach_arch):
645 # Already machine specific - nothing further to do
646 return
647
648 #
649 # We always try to scan SRC_URI for urls with machine overrides
650 # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
651 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500652 override = d.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500653 if override != '0':
654 paths = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500655 fpaths = (d.getVar('FILESPATH') or '').split(':')
656 machine = d.getVar('MACHINE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500657 for p in fpaths:
658 if os.path.basename(p) == machine and os.path.isdir(p):
659 paths.append(p)
660
661 if len(paths) != 0:
662 for s in srcuri.split():
663 if not s.startswith("file://"):
664 continue
665 fetcher = bb.fetch2.Fetch([s], d)
666 local = fetcher.localpath(s)
667 for mp in paths:
668 if local.startswith(mp):
669 #bb.note("overriding PACKAGE_ARCH from %s to %s for %s" % (pkg_arch, mach_arch, pn))
670 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
671 return
672
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500673 packages = d.getVar('PACKAGES').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500674 for pkg in packages:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500675 pkgarch = d.getVar("PACKAGE_ARCH_%s" % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500676
677 # We could look for != PACKAGE_ARCH here but how to choose
678 # if multiple differences are present?
679 # Look through PACKAGE_ARCHS for the priority order?
680 if pkgarch and pkgarch == mach_arch:
681 d.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500682 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 -0500683}
684
685addtask cleansstate after do_clean
686python do_cleansstate() {
687 sstate_clean_cachefiles(d)
688}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500689addtask cleanall after do_cleansstate
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500690do_cleansstate[nostamp] = "1"
691
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500692python do_cleanall() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500693 src_uri = (d.getVar('SRC_URI') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500694 if len(src_uri) == 0:
695 return
696
697 try:
698 fetcher = bb.fetch2.Fetch(src_uri, d)
699 fetcher.clean()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600700 except bb.fetch2.BBFetchException as e:
701 bb.fatal(str(e))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702}
703do_cleanall[nostamp] = "1"
704
705
706EXPORT_FUNCTIONS do_fetch do_unpack do_configure do_compile do_install do_package