Skip to content

Commit c63cb44

Browse files
chrislindebergmbriand
authored andcommitted
recipetool/create_go: Tidy up a bit
There is no need for a temporary Go module cache after moving generation of module dependency include files to go-mod-update-modules.bbclass. (From OE-Core rev: 658f2b33ff22eab76bba045bb417e5fd19074c04) Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
1 parent a4c6c0a commit c63cb44

1 file changed

Lines changed: 34 additions & 36 deletions

File tree

scripts/lib/recipetool/create_go.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def tinfoil_init(instance):
3232
tinfoil = instance
3333

3434

35-
3635
class GoRecipeHandler(RecipeHandler):
3736
"""Class to handle the go recipe creation"""
3837

@@ -85,41 +84,40 @@ def process(self, srctree, classes, lines_before,
8584
classes.append("go-mod-update-modules")
8685
extravalues["run_tasks"] = "update_modules"
8786

88-
with tempfile.TemporaryDirectory(prefix="go-mod-") as tmp_mod_dir:
89-
env = dict(os.environ)
90-
env["PATH"] += f":{go_bindir}"
91-
env['GOMODCACHE'] = tmp_mod_dir
92-
93-
stdout = subprocess.check_output(["go", "mod", "edit", "-json"], cwd=srctree, env=env, text=True)
94-
go_mod = json.loads(stdout)
95-
go_import = re.sub(r'/v([0-9]+)$', '', go_mod['Module']['Path'])
96-
97-
localfilesdir = tempfile.mkdtemp(prefix='recipetool-go-')
98-
extravalues.setdefault('extrafiles', {})
99-
100-
# Write the stub ${BPN}-licenses.inc and ${BPN}-go-mods.inc files
101-
basename = "{pn}-licenses.inc"
102-
filename = os.path.join(localfilesdir, basename)
103-
with open(filename, "w") as f:
104-
f.write("# FROM RECIPETOOL\n")
105-
extravalues['extrafiles'][f"../{basename}"] = filename
106-
107-
basename = "{pn}-go-mods.inc"
108-
filename = os.path.join(localfilesdir, basename)
109-
with open(filename, "w") as f:
110-
f.write("# FROM RECIPETOOL\n")
111-
extravalues['extrafiles'][f"../{basename}"] = filename
112-
113-
# Do generic license handling
114-
d = bb.data.createCopy(tinfoil.config_data)
115-
handle_license_vars(srctree, lines_before, handled, extravalues, d)
116-
self.__rewrite_lic_vars(lines_before)
117-
118-
self.__rewrite_src_uri(lines_before)
119-
120-
lines_before.append('require ${BPN}-licenses.inc')
121-
lines_before.append('require ${BPN}-go-mods.inc')
122-
lines_before.append(f'GO_IMPORT = "{go_import}"')
87+
env = dict(os.environ)
88+
env["PATH"] += f":{go_bindir}"
89+
90+
stdout = subprocess.check_output(("go", "mod", "edit", "-json"),
91+
cwd=srctree, env=env, text=True)
92+
go_mod = json.loads(stdout)
93+
go_import = re.sub(r'/v([0-9]+)$', '', go_mod['Module']['Path'])
94+
95+
localfilesdir = tempfile.mkdtemp(prefix='recipetool-go-')
96+
extravalues.setdefault('extrafiles', {})
97+
98+
# Write the stub ${BPN}-licenses.inc and ${BPN}-go-mods.inc files
99+
basename = "{pn}-licenses.inc"
100+
filename = os.path.join(localfilesdir, basename)
101+
with open(filename, "w") as f:
102+
f.write("# FROM RECIPETOOL\n")
103+
extravalues['extrafiles'][f"../{basename}"] = filename
104+
105+
basename = "{pn}-go-mods.inc"
106+
filename = os.path.join(localfilesdir, basename)
107+
with open(filename, "w") as f:
108+
f.write("# FROM RECIPETOOL\n")
109+
extravalues['extrafiles'][f"../{basename}"] = filename
110+
111+
# Do generic license handling
112+
d = bb.data.createCopy(tinfoil.config_data)
113+
handle_license_vars(srctree, lines_before, handled, extravalues, d)
114+
self.__rewrite_lic_vars(lines_before)
115+
116+
self.__rewrite_src_uri(lines_before)
117+
118+
lines_before.append('require ${BPN}-licenses.inc')
119+
lines_before.append('require ${BPN}-go-mods.inc')
120+
lines_before.append(f'GO_IMPORT = "{go_import}"')
123121

124122
def __update_lines_before(self, updated, newlines, lines_before):
125123
if updated:

0 commit comments

Comments
 (0)