From 988f77af3eaf49692bbd456bfe692c507dfa5fbe Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Wed, 3 Aug 2016 16:32:15 +0300 Subject: license: simple verification of LICENSE_ values LICENSE should be a superset of all LICENSE_ values. That is, LICENSE should contain all licenses and LICENSE_ can be used to "filter" this on a per-package basis. LICENSE_ shouldn't contain anything that isn't specified in LICENSE. This patch implements simple checking of LICENSE_ values. It does do not do advanced parsing/matching of license expressions, but, checks that all licenses mentioned in LICENSE_ are also specified in LICENSE. A warning is printed if problems are found. (From OE-Core rev: 0f4163a12ea431d0ba6265880ee1e557333d3211) Signed-off-by: Markus Lehtonen Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- meta/classes/base.bbclass | 13 +++++++++++++ meta/lib/oe/license.py | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'meta') diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass index f2e3d4092e..79edfe5451 100644 --- a/meta/classes/base.bbclass +++ b/meta/classes/base.bbclass @@ -543,6 +543,19 @@ python () { if pn in incompatwl: bb.note("INCLUDING " + pn + " as buildable despite INCOMPATIBLE_LICENSE because it has been whitelisted") + # Try to verify per-package (LICENSE_) values. LICENSE should be a + # superset of all per-package licenses. We do not do advanced (pattern) + # matching of license expressions - just check that all license strings + # in LICENSE_ are found in LICENSE. + license_set = oe.license.list_licenses(license) + for pkg in d.getVar('PACKAGES', True).split(): + pkg_license = d.getVar('LICENSE_' + pkg, True) + if pkg_license: + unlisted = oe.license.list_licenses(pkg_license) - license_set + if unlisted: + bb.warn("LICENSE_%s includes licenses (%s) that are not " + "listed in LICENSE" % (pkg, ' '.join(unlisted))) + needsrcrev = False srcuri = d.getVar('SRC_URI', True) for uri in srcuri.split(): diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py index 39ef9654fc..8d2fd1709c 100644 --- a/meta/lib/oe/license.py +++ b/meta/lib/oe/license.py @@ -215,3 +215,21 @@ def manifest_licenses(licensestr, dont_want_licenses, canonical_license, d): manifest.licensestr = manifest.licensestr.replace('[', '(').replace(']', ')') return (manifest.licensestr, manifest.licenses) + +class ListVisitor(LicenseVisitor): + """Record all different licenses found in the license string""" + def __init__(self): + self.licenses = set() + + def visit_Str(self, node): + self.licenses.add(node.s) + +def list_licenses(licensestr): + """Simply get a list of all licenses mentioned in a license string. + Binary operators are not applied or taken into account in any way""" + visitor = ListVisitor() + try: + visitor.visit_string(licensestr) + except SyntaxError as exc: + raise LicenseSyntaxError(licensestr, exc) + return visitor.licenses -- cgit v1.2.3-54-g00ecf