summaryrefslogtreecommitdiffstats
path: root/meta/classes-global/license.bbclass
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2024-10-24 13:03:07 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-10-25 15:37:10 +0100
commit71760081f782cdf1e53c3ff03a6376fac3605196 (patch)
tree5976208e344a0ec405cd19942468571349a70874 /meta/classes-global/license.bbclass
parentde1fa1e0b0a01ae8a30bbb848e681f0fa2db7ad4 (diff)
downloadpoky-71760081f782cdf1e53c3ff03a6376fac3605196.tar.gz
classes-global/license: Move functions to library code
Moves several of the functions in license.bbclass to be library code New function dependencies were manually verified using bitbake-dumpsigs to ensure that bitbake identified the same dependencies even though they are now in library code (although the new function names mean that the task hashes still change) (From OE-Core rev: 0333e04e353991260c5f67a72f80f3ab9dcf526a) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-global/license.bbclass')
-rw-r--r--meta/classes-global/license.bbclass165
1 files changed, 0 insertions, 165 deletions
diff --git a/meta/classes-global/license.bbclass b/meta/classes-global/license.bbclass
index 043715fcc3..94dcc7f331 100644
--- a/meta/classes-global/license.bbclass
+++ b/meta/classes-global/license.bbclass
@@ -255,171 +255,6 @@ def find_license_files(d):
255 255
256 return lic_files_paths 256 return lic_files_paths
257 257
258def return_spdx(d, license):
259 """
260 This function returns the spdx mapping of a license if it exists.
261 """
262 return d.getVarFlag('SPDXLICENSEMAP', license)
263
264def canonical_license(d, license):
265 """
266 Return the canonical (SPDX) form of the license if available (so GPLv3
267 becomes GPL-3.0-only) or the passed license if there is no canonical form.
268 """
269 return d.getVarFlag('SPDXLICENSEMAP', license) or license
270
271def expand_wildcard_licenses(d, wildcard_licenses):
272 """
273 There are some common wildcard values users may want to use. Support them
274 here.
275 """
276 licenses = set(wildcard_licenses)
277 mapping = {
278 "AGPL-3.0*" : ["AGPL-3.0-only", "AGPL-3.0-or-later"],
279 "GPL-3.0*" : ["GPL-3.0-only", "GPL-3.0-or-later"],
280 "LGPL-3.0*" : ["LGPL-3.0-only", "LGPL-3.0-or-later"],
281 }
282 for k in mapping:
283 if k in wildcard_licenses:
284 licenses.remove(k)
285 for item in mapping[k]:
286 licenses.add(item)
287
288 for l in licenses:
289 if l in oe.license.obsolete_license_list():
290 bb.fatal("Error, %s is an obsolete license, please use an SPDX reference in INCOMPATIBLE_LICENSE" % l)
291 if "*" in l:
292 bb.fatal("Error, %s is an invalid license wildcard entry" % l)
293
294 return list(licenses)
295
296def incompatible_license_contains(license, truevalue, falsevalue, d):
297 license = canonical_license(d, license)
298 bad_licenses = (d.getVar('INCOMPATIBLE_LICENSE') or "").split()
299 bad_licenses = expand_wildcard_licenses(d, bad_licenses)
300 return truevalue if license in bad_licenses else falsevalue
301
302def incompatible_pkg_license(d, dont_want_licenses, license):
303 # Handles an "or" or two license sets provided by
304 # flattened_licenses(), pick one that works if possible.
305 def choose_lic_set(a, b):
306 return a if all(oe.license.license_ok(canonical_license(d, lic),
307 dont_want_licenses) for lic in a) else b
308
309 try:
310 licenses = oe.license.flattened_licenses(license, choose_lic_set)
311 except oe.license.LicenseError as exc:
312 bb.fatal('%s: %s' % (d.getVar('P'), exc))
313
314 incompatible_lic = []
315 for l in licenses:
316 license = canonical_license(d, l)
317 if not oe.license.license_ok(license, dont_want_licenses):
318 incompatible_lic.append(license)
319
320 return sorted(incompatible_lic)
321
322def incompatible_license(d, dont_want_licenses, package=None):
323 """
324 This function checks if a recipe has only incompatible licenses. It also
325 take into consideration 'or' operand. dont_want_licenses should be passed
326 as canonical (SPDX) names.
327 """
328 import oe.license
329 license = d.getVar("LICENSE:%s" % package) if package else None
330 if not license:
331 license = d.getVar('LICENSE')
332
333 return incompatible_pkg_license(d, dont_want_licenses, license)
334
335def check_license_flags(d):
336 """
337 This function checks if a recipe has any LICENSE_FLAGS that
338 aren't acceptable.
339
340 If it does, it returns the all LICENSE_FLAGS missing from the list
341 of acceptable license flags, or all of the LICENSE_FLAGS if there
342 is no list of acceptable flags.
343
344 If everything is is acceptable, it returns None.
345 """
346
347 def license_flag_matches(flag, acceptlist, pn):
348 """
349 Return True if flag matches something in acceptlist, None if not.
350
351 Before we test a flag against the acceptlist, we append _${PN}
352 to it. We then try to match that string against the
353 acceptlist. This covers the normal case, where we expect
354 LICENSE_FLAGS to be a simple string like 'commercial', which
355 the user typically matches exactly in the acceptlist by
356 explicitly appending the package name e.g 'commercial_foo'.
357 If we fail the match however, we then split the flag across
358 '_' and append each fragment and test until we either match or
359 run out of fragments.
360 """
361 flag_pn = ("%s_%s" % (flag, pn))
362 for candidate in acceptlist:
363 if flag_pn == candidate:
364 return True
365
366 flag_cur = ""
367 flagments = flag_pn.split("_")
368 flagments.pop() # we've already tested the full string
369 for flagment in flagments:
370 if flag_cur:
371 flag_cur += "_"
372 flag_cur += flagment
373 for candidate in acceptlist:
374 if flag_cur == candidate:
375 return True
376 return False
377
378 def all_license_flags_match(license_flags, acceptlist):
379 """ Return all unmatched flags, None if all flags match """
380 pn = d.getVar('PN')
381 split_acceptlist = acceptlist.split()
382 flags = []
383 for flag in license_flags.split():
384 if not license_flag_matches(flag, split_acceptlist, pn):
385 flags.append(flag)
386 return flags if flags else None
387
388 license_flags = d.getVar('LICENSE_FLAGS')
389 if license_flags:
390 acceptlist = d.getVar('LICENSE_FLAGS_ACCEPTED')
391 if not acceptlist:
392 return license_flags.split()
393 unmatched_flags = all_license_flags_match(license_flags, acceptlist)
394 if unmatched_flags:
395 return unmatched_flags
396 return None
397
398def check_license_format(d):
399 """
400 This function checks if LICENSE is well defined,
401 Validate operators in LICENSES.
402 No spaces are allowed between LICENSES.
403 """
404 pn = d.getVar('PN')
405 licenses = d.getVar('LICENSE')
406 from oe.license import license_operator, license_operator_chars, license_pattern
407
408 elements = list(filter(lambda x: x.strip(), license_operator.split(licenses)))
409 for pos, element in enumerate(elements):
410 if license_pattern.match(element):
411 if pos > 0 and license_pattern.match(elements[pos - 1]):
412 oe.qa.handle_error('license-format',
413 '%s: LICENSE value "%s" has an invalid format - license names ' \
414 'must be separated by the following characters to indicate ' \
415 'the license selection: %s' %
416 (pn, licenses, license_operator_chars), d)
417 elif not license_operator.match(element):
418 oe.qa.handle_error('license-format',
419 '%s: LICENSE value "%s" has an invalid separator "%s" that is not ' \
420 'in the valid list of separators (%s)' %
421 (pn, licenses, element, license_operator_chars), d)
422
423SSTATETASKS += "do_populate_lic" 258SSTATETASKS += "do_populate_lic"
424do_populate_lic[sstate-inputdirs] = "${LICSSTATEDIR}" 259do_populate_lic[sstate-inputdirs] = "${LICSSTATEDIR}"
425do_populate_lic[sstate-outputdirs] = "${LICENSE_DIRECTORY}/" 260do_populate_lic[sstate-outputdirs] = "${LICENSE_DIRECTORY}/"