diff options
author | Vyacheslav Yurkov <uvv.mail@gmail.com> | 2024-01-16 09:23:19 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-01-19 11:53:56 +0000 |
commit | 9f220f61e3e44a650a46ee997b47f1d87b7c4ef0 (patch) | |
tree | 3a79ba04f0d9e29688dedb2c70e6d979a14c7cfd /scripts | |
parent | 596b58093cde62aacfa29e12e5aa4adfde8190bf (diff) | |
download | openembedded-core-9f220f61e3e44a650a46ee997b47f1d87b7c4ef0.tar.gz |
recipetool: Don't fail on local go modules
Local modules are usually referenced with a 'replace' directive in
go.mod file. If that's the case, remove them from populating SRC_URI.
Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/recipetool/create_go.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py index 21dcb41271..668a24b8dd 100644 --- a/scripts/lib/recipetool/create_go.py +++ b/scripts/lib/recipetool/create_go.py @@ -504,7 +504,7 @@ class GoRecipeHandler(RecipeHandler): return inline_fcn, commit - def __go_handle_dependencies(self, go_mod, localfilesdir, extravalues, d): + def __go_handle_dependencies(self, go_mod, srctree, localfilesdir, extravalues, d): src_uris = [] src_revs = [] @@ -525,6 +525,27 @@ class GoRecipeHandler(RecipeHandler): return src_rev + # we first go over replacement list, because we are essentialy + # interested only in the replaced path + if go_mod['Replace']: + for replacement in go_mod['Replace']: + oldpath = replacement['Old']['Path'] + path = replacement['New']['Path'] + version = '' + if 'Version' in replacement['New']: + version = replacement['New']['Version'] + + if os.path.exists(os.path.join(srctree, path)): + # the module refers to the local path, remove it from requirement list + # because it's a local module + go_mod['Require'][:] = [v for v in go_mod['Require'] if v.get('Path') != oldpath] + else: + # Replace the path and the version, so we don't iterate replacement list anymore + for require in go_mod['Require']: + if require['Path'] == oldpath: + require.update({'Path': path, 'Version': version}) + break + for require in go_mod['Require']: path = require['Path'] version = require['Version'] @@ -534,17 +555,6 @@ class GoRecipeHandler(RecipeHandler): src_uris.append(inline_fcn) src_revs.append(generate_src_rev(path, version, commithash)) - if go_mod['Replace']: - for replacement in go_mod['Replace']: - oldpath = replacement['Old']['Path'] - path = replacement['New']['Path'] - version = replacement['New']['Version'] - - inline_fcn, commithash = self.__generate_srcuri_inline_fcn( - path, version, oldpath) - src_uris.append(inline_fcn) - src_revs.append(generate_src_rev(path, version, commithash)) - pn, _ = determine_from_url(go_mod['Module']['Path']) go_mods_basename = "%s-modules.inc" % pn @@ -693,7 +703,7 @@ class GoRecipeHandler(RecipeHandler): self.__rewrite_src_uri(lines_before, ["file://modules.txt"]) - self.__go_handle_dependencies(go_mod, localfilesdir, extravalues, d) + self.__go_handle_dependencies(go_mod, srctree, localfilesdir, extravalues, d) lines_before.append("require ${BPN}-modules.inc") # Do generic license handling |