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>
This commit is contained in:
Christian Lindeberg
2025-09-02 16:06:46 +02:00
committed by Richard Purdie
parent 7cf52b24a5
commit 7424e8bbd0

View File

@@ -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":