]> code.ossystems Code Review - openembedded-core.git/commitdiff
license: simple verification of LICENSE_<pkg> values
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 3 Aug 2016 13:32:15 +0000 (16:32 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 25 Aug 2016 21:54:44 +0000 (22:54 +0100)
LICENSE should be a superset of all LICENSE_<pkg> values. That is,
LICENSE should contain all licenses and LICENSE_<pkg> can be used to
"filter" this on a per-package basis. LICENSE_<pkg> shouldn't contain
anything that isn't specified in LICENSE.

This patch implements simple checking of LICENSE_<pkg> values. It does
do not do advanced parsing/matching of license expressions, but,
checks that all licenses mentioned in LICENSE_<pkg> are also specified in
LICENSE. A warning is printed if problems are found.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/classes/base.bbclass
meta/lib/oe/license.py

index f2e3d4092eb0a4ea978fd8956d274b9fce13df0c..79edfe54518b4ac343efef51915eff3e865fd581 100644 (file)
@@ -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_<pkg>) 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_<pkg> 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():
index 39ef9654fcfe0658b8e1cfd08fabb4a71d940deb..8d2fd1709cf12f2b4c12d2793e2c6545898b54b2 100644 (file)
@@ -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