]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
license: Add support for SPDX 2.0 operators
authorSergei Miroshnichenko <sergeimir@emcraft.com>
Tue, 26 Jul 2016 07:53:03 +0000 (10:53 +0300)
committerSergei Miroshnichenko <sergeimir@emcraft.com>
Tue, 18 Oct 2016 10:14:57 +0000 (13:14 +0300)
LICENSE can contain "OR", "AND" and "WITH" operators of SPDX: map
them to "|" and "&" accordingly.

Signed-off-by: Sergei Miroshnichenko <sergeimir@emcraft.com>
meta/classes/license.bbclass
meta/lib/oe/license.py

index 2de3113557fe200eac07f22c74ca7e25021c2f12..96fff5e567ac5d433df4eb85a462a503e84437ca 100644 (file)
@@ -59,6 +59,7 @@ python license_create_manifest() {
 
 def write_license_files(d, license_manifest, pkg_dic):
     import re
+    from oe.license import license_operator
 
     bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE", True) or "").split()
     bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses)
@@ -76,6 +77,7 @@ def write_license_files(d, license_manifest, pkg_dic):
             else:
                 pkg_dic[pkg]["LICENSES"] = re.sub('[|&()*]', ' ', pkg_dic[pkg]["LICENSE"])
                 pkg_dic[pkg]["LICENSES"] = re.sub('  *', ' ', pkg_dic[pkg]["LICENSES"])
+                pkg_dic[pkg]["LICENSES"] = license_operator.sub(r' ', pkg_dic[pkg]["LICENSES"])
                 pkg_dic[pkg]["LICENSES"] = pkg_dic[pkg]["LICENSES"].split()
 
             if not "IMAGE_MANIFEST" in pkg_dic[pkg]:
@@ -647,20 +649,23 @@ def check_license_format(d):
     """
     pn = d.getVar('PN', True)
     licenses = d.getVar('LICENSE', True)
-    from oe.license import license_operator, license_operator_chars, license_pattern
+    from oe.license import license_operator, license_pattern
 
     elements = list(filter(lambda x: x.strip(), license_operator.split(licenses)))
     for pos, element in enumerate(elements):
-        if license_pattern.match(element):
-            if pos > 0 and license_pattern.match(elements[pos - 1]):
+        operator_match = license_operator.match(element)
+        license_match = license_pattern.match(element)
+
+        if license_match and not operator_match:
+            if pos > 0 and license_pattern.match(elements[pos - 1]) and not license_operator.match(elements[pos - 1]):
                 bb.warn('%s: LICENSE value "%s" has an invalid format - license names ' \
-                        'must be separated by the following characters to indicate ' \
+                        'must be separated by the following operators to indicate ' \
                         'the license selection: %s' %
-                        (pn, licenses, license_operator_chars))
-        elif not license_operator.match(element):
+                        (pn, licenses, license_operator.pattern))
+        elif not operator_match:
             bb.warn('%s: LICENSE value "%s" has an invalid separator "%s" that is not ' \
                     'in the valid list of separators (%s)' %
-                    (pn, licenses, element, license_operator_chars))
+                    (pn, licenses, element, license_operator.pattern))
 
 SSTATETASKS += "do_populate_lic"
 do_populate_lic[sstate-inputdirs] = "${LICSSTATEDIR}"
index 8d2fd1709cf12f2b4c12d2793e2c6545898b54b2..44f130df3fce213bd0ee3c4cf948dba16c554fa7 100644 (file)
@@ -40,8 +40,13 @@ class InvalidLicense(LicenseError):
         return "invalid characters in license '%s'" % self.license
 
 license_operator_chars = '&|() '
-license_operator = re.compile('([' + license_operator_chars + '])')
-license_pattern = re.compile('[a-zA-Z0-9.+_\-]+$')
+license_operator = re.compile('([' + license_operator_chars + ']|AND|OR|WITH)')
+license_pattern = re.compile('^(?:DocumentRef-[a-zA-Z0-9.\-]+:)?(?:LicenseRef-)?([a-zA-Z0-9_.+\-]+)$')
+
+license_operator_map = {}
+license_operator_map["OR"] = '|'
+license_operator_map["AND"] = '&'
+license_operator_map["WITH"] = '&'
 
 class LicenseVisitor(ast.NodeVisitor):
     """Get elements based on OpenEmbedded license strings"""
@@ -49,11 +54,17 @@ class LicenseVisitor(ast.NodeVisitor):
         new_elements = []
         elements = list([x for x in license_operator.split(licensestr) if x.strip()])
         for pos, element in enumerate(elements):
-            if license_pattern.match(element):
-                if pos > 0 and license_pattern.match(elements[pos-1]):
+            operator_match = license_operator.match(element)
+            license_match = license_pattern.match(element)
+            if operator_match:
+                if license_operator_map.get(element, None) != None:
+                    element = license_operator_map.get(element)
+            elif license_match:
+                if pos > 0 and license_pattern.match(elements[pos-1]) and not license_operator.match(elements[pos-1]):
                     new_elements.append('&')
+                element = license_match.group(1)
                 element = '"' + element + '"'
-            elif not license_operator.match(element):
+            else:
                 raise InvalidLicense(element)
             new_elements.append(element)