diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/gomod.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/gomod.py | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/bitbake/lib/bb/fetch2/gomod.py b/bitbake/lib/bb/fetch2/gomod.py index 03f649bc2f..53c1d8d115 100644 --- a/bitbake/lib/bb/fetch2/gomod.py +++ b/bitbake/lib/bb/fetch2/gomod.py | |||
@@ -107,23 +107,23 @@ class GoMod(Wget): | |||
107 | if ud.path != '/': | 107 | if ud.path != '/': |
108 | module += ud.path | 108 | module += ud.path |
109 | ud.parm['module'] = module | 109 | ud.parm['module'] = module |
110 | version = ud.parm['version'] | ||
110 | 111 | ||
111 | # Set URL and filename for wget download | 112 | # Set URL and filename for wget download |
112 | path = escape(module + '/@v/' + ud.parm['version']) | ||
113 | if ud.parm.get('mod', '0') == '1': | 113 | if ud.parm.get('mod', '0') == '1': |
114 | path += '.mod' | 114 | ext = '.mod' |
115 | else: | 115 | else: |
116 | path += '.zip' | 116 | ext = '.zip' |
117 | ud.parm['unpack'] = '0' | 117 | path = escape(f"{module}/@v/{version}{ext}") |
118 | ud.url = bb.fetch2.encodeurl( | 118 | ud.url = bb.fetch2.encodeurl( |
119 | ('https', proxy, '/' + path, None, None, None)) | 119 | ('https', proxy, '/' + path, None, None, None)) |
120 | ud.parm['downloadfilename'] = path | 120 | ud.parm['downloadfilename'] = f"{module.replace('/', '.')}@{version}{ext}" |
121 | 121 | ||
122 | ud.parm['name'] = f"{module}@{ud.parm['version']}" | 122 | # Set name for checksum verification |
123 | ud.parm['name'] = f"{module}@{version}" | ||
123 | 124 | ||
124 | # Set subdir for unpack | 125 | # Set path for unpack |
125 | ud.parm['subdir'] = os.path.join(moddir, 'cache/download', | 126 | ud.parm['unpackpath'] = os.path.join(moddir, 'cache/download', path) |
126 | os.path.dirname(path)) | ||
127 | 127 | ||
128 | super().urldata_init(ud, d) | 128 | super().urldata_init(ud, d) |
129 | 129 | ||
@@ -131,13 +131,22 @@ class GoMod(Wget): | |||
131 | """Unpack the module in the module cache.""" | 131 | """Unpack the module in the module cache.""" |
132 | 132 | ||
133 | # Unpack the module zip file or go.mod file | 133 | # Unpack the module zip file or go.mod file |
134 | super().unpack(ud, rootdir, d) | 134 | unpackpath = os.path.join(rootdir, ud.parm['unpackpath']) |
135 | unpackdir = os.path.dirname(unpackpath) | ||
136 | bb.utils.mkdirhier(unpackdir) | ||
137 | ud.unpack_tracer.unpack("file-copy", unpackdir) | ||
138 | cmd = f"cp {ud.localpath} {unpackpath}" | ||
139 | path = d.getVar('PATH') | ||
140 | if path: | ||
141 | cmd = f"PATH={path} {cmd}" | ||
142 | name = os.path.basename(unpackpath) | ||
143 | bb.note(f"Unpacking {name} to {unpackdir}/") | ||
144 | subprocess.check_call(cmd, shell=True, preexec_fn=subprocess_setup) | ||
135 | 145 | ||
136 | if ud.localpath.endswith('.zip'): | 146 | if name.endswith('.zip'): |
137 | # Unpack the go.mod file from the zip file | 147 | # Unpack the go.mod file from the zip file |
138 | module = ud.parm['module'] | 148 | module = ud.parm['module'] |
139 | unpackdir = os.path.join(rootdir, ud.parm['subdir']) | 149 | name = name.rsplit('.', 1)[0] + '.mod' |
140 | name = os.path.basename(ud.localpath).rsplit('.', 1)[0] + '.mod' | ||
141 | bb.note(f"Unpacking {name} to {unpackdir}/") | 150 | bb.note(f"Unpacking {name} to {unpackdir}/") |
142 | with zipfile.ZipFile(ud.localpath) as zf: | 151 | with zipfile.ZipFile(ud.localpath) as zf: |
143 | with open(os.path.join(unpackdir, name), mode='wb') as mf: | 152 | with open(os.path.join(unpackdir, name), mode='wb') as mf: |