Skip to contentSkip to conversation

Improved handling of LICENSE_<pkg> variables

PATCH New Markus Lehtonen 1 participant 3 messages Aug 3, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover Improved handling of LICENSE_<pkg> variables

The first patch is actually unchanged, just re-sending it.

However, in the discussion on the patch there seemed to be some confusion regarding the relation between LICENSE and LICENSE_<pkg> variables. Thus, I decided to implement the second patch of this series which does basic verification/sanity checking of LICENSE_<pkg> values.

Looking at the warnings I get after applying the second patch, at least nettle 2.7.1 and hdparm in OE-Core seem to be using LICENSE and LICENSE_<pkg> incorrectly.

[YOCTO #9499]

The following changes since commit 986f7fbe37a48d050611f08f7160ed96755ac3dc:

foomatic-filters: Security fixes CVE-2015-8327 (2016-08-01 12:11:09 +0100)

are available in the git repository at:

git://git.openembedded.org/openembedded-core-contrib marquiz/fixes-9499
http://git.openembedded.org/openembedded-core-contrib/log/?h=marquiz/fixes-9499

Markus Lehtonen (2):
license.bbclass: do not process LICENSE_pn variables
license: simple verification of LICENSE_<pkg> values

 meta/classes/base.bbclass    | 13 +++++++++++++
 meta/classes/license.bbclass | 16 +---------------
 meta/lib/oe/license.py       | 18 ++++++++++++++++++
 3 files changed, 32 insertions(+), 15 deletions(-)
Signature · 1 line
2.6.6
#1 lore raw

PATCH v2 1/2 license.bbclass: do not process LICENSE_pn variables

The loop iterating over LICENSE_pn variables has never worked. In addition, the LICENSE variable is supposed to contain all licenses defined in LICENSE_pn variables. Thus, it is simpler just to use LICENSE as the data we get is essentially the same.

[YOCTO #9499]

---
 meta/classes/license.bbclass | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)
meta/classes/license.bbclass +1 -15
index 26c297d..598c8af 100644
@@ -386,20 +386,6 @@ def find_license_files(d):
     import shutil
     import oe.license
 
-    pn = d.getVar('PN', True)
-    for package in d.getVar('PACKAGES', True):
-        if d.getVar('LICENSE_' + package, True):
-            license_types = license_types + ' & ' + \
-                            d.getVar('LICENSE_' + package, True)
-
-    #If we get here with no license types, then that means we have a recipe 
-    #level license. If so, we grab only those.
-    try:
-        license_types
-    except NameError:        
-        # All the license types at the recipe level
-        license_types = d.getVar('LICENSE', True)
- 
     # All the license files for the package
     lic_files = d.getVar('LIC_FILES_CHKSUM', True)
     pn = d.getVar('PN', True)
@@ -497,7 +483,7 @@ def find_license_files(d):
 
     v = FindVisitor()
     try:
-        v.visit_string(license_types)
+        v.visit_string(d.getVar('LICENSE', True))
     except oe.license.InvalidLicense as exc:
         bb.fatal('%s: %s' % (d.getVar('PF', True), exc))
     except SyntaxError:
Signature · 1 line
2.6.6
#2 lore raw

PATCH v2 2/2 license: simple verification of LICENSE_<pkg> values

In reply to Markus Lehtonen

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.

---
 meta/classes/base.bbclass | 13 +++++++++++++
 meta/lib/oe/license.py    | 18 ++++++++++++++++++
 2 files changed, 31 insertions(+)
meta/classes/base.bbclass +13 -0
index 5d8e8d6..32aca31 100644
@@ -545,6 +545,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():
meta/lib/oe/license.py +18 -0
index 39ef965..8d2fd17 100644
@@ -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
Signature · 1 line
2.6.6