Openembedded Core Discussions
 help / color / mirror / Atom feed
From: "Aníbal Limón" <anibal.limon@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 2/4] license_class: Added support for INCOMPATIBLE_LICENSE into license_create_manifest
Date: Wed, 29 Oct 2014 12:34:14 -0600	[thread overview]
Message-ID: <1414607656-12144-3-git-send-email-anibal.limon@linux.intel.com> (raw)
In-Reply-To: <1414607656-12144-1-git-send-email-anibal.limon@linux.intel.com>

Now license_create_manifest handle INCOMPATIBLE_LICENSE to avoid
put them into license.manifest and copy them into target image.

Generalized license_ok(license) to license_ok(bad_licenses, license)
to avoid duplicate code.

[YOCTO #6765]

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
---
 meta/classes/license.bbclass | 60 ++++++++++++++++++++++++++++++--------------
 1 file changed, 41 insertions(+), 19 deletions(-)

diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index c8a86ce..c11ef1c 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -28,6 +28,15 @@ python write_package_manifest() {
 python license_create_manifest() {
     import shutil
     import re
+    import oe.license
+
+    bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE", True) or "").split()
+    bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses)
+
+    # Handles an "or" or two license sets provided by
+    # flattened_licenses(), pick one that works if possible.
+    def choose_lic_set(a, b):
+        return a if all(license_ok(bad_licenses, lic) for lic in a) else b
 
     build_images_from_feeds = d.getVar('BUILD_IMAGES_FROM_FEEDS', True)
     if build_images_from_feeds == "1":
@@ -70,9 +79,13 @@ python license_create_manifest() {
             license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"])
             license_file.write("LICENSE:")
 
-            licenses = re.sub('[|&()*]', '', pkg_dic[pkg]["LICENSE"])
-            licenses = re.sub('  *', ' ', licenses)
-            for lic in licenses.split():
+            try:
+                licenses = oe.license.flattened_licenses(pkg_dic[pkg]["LICENSE"]
+                            , choose_lic_set)
+            except oe.license.LicenseError as exc:
+                bb.fatal('%s: %s' % (d.getVar('P', True), exc))
+
+            for lic in licenses:
                 lic = re.sub('\+', '', lic)
                 lic_file = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
                                         pkg_dic[pkg]["PN"], "generic_%s" % lic)
@@ -110,11 +123,18 @@ python license_create_manifest() {
                     pkg_rootfs_license = os.path.join(pkg_rootfs_license_dir, lic)
 
                     if re.match("^generic_.*$", lic):
+                        generic_lic = re.search("^generic_(.*)$", lic).group(1)
+                        if not license_ok(bad_licenses, generic_lic):
+                            continue
+
                         if not os.path.exists(pkg_rootfs_license):
                             shutil.copyfile(pkg_license, rootfs_license)
 
                         os.symlink(os.path.join('..', lic), pkg_rootfs_license)
                     else:
+                        if not license_ok(bad_licenses, lic):
+                            continue
+
                         shutil.copyfile(pkg_license, pkg_rootfs_license)
 }
 
@@ -297,6 +317,21 @@ def canonical_license(d, license):
     """
     return d.getVarFlag('SPDXLICENSEMAP', license, True) or license
 
+def license_ok(dont_want_licenses, license):
+    import re
+    from fnmatch import fnmatchcase as fnmatch
+    for dwl in dont_want_licenses:
+        # If you want to exclude license named generically 'X', we
+        # surely want to exclude 'X+' as well.  In consequence, we
+        # will exclude a trailing '+' character from LICENSE in
+        # case INCOMPATIBLE_LICENSE is not a 'X+' license.
+        lic = license
+        if not re.search('\+$', dwl):
+            lic = re.sub('\+', '', license)
+        if fnmatch(lic, dwl):
+            return False
+    return True
+
 def incompatible_license(d, dont_want_licenses, package=None):
     """
     This function checks if a recipe has only incompatible licenses. It also
@@ -305,34 +340,21 @@ def incompatible_license(d, dont_want_licenses, package=None):
     """
     import re
     import oe.license
-    from fnmatch import fnmatchcase as fnmatch
     license = d.getVar("LICENSE_%s" % package, True) if package else None
     if not license:
         license = d.getVar('LICENSE', True)
 
-    def license_ok(license):
-        for dwl in dont_want_licenses:
-            # If you want to exclude license named generically 'X', we
-            # surely want to exclude 'X+' as well.  In consequence, we
-            # will exclude a trailing '+' character from LICENSE in
-            # case INCOMPATIBLE_LICENSE is not a 'X+' license.
-            lic = license
-            if not re.search('\+$', dwl):
-                lic = re.sub('\+', '', license)
-            if fnmatch(lic, dwl):
-                return False
-        return True
-
     # Handles an "or" or two license sets provided by
     # flattened_licenses(), pick one that works if possible.
     def choose_lic_set(a, b):
-        return a if all(license_ok(lic) for lic in a) else b
+        return a if all(license_ok(dont_want_licenses, lic) for lic in a) else b
 
     try:
         licenses = oe.license.flattened_licenses(license, choose_lic_set)
     except oe.license.LicenseError as exc:
         bb.fatal('%s: %s' % (d.getVar('P', True), exc))
-    return any(not license_ok(canonical_license(d, l)) for l in licenses)
+    return any(not license_ok(dont_want_licenses,canonical_license(d, l))
+                for l in licenses)
 
 def check_license_flags(d):
     """
-- 
1.9.1



  parent reply	other threads:[~2014-10-29 18:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-29 18:34 [PATCH 0/4] license_class: Added support for LICENSE_PRIORITY in manifest creation Aníbal Limón
2014-10-29 18:34 ` [PATCH 1/4] license_class: Reimplemented manifest creation in python Aníbal Limón
2014-10-29 21:28   ` Richard Purdie
2014-10-30 23:08     ` Aníbal Limón
2014-10-29 18:34 ` Aníbal Limón [this message]
2014-10-29 18:34 ` [PATCH 3/4] license_class: Added LICENSE_PRIORITY support Aníbal Limón
2014-10-29 18:34 ` [PATCH 4/4] license_class: Fix remove + trim in license_create_manifest Aníbal Limón
2015-02-24 16:00 ` [PATCH 0/4] license_class: Added support for LICENSE_PRIORITY in manifest creation Paul Eggleton
2015-02-24 16:05   ` Aníbal Limón
2015-02-24 17:08   ` Flanagan, Elizabeth
2015-02-26 16:34     ` Flanagan, Elizabeth
2015-02-26 17:50       ` Richard Purdie
2015-02-27 16:27         ` Aníbal Limón
2015-02-27 16:31           ` Paul Eggleton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1414607656-12144-3-git-send-email-anibal.limon@linux.intel.com \
    --to=anibal.limon@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox