Skip to contentSkip to conversation

go-vendor.bbclass: Unpack into BP for destsuffix

PATCH In review John Ripple 2 participants 4 messages Jun 22 – Jun 26

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 go-vendor.bbclass: Unpack into BP for destsuffix

The go-vendor class has a hardcoded destsuffix variable used to unpack sources fetched with the go_src_uri function. This was causing a conflict with insane.bbclass which prohibts setting S = "${UNPACKDIR}/git" which was needed to find the vendored sources in the hardcoded location. Changing this unpack location to use the standard base package name (BP) fixes the previous issue and no longer requires manually setting S in the recipes that use go-vendor.

---
 meta/classes/go-vendor.bbclass | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
meta/classes/go-vendor.bbclass +3 -2
index 6ec6178add..f854d14bdf 100644
@@ -19,7 +19,7 @@ inherit go-mod
 def go_src_uri(repo, version, path=None, subdir=None, \
                 vcs='git', replaces=None, pathmajor=None):
 
-    destsuffix = "git/src/import/vendor.fetch"
+    destsuffix = "${BP}/src/import/vendor.fetch"
     module_path = repo if not path else path
 
     src_uri = "{}://{};name={}".format(vcs, repo, module_path.replace('/', '.'))
@@ -58,7 +58,8 @@ python do_go_vendor() {
     if not src_uri:
         bb.fatal("SRC_URI is empty")
 
-    default_destsuffix = "git/src/import/vendor.fetch"
+    base_package = d.getVar('BP')
+    default_destsuffix = "{}/src/import/vendor.fetch".format(base_package)
     fetcher = bb.fetch2.Fetch(src_uri, d)
     go_import = d.getVar('GO_IMPORT')
     source_dir = d.getVar('S')
#1 lore raw

PATCH v3 2/2 go-vendor.bbclass: Remove vendor symlink

The go-vendor class creates a symlink at the end of do_go_vendor between the vendor.fetch location and the vendor folder used by go to find vendored sources. The do_vendor_unlink task originally removed the symlink created in the S directory but only after it had already been copied to the D directory.

The do_go_vendor and do_vendor_unlink tasks were never tied together. This caused file not found errors on subsequent builds where the do_vendor_unlink task was re-run without the do_go_vendor task being re-run. Leaving the symlink in S and only deleting the symlink copied to D fixes this issue.

---
 meta/classes/go-vendor.bbclass | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
meta/classes/go-vendor.bbclass +4 -6
index f854d14bdf..e879d629a8 100644
@@ -42,10 +42,9 @@ def go_src_uri(repo, version, path=None, subdir=None, \
 
 python do_vendor_unlink() {
     go_import = d.getVar('GO_IMPORT')
-    source_dir = d.getVar('S')
-    linkname = os.path.join(source_dir, *['src', go_import, 'vendor'])
-
-    os.unlink(linkname)
+    linkname = os.path.join(d.getVar('D') + d.getVar('libdir'), 'go', 'src', go_import, 'vendor')
+    if os.path.islink(linkname):
+        os.unlink(linkname)
 }
 
 addtask vendor_unlink before do_package after do_install
@@ -209,8 +208,7 @@ python do_go_vendor() {
         os.symlink(relative_symlink_target, symlink_name)
 
     # Create a symlink to the actual directory
-    relative_vendor_dir = os.path.relpath(vendor_dir, os.path.dirname(linkname))
-    os.symlink(relative_vendor_dir, linkname)
+    oe.path.relsymlink(vendor_dir, linkname)
 }
 
 addtask go_vendor before do_patch after do_unpack
#2 lore raw
In reply to John Ripple

Hi John,

Quoted 9 lines · John Ripple via lists.openembedded.org

The go-vendor class has a hardcoded destsuffix variable used to unpack sources fetched with the go_src_uri function. This was causing a conflict with insane.bbclass which prohibts setting S = "${UNPACKDIR}/git" which was needed to find the vendored sources in the hardcoded location. Changing this unpack location to use the standard base package name (BP) fixes the previous issue and no longer requires manually setting S in the recipes that use go-vendor.

Thanks for these patches. Sadly we don’t have a test case for the go-vendor class, as you clearly use it would you be able to write a small test case to verify that a recipe using the go-vendor class works? We can host little test repositories on git.yoctoproject.org if needed (for example, https://git.yoctoproject.org/recipetool-go-test/).

Many thanks,
Ross

#3 lore raw

Hi Ross,

Quoted 13 lines
Quoted 5 lines

On 23 Jun 2026, at 00:03, John Ripple via lists.openembedded.org <john.ripple=keysight.com@...> wrote:

Quoted 7 lines

The go-vendor class has a hardcoded destsuffix variable used to unpack sources fetched with the go_src_uri function. This was causing a conflict with insane.bbclass which prohibts setting S = "${UNPACKDIR}/git" which was needed to find the vendored sources in the hardcoded location. Changing this unpack location to use the standard base package name (BP) fixes the previous issue and no longer requires manually setting S in the recipes that use go-vendor.

Quoted 6 lines

Thanks for these patches. Sadly we don’t have a test case for the go-vendor class, as you clearly use it would you be able to write a small test case to verify that a recipe using the go-vendor class works? We can host little test repositories on git.yoctoproject.org if needed (for example, https://git.yoctoproject.org/recipetool-go-test/ ).

Is there anything the test should do in particular or is there a general guides for what should be tested for a bbclass? I'm not very familiar with the Yocto self test framework so any tips or documentation would be appreciated. I'll try to follow what the gotoolchain.py test does if nothing else.

John