Skip to contentSkip to conversation

license.py: fix behaviour of copyleft_compliance

PATCH In review Eric Bénard 2 participants 3 messages Apr 2, 2012 – Apr 4, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 license.py: fix behaviour of copyleft_compliance

actually if a package has a license in its LICENSE variable which is not in the whitelist nor in the blacklist and even if an other license in this variable is in the whitelist, the package gets excluded and is not taken in account in the copyleft_compliance.
This patch solves this by excluding a recipe _only_ if the LICENSE variable includes a pattern from the blacklist and including a recipe only if it includes a variable from the whitelist _and_ none from the blacklist.

Example in busybox which has LICENSE="GPLv2 & BSD-4-Clause",
with the actual behaviour (where he blacklist contains only
CLOSED Proprietary) we get :
DEBUG: copyleft: busybox-1.19.4 is excluded: recipe has excluded licenses: BSD-4-Clause which is not sane because busybox is covered by a copyleft license
which is GPLv2 and should match the default whitelist which is
GPL* LGPL*.

---
v2: updated and tested after Kergoth's review on IRC

 meta/lib/oe/license.py |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
meta/lib/oe/license.py +7 -4
index 5914506..173e319 100644
@@ -86,8 +86,10 @@ def is_included(licensestr, whitelist=None, blacklist=None):
     """
 
     def include_license(license):
-        return (any(fnmatch(license, pattern) for pattern in whitelist) and not
-                any(fnmatch(license, pattern) for pattern in blacklist))
+        return any(fnmatch(license, pattern) for pattern in whitelist)
+
+    def exclude_license(license):
+        return any(fnmatch(license, pattern) for pattern in blacklist)
 
     def choose_licenses(alpha, beta):
         """Select the option in an OR which is the 'best' (has the most
@@ -106,8 +108,9 @@ def is_included(licensestr, whitelist=None, blacklist=None):
         blacklist = []
 
     licenses = flattened_licenses(licensestr, choose_licenses)
-    excluded = filter(lambda lic: not include_license(lic), licenses)
+    excluded = filter(lambda lic: exclude_license(lic), licenses)
+    included = filter(lambda lic: include_license(lic), licenses)
     if excluded:
         return False, excluded
     else:
-        return True, None
+        return True, included
Signature · 1 line
1.7.7.6
#1 lore raw

PATCH 2/2 copyleft_compliance: also print the reason for including a package

---
 meta/classes/copyleft_compliance.bbclass |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
meta/classes/copyleft_compliance.bbclass +4 -4
index 4082e7e..3ca7337 100644
@@ -47,14 +47,14 @@ def copyleft_should_include(d):
     exclude = oe.data.typed_value('COPYLEFT_LICENSE_EXCLUDE', d)
 
     try:
-        is_included, excluded = oe.license.is_included(d.getVar('LICENSE', True), include, exclude)
+        is_included, reason = oe.license.is_included(d.getVar('LICENSE', True), include, exclude)
     except oe.license.LicenseError as exc:
         bb.fatal('%s: %s' % (d.getVar('PF', True), exc))
     else:
         if is_included:
-            return True, None
+            return True, 'recipe has included licenses: %s' % ', '.join(reason)
         else:
-            return False, 'recipe has excluded licenses: %s' % ', '.join(excluded)
+            return False, 'recipe has excluded licenses: %s' % ', '.join(reason)
 
 python do_prepare_copyleft_sources () {
     """Populate a tree of the recipe sources and emit patch series files"""
@@ -67,7 +67,7 @@ python do_prepare_copyleft_sources () {
         bb.debug(1, 'copyleft: %s is excluded: %s' % (p, reason))
         return
     else:
-        bb.debug(1, 'copyleft: %s is included' % p)
+        bb.debug(1, 'copyleft: %s is included: %s' % (p, reason))
 
     sources_dir = d.getVar('COPYLEFT_SOURCES_DIR', True)
     src_uri = d.getVar('SRC_URI', True).split()
Signature · 1 line
1.7.7.6
#2 lore raw
In reply to Eric Bénard
Quoted 44 lines · Eric Bénard

actually if a package has a license in its LICENSE variable which is not in the whitelist nor in the blacklist and even if an other license in this variable is in the whitelist, the package gets excluded and is not taken in account in the copyleft_compliance.
This patch solves this by excluding a recipe _only_ if the LICENSE variable includes a pattern from the blacklist and including a recipe only if it includes a variable from the whitelist _and_ none from the blacklist.

Example in busybox which has LICENSE="GPLv2& BSD-4-Clause",
with the actual behaviour (where he blacklist contains only
CLOSED Proprietary) we get :
DEBUG: copyleft: busybox-1.19.4 is excluded: recipe has excluded licenses: BSD-4-Clause which is not sane because busybox is covered by a copyleft license
which is GPLv2 and should match the default whitelist which is
GPL* LGPL*.

---
v2: updated and tested after Kergoth's review on IRC

  meta/lib/oe/license.py |   11 +++++++----
  1 files changed, 7 insertions(+), 4 deletions(-)
meta/lib/oe/license.py +4 -2
index 5914506..173e319 100644
@@ -86,8 +86,10 @@ def is_included(licensestr, whitelist=None, blacklist=None):
      """
 
      def include_license(license):
-        return (any(fnmatch(license, pattern) for pattern in whitelist) and not
-                any(fnmatch(license, pattern) for pattern in blacklist))
+        return any(fnmatch(license, pattern) for pattern in whitelist)
+
+    def exclude_license(license):
+        return any(fnmatch(license, pattern) for pattern in blacklist)
 
      def choose_licenses(alpha, beta):
          """Select the option in an OR which is the 'best' (has the most
@@ -106,8 +108,9 @@ def is_included(licensestr, whitelist=None, blacklist=None):
          blacklist = []

meta/lib/oe/license.py def is_included(licensestr, whitelist=None, blacklist=None): · line 116

Quoted 10 lines
meta/lib/oe/license.py +3 -2
 
      licenses = flattened_licenses(licensestr, choose_licenses)
-    excluded = filter(lambda lic: not include_license(lic), licenses)
+    excluded = filter(lambda lic: exclude_license(lic), licenses)
+    included = filter(lambda lic: include_license(lic), licenses)
      if excluded:
          return False, excluded
      else:
-        return True, None
+        return True, included

Merged both of these into OE-Core

Thanks
Sau!