classes: go-vendor: Reference local modules

Create symlinks for local modules, which are usually not referenced in
the SRC_URI, but still expected to be found in the vendor directory
during the build.

(From OE-Core rev: 16da5d9ad448aafd8b5fd63480727bd1b09ec9f1)

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Vyacheslav Yurkov 2024-01-16 09:23:20 +01:00 committed by Richard Purdie
parent 0161d08ac9
commit d5e2279d21

View File

@ -169,6 +169,7 @@ python do_go_vendor() {
fetched_paths.remove('.')
vendored_paths = set()
replaced_paths = dict()
with open(modules_txt_src) as f:
for line in f:
if not line.startswith("#"):
@ -182,6 +183,15 @@ python do_go_vendor() {
vendored_paths.add(topdir)
topdir = os.path.dirname(topdir)
else:
replaced_module = line.split("=>")
if len(replaced_module) > 1:
# This module has been replaced, use a local path
# we parse the line that has a pattern "# module-name [module-version] => local-path
actual_path = replaced_module[1].strip()
vendored_name = replaced_module[0].split()[1]
bb.debug(1, "added vendored name %s for actual path %s" % (vendored_name, actual_path))
replaced_paths[vendored_name] = actual_path
for path in fetched_paths:
if path not in vendored_paths:
@ -189,7 +199,13 @@ python do_go_vendor() {
if os.path.exists(realpath):
shutil.rmtree(realpath)
# Create a symlink the the actual directory
for vendored_name, replaced_path in replaced_paths.items():
symlink_target = os.path.join(source_dir, *['src', go_import, replaced_path])
symlink_name = os.path.join(vendor_dir, vendored_name)
bb.debug(1, "vendored name %s, symlink name %s" % (vendored_name, symlink_name))
os.symlink(symlink_target, symlink_name)
# Create a symlink to the actual directory
os.symlink(vendor_dir, linkname)
}