diff mbox series

[6/7] go-mod-update-modules: name unidentified licenses with a LicenseRef

Message ID 20261201034910.25521-7-tim.orling@konsulko.com
State New
Headers show
Series go-mod-update-modules: identify licenses with licensecheck | expand

Commit Message

Tim Orling Dec. 1, 2026, 3:49 a.m. UTC
A license file that is not identified was written as "Unknown", which
has no license text, so do_populate_lic failed.

Name it LicenseRef-go-<module>-<file>, warn, and point
NO_GENERIC_LICENSE at the module's own text, so that the recipe builds
and its SBOM names the file. GO_MOD_LICENSE_STRICT still fails first.

AI-Generated: Claude Opus 5.5
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 .../go-mod-update-modules.bbclass             | 28 +++++++++++++++++--
 1 file changed, 25 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/go-mod-update-modules.bbclass b/meta/classes-recipe/go-mod-update-modules.bbclass
index 030099fb0f..9ec41c7b57 100644
--- a/meta/classes-recipe/go-mod-update-modules.bbclass
+++ b/meta/classes-recipe/go-mod-update-modules.bbclass
@@ -133,13 +133,31 @@  python do_update_modules() {
                          bpn, "\n".join(f"  {f}" for f, _ in unknown),
                          "\n".join(sorted({f"  {md5},Unknown" for _, md5 in unknown}))))
 
+        # Name a license that is not identified LicenseRef-go-<module>-<file>,
+        # with NO_GENERIC_LICENSE pointing at the module's own text, as
+        # "Unknown" has no text and would fail do_populate_lic.
+        for lic_file, (node, md5) in list(lic_files.items()):
+            if not isinstance(node, oe.spdx_license.UnknownId):
+                continue
+            module, _, rest = lic_file.partition('@')
+            in_module = rest.partition('/')[2]
+            name = re.sub(r'[^A-Za-z0-9.-]+', '-', f"go-{unescape_path(module)}-{in_module}").strip('-')
+            node = oe.spdx_license.parse("LicenseRef-" + name)
+            bb.warn(f"{lic_file}: license not identified, using its own text as {node.to_string()}")
+            lic_files[lic_file] = (node, md5)
+
+        lic_dirs = [d.getVar("COMMON_LICENSE_DIR")] + (d.getVar("LICENSE_PATH") or "").split()
+        no_generic = {}
+        for lic_file, (node, _) in lic_files.items():
+            for ref in node.iter():
+                if isinstance(ref, oe.spdx_license.LicenseRef) and not any(
+                        os.path.isfile(os.path.join(ld, n)) for ld in lic_dirs for n in (ref.name, ref.ident)):
+                    no_generic.setdefault(ref.name, f"pkg/mod/{lic_file}")
+
         licenses = []
         lic_files_chksum = []
         for lic_file in lic_files:
             node, license_md5 = lic_files[lic_file]
-            if isinstance(node, oe.spdx_license.UnknownId):
-                bb.warn(f"Unknown license: {lic_file} {license_md5}")
-
             licenses.append(node)
             lic_files_chksum.append(
                 f'file://pkg/mod/{lic_file};md5={license_md5};spdx={urllib.parse.quote_plus(node.to_string())}')
@@ -156,6 +174,10 @@  python do_update_modules() {
             for lic in sorted(lic_files_chksum, key=fold_uri):
                 f.write('    ' + lic + ' \\\n')
             f.write('"\n')
+            if no_generic:
+                f.write('\n')
+            for name in sorted(no_generic):
+                f.write(f'NO_GENERIC_LICENSE[{name}] = "{no_generic[name]}"\n')
 
         #
         # Sources