Skip to content

Commit dc19a31

Browse files
jhofsteembriand
authored andcommitted
gomod: extract license files for omitted modules
If a gomod is omitted with a PACKAGECONFIG option its license file doesn't get extracted to the gomod cache dir and hence do_populate_lic will complain that the license file isn't found. This adds a task do_extract_lic after do_compile and before do_populate_lic to make sure the license files are extracted in such a case. (From OE-Core rev: a24e1f4d24e183574268372127455d993b8482c7) Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
1 parent 52ace71 commit dc19a31

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

meta/classes-recipe/go-mod.bbclass

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@ do_unpack[cleandirs] += "${GOMODCACHE}"
2929
GO_WORKDIR ?= "${GO_IMPORT}"
3030
do_compile[dirs] += "${B}/src/${GO_WORKDIR}"
3131

32+
python do_extract_lic() {
33+
import zipfile
34+
35+
lics = d.getVar("LIC_FILES_CHKSUM")
36+
cache = d.getVar("GOMODCACHE")
37+
dldir = os.path.join(cache, "cache", "download")
38+
prefix = "file://pkg/mod/"
39+
40+
for lic in lics.split():
41+
if not lic.startswith(prefix):
42+
continue
43+
44+
try:
45+
src = lic[len(prefix):].split(";")[0]
46+
url, suffix = src.split("@v")
47+
version, _, file = suffix.partition(os.path.sep)
48+
except:
49+
continue
50+
51+
cachefile = os.path.join(cache, src)
52+
zip = os.path.join(dldir, url, "@v", "v" + version) + ".zip"
53+
if os.path.exists(cachefile) or not os.path.exists(zip):
54+
continue
55+
56+
try:
57+
bb.note(f"extract {src} from {zip}")
58+
zipfile.ZipFile(zip).extract(src, cache)
59+
except:
60+
bb.warn(f"could not extract {src} from {zip}")
61+
}
62+
3263
# Make go install unpack the module zip files in the module cache directory
3364
# before the license directory is polulated with license files.
65+
# Do make sure licenses get extracted for omitted modules.
66+
addtask do_extract_lic after do_compile before do_populate_lic
3467
addtask do_compile before do_populate_lic

0 commit comments

Comments
 (0)