diff mbox series

[2/3] go-mod-update-modules.bbclass: Update license finding

Message ID 20250902140647.126140-3-christli@axis.com
State New
Headers show
Series Go module dependencies | expand

Commit Message

Christian Lindeberg Sept. 2, 2025, 2:06 p.m. UTC
From: Christian Lindeberg <christian.lindeberg@axis.com>

Use ${GO_INSTALL} when listing package dependencies.

Look for licenses for each package dependency continuing upwards, but not
above the module root, until some license is found.

Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com>
---
 .../go-mod-update-modules.bbclass             | 30 ++++++++-----------
 1 file changed, 12 insertions(+), 18 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 5fccd0bb0d..0083588a25 100644
--- a/meta/classes-recipe/go-mod-update-modules.bbclass
+++ b/meta/classes-recipe/go-mod-update-modules.bbclass
@@ -15,7 +15,7 @@  do_update_modules[network] = "1"
 python do_update_modules() {
     import subprocess, tempfile, json, re, urllib.parse
     from oe.license import tidy_licenses
-    from oe.license_finder import find_licenses
+    from oe.license_finder import find_licenses_up
 
     def unescape_path(path):
         """Unescape capital letters using exclamation points."""
@@ -47,12 +47,10 @@  python do_update_modules() {
 """
 
         env = dict(os.environ, GOMODCACHE=mod_cache_dir)
-
         source = d.expand("${UNPACKDIR}/${GO_SRCURI_DESTSUFFIX}")
-        output = subprocess.check_output(("go", "mod", "edit", "-json"), cwd=source, env=env, text=True)
-        go_mod = json.loads(output)
-
-        output = subprocess.check_output(("go", "list", "-json=Dir,Module", "-deps", f"{go_mod['Module']['Path']}/..."), cwd=source, env=env, text=True)
+        go_install = d.getVar("GO_INSTALL").split()
+        output = subprocess.check_output(("go", "list", "-json=Dir,Module", "-deps", *go_install),
+                                         cwd=source, env=env, text=True)
 
         #
         # Licenses
@@ -66,26 +64,22 @@  python do_update_modules() {
         # Very frustrating that the json parser in python can't repeatedly
         # parse from a stream.
         pkgs = json.loads('[' + output.replace('}\n{', '},\n{') + ']')
+
         # Collect licenses for the dependencies.
-        licenses = set()
-        lic_files_chksum = []
         lic_files = {}
-
         for pkg in pkgs:
-            mod = pkg.get('Module', None)
-            if not mod or mod.get('Main', False):
-                continue
-
-            mod_dir = mod['Dir']
-
-            if not mod_dir.startswith(mod_cache_dir):
+            pkg_dir = pkg['Dir']
+            if not pkg_dir.startswith(mod_cache_dir):
                 continue
 
+            mod_dir = pkg['Module']['Dir']
             path = os.path.relpath(mod_dir, mod_cache_dir)
 
-            for license_name, license_file, license_md5 in find_licenses(mod['Dir'], d, first_only=True, extra_hashes=extra_hashes):
-                lic_files[os.path.join(path, license_file)] = (license_name, license_md5)
+            for name, file, md5 in find_licenses_up(pkg_dir, mod_dir, d, first_only=True, extra_hashes=extra_hashes):
+                lic_files[os.path.join(path, file)] = (name, md5)
 
+        licenses = set()
+        lic_files_chksum = []
         for lic_file in lic_files:
             license_name, license_md5 = lic_files[lic_file]
             if license_name == "Unknown":