public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCH 1/2] create-spdx.bbclass: Simplify extraction of license text
@ 2022-03-23 23:14 Peter Kjellerstedt
  2022-03-23 23:14 ` [PATCH 2/2] license.bbclass: Remove the available_licenses() function Peter Kjellerstedt
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Kjellerstedt @ 2022-03-23 23:14 UTC (permalink / raw)
  To: openembedded-core

There is no reason to first search for all available licenses using
avail_licenses() and then search through the same paths looking for
the actual license texts. Just look for the license texts directly
instead.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---
 meta/classes/create-spdx.bbclass | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index 1a4804a7c5..cae8cccd8d 100644
--- a/meta/classes/create-spdx.bbclass
+++ b/meta/classes/create-spdx.bbclass
@@ -94,7 +94,6 @@ def convert_license_to_spdx(lic, document, d, existing={}):
     from pathlib import Path
     import oe.spdx
 
-    avail_licenses = available_licenses(d)
     license_data = d.getVar("SPDX_LICENSE_DATA")
     extracted = {}
 
@@ -112,8 +111,8 @@ def convert_license_to_spdx(lic, document, d, existing={}):
         if name == "PD":
             # Special-case this.
             extracted_info.extractedText = "Software released to the public domain"
-        elif name in avail_licenses:
-            # This license can be found in COMMON_LICENSE_DIR or LICENSE_PATH
+        else:
+            # Seach for the license in COMMON_LICENSE_DIR and LICENSE_PATH
             for directory in [d.getVar('COMMON_LICENSE_DIR')] + (d.getVar('LICENSE_PATH') or '').split():
                 try:
                     with (Path(directory) / name).open(errors="replace") as f:
@@ -122,18 +121,14 @@ def convert_license_to_spdx(lic, document, d, existing={}):
                 except FileNotFoundError:
                     pass
             if extracted_info.extractedText is None:
-                # Error out, as the license was in avail_licenses so should
-                # be on disk somewhere.
-                bb.error("Cannot find text for license %s" % name)
-        else:
-            # If it's not SPDX, or PD, or in avail_licenses, then NO_GENERIC_LICENSE must be set
-            filename = d.getVarFlag('NO_GENERIC_LICENSE', name)
-            if filename:
-                filename = d.expand("${S}/" + filename)
-                with open(filename, errors="replace") as f:
-                    extracted_info.extractedText = f.read()
-            else:
-                bb.error("Cannot find any text for license %s" % name)
+                # If it's not SPDX or PD, then NO_GENERIC_LICENSE must be set
+                filename = d.getVarFlag('NO_GENERIC_LICENSE', name)
+                if filename:
+                    filename = d.expand("${S}/" + filename)
+                    with open(filename, errors="replace") as f:
+                        extracted_info.extractedText = f.read()
+                else:
+                    bb.error("Cannot find any text for license %s" % name)
 
         extracted[name] = extracted_info
         document.hasExtractedLicensingInfos.append(extracted_info)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] license.bbclass: Remove the available_licenses() function
  2022-03-23 23:14 [PATCH 1/2] create-spdx.bbclass: Simplify extraction of license text Peter Kjellerstedt
@ 2022-03-23 23:14 ` Peter Kjellerstedt
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Kjellerstedt @ 2022-03-23 23:14 UTC (permalink / raw)
  To: openembedded-core

It is no longer used in OE-Core.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---
 meta/classes/license.bbclass | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index 813e1ea4f5..0c637e966e 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -256,21 +256,6 @@ def canonical_license(d, license):
     """
     return d.getVarFlag('SPDXLICENSEMAP', license) or license
 
-def available_licenses(d):
-    """
-    Return the available licenses by searching the directories specified by
-    COMMON_LICENSE_DIR and LICENSE_PATH.
-    """
-    lic_dirs = ((d.getVar('COMMON_LICENSE_DIR') or '') + ' ' +
-                (d.getVar('LICENSE_PATH') or '')).split()
-
-    licenses = []
-    for lic_dir in lic_dirs:
-        licenses += os.listdir(lic_dir)
-
-    licenses = sorted(licenses)
-    return licenses
-
 def expand_wildcard_licenses(d, wildcard_licenses):
     """
     There are some common wildcard values users may want to use. Support them


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-23 23:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-23 23:14 [PATCH 1/2] create-spdx.bbclass: Simplify extraction of license text Peter Kjellerstedt
2022-03-23 23:14 ` [PATCH 2/2] license.bbclass: Remove the available_licenses() function Peter Kjellerstedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox