[OE-core] [PATCH 3/4] license_class: Added LICENSE_PRIORITY support

Aníbal Limón anibal.limon at linux.intel.com
Wed Oct 29 18:34:15 UTC 2014


Now you can specify LICENSE_PRIORITY for license manifest creation.

This means that if you have LICENSE expression with OR's only one
license is selected based on LICENSE_PRIORITY and INCOMPATIBLE_LICENSE.

[YOCTO #6757]

Signed-off-by: Aníbal Limón <anibal.limon at linux.intel.com>
---
 meta/classes/license.bbclass | 47 ++++++++++++++++++++++++++++++++++++++------
 meta/conf/documentation.conf |  1 +
 2 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index c11ef1c..a055660 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -33,10 +33,45 @@ python license_create_manifest() {
     bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE", True) or "").split()
     bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses)
 
+    priority_licenses = (d.getVar("LICENSE_PRIORITY", True) or "").split()
+    priority_licenses = map(lambda l: canonical_license(d, l), priority_licenses)
+    priority_licenses.reverse()
+
+    # Get license priority based on index,
+    # INCOMPATIBLE_LICENSE entries have negative weight.
+    # Licenses not listed have a weight of 0.
+    # LICENSE_PRIORITY entries have a positive weight.
+    def get_license_priority(license):
+        # 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.
+        for bl in bad_licenses:
+            lic = license
+            if not re.search('\+$', bl):
+                lic = re.sub('\+', '', license)
+
+            if lic == bl:
+                return -1 * (bad_licenses.index(lic) + 1)
+
+        if license in priority_licenses:
+            return priority_licenses.index(license) + 1
+        else:
+            return 0
+
     # 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
+    # flattened_licenses(), pick one that works based on
+    # LICENSE_PRIORITY and INCOMPATIBLE_LICENSE.
+    def choose_lic_set(alpha, beta):
+        alpha_canonical = [canonical_license(d, l) for l in alpha]
+        beta_canonical = [canonical_license(d, l) for l in beta]
+        alpha_weight = sum(get_license_priority(a) for a in alpha_canonical)
+        beta_weight = sum(get_license_priority(b) for b in beta_canonical)
+
+        if alpha_weight >= beta_weight:
+            return alpha
+        else:
+            return beta
 
     build_images_from_feeds = d.getVar('BUILD_IMAGES_FROM_FEEDS', True)
     if build_images_from_feeds == "1":
@@ -80,12 +115,12 @@ python license_create_manifest() {
             license_file.write("LICENSE:")
 
             try:
-                licenses = oe.license.flattened_licenses(pkg_dic[pkg]["LICENSE"]
-                            , choose_lic_set)
+                pkg_dic[pkg]["FLATTENED_LICENSE"] = 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:
+            for lic in pkg_dic[pkg]["FLATTENED_LICENSE"]:
                 lic = re.sub('\+', '', lic)
                 lic_file = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
                                         pkg_dic[pkg]["PN"], "generic_%s" % lic)
diff --git a/meta/conf/documentation.conf b/meta/conf/documentation.conf
index 66ec093..d2b3057 100644
--- a/meta/conf/documentation.conf
+++ b/meta/conf/documentation.conf
@@ -220,6 +220,7 @@ IMAGE_ROOTFS_SIZE[doc] = "Defines the size in Kbytes for the generated image."
 IMAGE_TYPES[doc] = "Specifies the complete list of supported image types by default."
 INC_PR[doc] = "Helps define the recipe revision for recipes that share a common include file."
 INCOMPATIBLE_LICENSE[doc] = "Specifies a space-separated list of license names (as they would appear in LICENSE) that should be excluded from the build."
+LICENSE_PRIORITY[doc] = "Space separated list of licenses in priority order, highest to lowest."
 INHIBIT_DEFAULT_DEPS[doc] = "Prevents the default dependencies, namely the C compiler and standard C library (libc), from being added to DEPENDS."
 INHIBIT_PACKAGE_STRIP[doc] = "If set to "1", causes the build to not strip binaries in resulting packages."
 INHERIT[doc] = "Causes the named class to be inherited at this point during parsing. The variable is only valid in configuration files."
-- 
1.9.1




More information about the Openembedded-core mailing list