@@ -29,6 +29,40 @@ do_unpack[cleandirs] += "${GOMODCACHE}"
GO_WORKDIR ?= "${GO_IMPORT}"
do_compile[dirs] += "${B}/src/${GO_WORKDIR}"
+python do_extract_lic() {
+ import zipfile
+
+ lics = d.getVar("LIC_FILES_CHKSUM")
+ cache = d.getVar("GOMODCACHE")
+ dldir = os.path.join(cache, "cache", "download")
+ prefix = "file://pkg/mod/"
+
+ for lic in lics.split():
+ if not lic.startswith(prefix):
+ continue
+
+ try:
+ src = lic[len(prefix):].split(";")[0]
+ url, suffix = src.split("@v")
+ version, _, file = suffix.partition(os.path.sep)
+ except:
+ continue
+
+ cachefile = os.path.join(cache, src)
+ zip = os.path.join(dldir, url, "@v", "v" + version) + ".zip"
+ if os.path.exists(cachefile) or not os.path.exists(zip):
+ continue
+
+ try:
+ bb.note(f"extract {src} from {zip}")
+ bb.utils.mkdirhier(os.path.dirname(cachefile))
+ zipfile.ZipFile(zip).extract(src, cache)
+ except:
+ bb.warn(f"could not extract {src} from {zip}")
+}
+
# Make go install unpack the module zip files in the module cache directory
# before the license directory is polulated with license files.
+# Do make sure licenses get extracted for omitted modules.
+addtask do_extract_lic after do_compile before do_populate_lic
addtask do_compile before do_populate_lic