summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2025-12-05 19:33:04 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2025-12-08 20:57:44 -0500
commitdf651f904ee91b3cf9face353af8219223442e6b (patch)
tree6a3b0eceeef219168afe291b65b38d98e5d7b11d /classes
parentae9fa39e6f52e71052ba37c54a7e0b3aea2e7ee3 (diff)
downloadmeta-virtualization-df651f904ee91b3cf9face353af8219223442e6b.tar.gz
discover: manage go.* files
The discovery repository can be in an incosistent state after a build. By restoring the go.* files, we ensure a stable start point. Add automatic removal of go.sum files from git-fetched dependencies in vcs_cache during do_create_module_cache. This prevents checksum mismatch errors caused by stale go.sum files in dependencies having different checksums than the git-sourced modules. Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'classes')
-rw-r--r--classes/go-mod-discovery.bbclass15
-rw-r--r--classes/go-mod-vcs.bbclass12
2 files changed, 27 insertions, 0 deletions
diff --git a/classes/go-mod-discovery.bbclass b/classes/go-mod-discovery.bbclass
index 05265c20..d57a7d38 100644
--- a/classes/go-mod-discovery.bbclass
+++ b/classes/go-mod-discovery.bbclass
@@ -184,9 +184,20 @@ Hint: Set GO_MOD_DISCOVERY_SRCDIR to the directory containing go.mod"
184 echo "LDFLAGS: ${GO_MOD_DISCOVERY_LDFLAGS}" 184 echo "LDFLAGS: ${GO_MOD_DISCOVERY_LDFLAGS}"
185 echo "" 185 echo ""
186 186
187 # Restore original go.sum from git if it was modified by do_create_module_cache
188 # The build task rewrites go.sum with git-based checksums, but discovery needs
189 # the original proxy-based checksums to download from proxy.golang.org
190 if git -C "${GO_MOD_DISCOVERY_SRCDIR}" diff --quiet go.sum 2>/dev/null; then
191 echo "go.sum is clean"
192 else
193 echo "Restoring original go.sum from git (was modified by previous build)..."
194 git -C "${GO_MOD_DISCOVERY_SRCDIR}" checkout go.sum
195 fi
196
187 # Use native go binary 197 # Use native go binary
188 GO_NATIVE="${STAGING_DIR_NATIVE}${bindir_native}/go" 198 GO_NATIVE="${STAGING_DIR_NATIVE}${bindir_native}/go"
189 199
200 echo ""
190 echo "Running: go build (to discover all modules)..." 201 echo "Running: go build (to discover all modules)..."
191 202
192 BUILD_CMD="${GO_NATIVE} build -v -trimpath" 203 BUILD_CMD="${GO_NATIVE} build -v -trimpath"
@@ -341,9 +352,13 @@ Add to your recipe: GO_MOD_DISCOVERY_GIT_REPO = \"https://github.com/...\"
341Or run 'bitbake ${PN} -c show_upgrade_commands' to see manual options." 352Or run 'bitbake ${PN} -c show_upgrade_commands' to see manual options."
342 fi 353 fi
343 354
355 # CRITICAL: Change to source directory so oe-go-mod-fetcher.py can find go.mod/go.sum
356 cd "${GO_MOD_DISCOVERY_SRCDIR}"
357
344 echo "======================================================================" 358 echo "======================================================================"
345 echo "GENERATING RECIPE FILES: ${PN} ${PV}" 359 echo "GENERATING RECIPE FILES: ${PN} ${PV}"
346 echo "======================================================================" 360 echo "======================================================================"
361 echo "Source dir: ${GO_MOD_DISCOVERY_SRCDIR}"
347 echo "Modules JSON: ${GO_MOD_DISCOVERY_MODULES_JSON}" 362 echo "Modules JSON: ${GO_MOD_DISCOVERY_MODULES_JSON}"
348 echo "Git repo: ${GO_MOD_DISCOVERY_GIT_REPO}" 363 echo "Git repo: ${GO_MOD_DISCOVERY_GIT_REPO}"
349 echo "Git ref: ${GO_MOD_DISCOVERY_GIT_REF}" 364 echo "Git ref: ${GO_MOD_DISCOVERY_GIT_REF}"
diff --git a/classes/go-mod-vcs.bbclass b/classes/go-mod-vcs.bbclass
index 26c8c7f3..cf583462 100644
--- a/classes/go-mod-vcs.bbclass
+++ b/classes/go-mod-vcs.bbclass
@@ -797,6 +797,18 @@ python do_create_module_cache() {
797 workdir = Path(d.getVar('WORKDIR')) 797 workdir = Path(d.getVar('WORKDIR'))
798 modules_data = json.loads(d.getVar('GO_MODULE_CACHE_DATA')) 798 modules_data = json.loads(d.getVar('GO_MODULE_CACHE_DATA'))
799 799
800 # Remove go.sum files from git-fetched dependencies to prevent checksum conflicts
801 # The module checksums from git sources differ from the proxy checksums, and stale
802 # go.sum files in dependencies can cause "checksum mismatch" errors during build
803 vcs_cache_dir = workdir / "sources" / "vcs_cache"
804 if vcs_cache_dir.exists():
805 import subprocess
806 result = subprocess.run(
807 ['find', str(vcs_cache_dir), '-name', 'go.sum', '-delete'],
808 capture_output=True, text=True
809 )
810 bb.debug(1, "Removed go.sum files from vcs_cache to prevent checksum conflicts")
811
800 bb.note(f"Building module cache for {len(modules_data)} modules") 812 bb.note(f"Building module cache for {len(modules_data)} modules")
801 813
802 # Track results from processing 814 # Track results from processing