From: Christian Lindeberg Date: Tue, 2 Sep 2025 14:06:46 +0000 (+0200) Subject: go-mod-update-modules.bbclass: Update license finding X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=26368cfb9180664b66bed5caf900931d08e44d38;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git 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. Signed-off-by: Christian Lindeberg Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- 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":