]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
classes: go-vendor: Reference local modules
authorVyacheslav Yurkov <uvv.mail@gmail.com>
Tue, 16 Jan 2024 08:23:20 +0000 (09:23 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 19 Jan 2024 11:53:56 +0000 (11:53 +0000)
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.

Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/go-vendor.bbclass

index 2426bddfba45da6073da8c2fa16e304c81dce801..b965428dd1fef4939d0cff66825f1da2096ce0bc 100644 (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)
 }