diff options
author | Christian Lindeberg <christian.lindeberg@axis.com> | 2025-09-02 16:06:47 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-09-08 18:02:39 +0100 |
commit | a25eb24eed30b3b07dcf7268e550b8711e843abb (patch) | |
tree | a8d5150f5bc4efed5ea8292335c48d3208ff45d4 /scripts/lib/recipetool | |
parent | 7424e8bbd04355d80f40de57dff0222438dcef53 (diff) | |
download | poky-a25eb24eed30b3b07dcf7268e550b8711e843abb.tar.gz |
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: 376ce22b3ba5286eda54d9f9bb1c4cd7f54ff9e7)
Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/recipetool')
-rw-r--r-- | scripts/lib/recipetool/create_go.py | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py index 4b1fa39d13..1b2e5a03d5 100644 --- a/scripts/lib/recipetool/create_go.py +++ b/scripts/lib/recipetool/create_go.py | |||
@@ -32,7 +32,6 @@ def tinfoil_init(instance): | |||
32 | tinfoil = instance | 32 | tinfoil = instance |
33 | 33 | ||
34 | 34 | ||
35 | |||
36 | class GoRecipeHandler(RecipeHandler): | 35 | class GoRecipeHandler(RecipeHandler): |
37 | """Class to handle the go recipe creation""" | 36 | """Class to handle the go recipe creation""" |
38 | 37 | ||
@@ -85,41 +84,40 @@ class GoRecipeHandler(RecipeHandler): | |||
85 | classes.append("go-mod-update-modules") | 84 | classes.append("go-mod-update-modules") |
86 | extravalues["run_tasks"] = "update_modules" | 85 | extravalues["run_tasks"] = "update_modules" |
87 | 86 | ||
88 | with tempfile.TemporaryDirectory(prefix="go-mod-") as tmp_mod_dir: | 87 | env = dict(os.environ) |
89 | env = dict(os.environ) | 88 | env["PATH"] += f":{go_bindir}" |
90 | env["PATH"] += f":{go_bindir}" | 89 | |
91 | env['GOMODCACHE'] = tmp_mod_dir | 90 | stdout = subprocess.check_output(("go", "mod", "edit", "-json"), |
92 | 91 | cwd=srctree, env=env, text=True) | |
93 | stdout = subprocess.check_output(["go", "mod", "edit", "-json"], cwd=srctree, env=env, text=True) | 92 | go_mod = json.loads(stdout) |
94 | go_mod = json.loads(stdout) | 93 | go_import = re.sub(r'/v([0-9]+)$', '', go_mod['Module']['Path']) |
95 | go_import = re.sub(r'/v([0-9]+)$', '', go_mod['Module']['Path']) | 94 | |
96 | 95 | localfilesdir = tempfile.mkdtemp(prefix='recipetool-go-') | |
97 | localfilesdir = tempfile.mkdtemp(prefix='recipetool-go-') | 96 | extravalues.setdefault('extrafiles', {}) |
98 | extravalues.setdefault('extrafiles', {}) | 97 | |
99 | 98 | # Write the stub ${BPN}-licenses.inc and ${BPN}-go-mods.inc files | |
100 | # Write the stub ${BPN}-licenses.inc and ${BPN}-go-mods.inc files | 99 | basename = "{pn}-licenses.inc" |
101 | basename = "{pn}-licenses.inc" | 100 | filename = os.path.join(localfilesdir, basename) |
102 | filename = os.path.join(localfilesdir, basename) | 101 | with open(filename, "w") as f: |
103 | with open(filename, "w") as f: | 102 | f.write("# FROM RECIPETOOL\n") |
104 | f.write("# FROM RECIPETOOL\n") | 103 | extravalues['extrafiles'][f"../{basename}"] = filename |
105 | extravalues['extrafiles'][f"../{basename}"] = filename | 104 | |
106 | 105 | basename = "{pn}-go-mods.inc" | |
107 | basename = "{pn}-go-mods.inc" | 106 | filename = os.path.join(localfilesdir, basename) |
108 | filename = os.path.join(localfilesdir, basename) | 107 | with open(filename, "w") as f: |
109 | with open(filename, "w") as f: | 108 | f.write("# FROM RECIPETOOL\n") |
110 | f.write("# FROM RECIPETOOL\n") | 109 | extravalues['extrafiles'][f"../{basename}"] = filename |
111 | extravalues['extrafiles'][f"../{basename}"] = filename | 110 | |
112 | 111 | # Do generic license handling | |
113 | # Do generic license handling | 112 | d = bb.data.createCopy(tinfoil.config_data) |
114 | d = bb.data.createCopy(tinfoil.config_data) | 113 | handle_license_vars(srctree, lines_before, handled, extravalues, d) |
115 | handle_license_vars(srctree, lines_before, handled, extravalues, d) | 114 | self.__rewrite_lic_vars(lines_before) |
116 | self.__rewrite_lic_vars(lines_before) | 115 | |
117 | 116 | self.__rewrite_src_uri(lines_before) | |
118 | self.__rewrite_src_uri(lines_before) | 117 | |
119 | 118 | lines_before.append('require ${BPN}-licenses.inc') | |
120 | lines_before.append('require ${BPN}-licenses.inc') | 119 | lines_before.append('require ${BPN}-go-mods.inc') |
121 | lines_before.append('require ${BPN}-go-mods.inc') | 120 | lines_before.append(f'GO_IMPORT = "{go_import}"') |
122 | lines_before.append(f'GO_IMPORT = "{go_import}"') | ||
123 | 121 | ||
124 | def __update_lines_before(self, updated, newlines, lines_before): | 122 | def __update_lines_before(self, updated, newlines, lines_before): |
125 | if updated: | 123 | if updated: |