Skip to contentSkip to conversation

license: Add support for SPDX 2.0 operators

PATCH Superseded Sergei Miroshnichenko 1 participant 2 messages Jun 21, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 license: Add support for SPDX 2.0 operators

Composite SPDX license expressions can be constructed using "OR", "AND" and "WITH" operators: map them to "|" and "&" Yocto operators accordingly.

Recognize long form license identifiers: "[DocumentRef-XXX:][LicenseRef-]YYY".

Tested on the following expressions:
LICENSE = "Artistic-1.0"
LICENSE = "LicenseRef-Artistic-1.0 AND NASA-1.3" LICENSE = "(LicenseRef-Artistic-1.0 WITH Classpath-exception-2.0)

           OR (DocumentRef-spdx-tool-1.2:LicenseRef-NASA-1.3 AND GPL-2.0+)"

Reference:
https://spdx.org/sites/spdx/files/SPDX-2.0.pdf Appendix IV: SPDX License Expression

---
 meta/classes/license.bbclass | 17 ++++++++++-------
 meta/lib/oe/license.py       | 21 ++++++++++++++++-----
 2 files changed, 26 insertions(+), 12 deletions(-)
meta/classes/license.bbclass +10 -7
index 69335d6..7f7f7dd 100644
@@ -633,20 +633,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 = 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}"
meta/lib/oe/license.py +16 -5
index f0f661c..4f42a9e 100644
@@ -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 = filter(lambda x: x.strip(), license_operator.split(licensestr))
         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)
 
Signature · 1 line
2.1.0
#1 lore raw

PATCH 2/2 ref-manual: Add description for SPDX license operators

Add examples of "OR", "AND" and "WITH" operators usage.

Reference:
https://spdx.org/sites/spdx/files/SPDX-2.0.pdf Appendix IV: SPDX License Expression

---
 documentation/ref-manual/ref-variables.xml | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
documentation/ref-manual/ref-variables.xml +16 -5
index d55bccd..5892530 100644
@@ -7106,12 +7106,17 @@ recipes-graphics/xorg-font/font-alias_1.0.3.bb:PR = "${INC_PR}.3"
                     <itemizedlist>
                         <listitem><para>Do not use spaces within individual
                             license names.</para></listitem>
-                        <listitem><para>Separate license names using
-                            | (pipe) when there is a choice between licenses.
+                        <listitem><para>Separate license names using the
+                            | (pipe) or "OR" operators when there is a choice
+                            between licenses.
                             </para></listitem>
-                        <listitem><para>Separate license names using
-                            &amp; (ampersand) when multiple licenses exist
-                            that cover different parts of the source.
+                        <listitem><para>Separate license names using the
+                            &amp; (ampersand) or "AND" operators when multiple
+                            licenses exist that cover different parts of the source.
+                            </para></listitem>
+                        <listitem><para>Separate license and exception names using the
+                            "WITH" operator when a set of license terms apply except
+                            under special circumstances.
                             </para></listitem>
                         <listitem><para>You can use spaces between license
                             names.</para></listitem>
@@ -7132,6 +7137,12 @@ recipes-graphics/xorg-font/font-alias_1.0.3.bb:PR = "${INC_PR}.3"
      LICENSE = "LGPLv2.1 | GPLv3"
      LICENSE = "MPL-1 &amp; LGPLv2.1"
      LICENSE = "GPLv2+"
+     LICENSE = "LGPL-2.1 OR MIT"
+     LICENSE = "LGPL-2.1 OR MIT OR BSD-3-Clause"
+     LICENSE = "LGPL-2.1 AND MIT"
+     LICENSE = "LGPL-2.1 AND MIT AND BSD-2-Clause"
+     LICENSE = "GPL-2.0+ WITH Bison-exception-2.2"
+     LICENSE = "MIT AND (LGPL-2.1+ AND BSD-3-Clause)"
                     </literallayout>
                     The first example is from the recipes for Qt, which the user
                     may choose to distribute under either the LGPL version
Signature · 1 line
2.1.0