summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Lindeberg <christian.lindeberg@axis.com>2025-09-02 16:06:46 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-09-08 18:02:39 +0100
commit7424e8bbd04355d80f40de57dff0222438dcef53 (patch)
treed1865ac4c917c9003bbb699821a08ccb12bdc12d
parent7cf52b24a5a105a5933e6d1c38678dfe432fc5d9 (diff)
downloadpoky-7424e8bbd04355d80f40de57dff0222438dcef53.tar.gz
go-mod-update-modules.bbclass: Update license finding
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. (From OE-Core rev: 26368cfb9180664b66bed5caf900931d08e44d38) Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-recipe/go-mod-update-modules.bbclass30
1 files changed, 12 insertions, 18 deletions
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"
15python do_update_modules() { 15python do_update_modules() {
16 import subprocess, tempfile, json, re, urllib.parse 16 import subprocess, tempfile, json, re, urllib.parse
17 from oe.license import tidy_licenses 17 from oe.license import tidy_licenses
18 from oe.license_finder import find_licenses 18 from oe.license_finder import find_licenses_up
19 19
20 def unescape_path(path): 20 def unescape_path(path):
21 """Unescape capital letters using exclamation points.""" 21 """Unescape capital letters using exclamation points."""
@@ -47,12 +47,10 @@ python do_update_modules() {
47""" 47"""
48 48
49 env = dict(os.environ, GOMODCACHE=mod_cache_dir) 49 env = dict(os.environ, GOMODCACHE=mod_cache_dir)
50
51 source = d.expand("${UNPACKDIR}/${GO_SRCURI_DESTSUFFIX}") 50 source = d.expand("${UNPACKDIR}/${GO_SRCURI_DESTSUFFIX}")
52 output = subprocess.check_output(("go", "mod", "edit", "-json"), cwd=source, env=env, text=True) 51 go_install = d.getVar("GO_INSTALL").split()
53 go_mod = json.loads(output) 52 output = subprocess.check_output(("go", "list", "-json=Dir,Module", "-deps", *go_install),
54 53 cwd=source, env=env, text=True)
55 output = subprocess.check_output(("go", "list", "-json=Dir,Module", "-deps", f"{go_mod['Module']['Path']}/..."), cwd=source, env=env, text=True)
56 54
57 # 55 #
58 # Licenses 56 # Licenses
@@ -66,26 +64,22 @@ python do_update_modules() {
66 # Very frustrating that the json parser in python can't repeatedly 64 # Very frustrating that the json parser in python can't repeatedly
67 # parse from a stream. 65 # parse from a stream.
68 pkgs = json.loads('[' + output.replace('}\n{', '},\n{') + ']') 66 pkgs = json.loads('[' + output.replace('}\n{', '},\n{') + ']')
67
69 # Collect licenses for the dependencies. 68 # Collect licenses for the dependencies.
70 licenses = set()
71 lic_files_chksum = []
72 lic_files = {} 69 lic_files = {}
73
74 for pkg in pkgs: 70 for pkg in pkgs:
75 mod = pkg.get('Module', None) 71 pkg_dir = pkg['Dir']
76 if not mod or mod.get('Main', False): 72 if not pkg_dir.startswith(mod_cache_dir):
77 continue
78
79 mod_dir = mod['Dir']
80
81 if not mod_dir.startswith(mod_cache_dir):
82 continue 73 continue
83 74
75 mod_dir = pkg['Module']['Dir']
84 path = os.path.relpath(mod_dir, mod_cache_dir) 76 path = os.path.relpath(mod_dir, mod_cache_dir)
85 77
86 for license_name, license_file, license_md5 in find_licenses(mod['Dir'], d, first_only=True, extra_hashes=extra_hashes): 78 for name, file, md5 in find_licenses_up(pkg_dir, mod_dir, d, first_only=True, extra_hashes=extra_hashes):
87 lic_files[os.path.join(path, license_file)] = (license_name, license_md5) 79 lic_files[os.path.join(path, file)] = (name, md5)
88 80
81 licenses = set()
82 lic_files_chksum = []
89 for lic_file in lic_files: 83 for lic_file in lic_files:
90 license_name, license_md5 = lic_files[lic_file] 84 license_name, license_md5 = lic_files[lic_file]
91 if license_name == "Unknown": 85 if license_name == "Unknown":