diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-01-04 11:40:15 -0500 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-01-04 11:40:15 -0500 |
| commit | dbf720ccb0519a4dbf143dbaed1633527b8d7b60 (patch) | |
| tree | 16c72e1b58d63d1a116a3a91b02e13646ba8bee0 /classes | |
| parent | d7434129524162f356c3cd154f46a395c9076df7 (diff) | |
| download | meta-virtualization-dbf720ccb0519a4dbf143dbaed1633527b8d7b60.tar.gz | |
go-mod-fetcher: fix shallow clone handling, duplicates, and discovery workflow
oe-go-mod-fetcher.py:
- Remove BB_GIT_SHALLOW_EXTRA_REFS generation - refs must be present in
ALL repositories which isn't the case for module dependencies. Instead,
use tag= parameter in individual SRC_URI entries.
- Add tag=<tagname> to SRC_URI when ref is a tag, allowing BitBake's
shallow clone to include the necessary tag (with BB_GIT_SHALLOW=1)
- Remove premature _ref_points_to_commit() check that was clearing
ref_hints before repos were fetched, preventing tag= from being added
- Fix pseudo-version verification: only use shallow fetch for actual
tags (refs/tags/...), not branch refs. Pseudo-versions with branch
refs (refs/heads/...) now correctly use unshallow path to reach
historical commits that aren't fetchable with depth=1
oe-go-mod-fetcher-hybrid.py:
- Fix duplicate SRC_URI entries when multiple modules share the same
git repo/commit (e.g., errdefs and errdefs/pkg). Track added vcs_hashes
to skip duplicates.
- Add --discovery-cache option to calculate module sizes from discovery
cache .zip files, enabling size recommendations during discover_and_generate
go-mod-discovery.bbclass:
- Add automatic hybrid mode recommendations after generate_modules,
showing module sizes and suggested --git prefixes for conversion
- Add GO_MOD_DISCOVERY_SKIP_VERIFY variable to skip commit verification
on retries (useful after fixing verification issues)
- Pass --discovery-cache to hybrid script for accurate size calculations
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/go-mod-discovery.bbclass | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/classes/go-mod-discovery.bbclass b/classes/go-mod-discovery.bbclass index fc7c2008..d41d70a5 100644 --- a/classes/go-mod-discovery.bbclass +++ b/classes/go-mod-discovery.bbclass | |||
| @@ -117,6 +117,11 @@ GO_MOD_DISCOVERY_GIT_REF ?= "${SRCREV}" | |||
| 117 | # Recipe directory for generated .inc files - defaults to recipe's directory | 117 | # Recipe directory for generated .inc files - defaults to recipe's directory |
| 118 | GO_MOD_DISCOVERY_RECIPEDIR ?= "${FILE_DIRNAME}" | 118 | GO_MOD_DISCOVERY_RECIPEDIR ?= "${FILE_DIRNAME}" |
| 119 | 119 | ||
| 120 | # Skip commit verification during generation (use cached results only) | ||
| 121 | # Set to "1" to skip verification on retries after initial discovery | ||
| 122 | # Usage: GO_MOD_DISCOVERY_SKIP_VERIFY = "1" in local.conf or recipe | ||
| 123 | GO_MOD_DISCOVERY_SKIP_VERIFY ?= "" | ||
| 124 | |||
| 120 | # Empty default for TAGS if not set by recipe (avoids undefined variable errors) | 125 | # Empty default for TAGS if not set by recipe (avoids undefined variable errors) |
| 121 | TAGS ?= "" | 126 | TAGS ?= "" |
| 122 | 127 | ||
| @@ -384,11 +389,19 @@ Or run 'bitbake ${PN} -c show_upgrade_commands' to see manual options." | |||
| 384 | bbfatal "Could not find oe-go-mod-fetcher.py in any layer" | 389 | bbfatal "Could not find oe-go-mod-fetcher.py in any layer" |
| 385 | fi | 390 | fi |
| 386 | 391 | ||
| 392 | # Build fetcher command with optional flags | ||
| 393 | SKIP_VERIFY_FLAG="" | ||
| 394 | if [ "${GO_MOD_DISCOVERY_SKIP_VERIFY}" = "1" ]; then | ||
| 395 | echo "NOTE: Skipping commit verification (GO_MOD_DISCOVERY_SKIP_VERIFY=1)" | ||
| 396 | SKIP_VERIFY_FLAG="--skip-verify" | ||
| 397 | fi | ||
| 398 | |||
| 387 | python3 "${FETCHER_SCRIPT}" \ | 399 | python3 "${FETCHER_SCRIPT}" \ |
| 388 | --discovered-modules "${GO_MOD_DISCOVERY_MODULES_JSON}" \ | 400 | --discovered-modules "${GO_MOD_DISCOVERY_MODULES_JSON}" \ |
| 389 | --git-repo "${GO_MOD_DISCOVERY_GIT_REPO}" \ | 401 | --git-repo "${GO_MOD_DISCOVERY_GIT_REPO}" \ |
| 390 | --git-ref "${GO_MOD_DISCOVERY_GIT_REF}" \ | 402 | --git-ref "${GO_MOD_DISCOVERY_GIT_REF}" \ |
| 391 | --recipedir "${GO_MOD_DISCOVERY_RECIPEDIR}" | 403 | --recipedir "${GO_MOD_DISCOVERY_RECIPEDIR}" \ |
| 404 | ${SKIP_VERIFY_FLAG} | ||
| 392 | 405 | ||
| 393 | if [ $? -eq 0 ]; then | 406 | if [ $? -eq 0 ]; then |
| 394 | echo "" | 407 | echo "" |
| @@ -411,6 +424,70 @@ addtask generate_modules | |||
| 411 | do_generate_modules[nostamp] = "1" | 424 | do_generate_modules[nostamp] = "1" |
| 412 | do_generate_modules[vardeps] += "GO_MOD_DISCOVERY_MODULES_JSON GO_MOD_DISCOVERY_GIT_REPO \ | 425 | do_generate_modules[vardeps] += "GO_MOD_DISCOVERY_MODULES_JSON GO_MOD_DISCOVERY_GIT_REPO \ |
| 413 | GO_MOD_DISCOVERY_GIT_REF GO_MOD_DISCOVERY_RECIPEDIR" | 426 | GO_MOD_DISCOVERY_GIT_REF GO_MOD_DISCOVERY_RECIPEDIR" |
| 427 | do_generate_modules[postfuncs] = "do_show_hybrid_recommendation" | ||
| 428 | |||
| 429 | # Show hybrid conversion recommendations after VCS generation | ||
| 430 | python do_show_hybrid_recommendation() { | ||
| 431 | """ | ||
| 432 | Show recommendations for converting to hybrid gomod:// + git:// mode. | ||
| 433 | Runs automatically after generate_modules completes. | ||
| 434 | """ | ||
| 435 | import subprocess | ||
| 436 | from pathlib import Path | ||
| 437 | |||
| 438 | recipedir = d.getVar('GO_MOD_DISCOVERY_RECIPEDIR') | ||
| 439 | git_inc = Path(recipedir) / 'go-mod-git.inc' | ||
| 440 | |||
| 441 | if not git_inc.exists(): | ||
| 442 | return | ||
| 443 | |||
| 444 | # Find the hybrid script | ||
| 445 | layerdir = None | ||
| 446 | for layer in d.getVar('BBLAYERS').split(): | ||
| 447 | if 'meta-virtualization' in layer: | ||
| 448 | layerdir = layer | ||
| 449 | break | ||
| 450 | |||
| 451 | if not layerdir: | ||
| 452 | return | ||
| 453 | |||
| 454 | scriptpath = Path(layerdir) / "scripts" / "oe-go-mod-fetcher-hybrid.py" | ||
| 455 | if not scriptpath.exists(): | ||
| 456 | return | ||
| 457 | |||
| 458 | bb.plain("") | ||
| 459 | bb.plain("=" * 70) | ||
| 460 | bb.plain("HYBRID MODE RECOMMENDATION") | ||
| 461 | bb.plain("=" * 70) | ||
| 462 | |||
| 463 | cmd = ['python3', str(scriptpath), '--recipedir', recipedir, '--recommend'] | ||
| 464 | |||
| 465 | # Try to find module sizes from discovery cache or vcs_cache | ||
| 466 | discovery_dir = d.getVar('GO_MOD_DISCOVERY_DIR') | ||
| 467 | workdir = d.getVar('WORKDIR') | ||
| 468 | |||
| 469 | # Check discovery cache first (has .zip files with accurate sizes) | ||
| 470 | if discovery_dir: | ||
| 471 | discovery_cache = Path(discovery_dir) / 'cache' / 'cache' / 'download' | ||
| 472 | if discovery_cache.exists(): | ||
| 473 | cmd.extend(['--discovery-cache', str(discovery_cache)]) | ||
| 474 | |||
| 475 | # Also check vcs_cache if it exists (from a previous build) | ||
| 476 | if workdir: | ||
| 477 | vcs_cache = Path(workdir) / 'sources' / 'vcs_cache' | ||
| 478 | if vcs_cache.exists(): | ||
| 479 | cmd.extend(['--workdir', workdir]) | ||
| 480 | |||
| 481 | try: | ||
| 482 | result = subprocess.run(cmd, capture_output=True, text=True, timeout=120) | ||
| 483 | if result.stdout: | ||
| 484 | for line in result.stdout.splitlines(): | ||
| 485 | bb.plain(line) | ||
| 486 | bb.plain("") | ||
| 487 | bb.plain("") | ||
| 488 | except Exception as e: | ||
| 489 | bb.note(f"Could not run hybrid recommendation: {e}") | ||
| 490 | } | ||
| 414 | 491 | ||
| 415 | # ============================================================================= | 492 | # ============================================================================= |
| 416 | # TASK 4: do_discover_and_generate - All-in-one convenience task | 493 | # TASK 4: do_discover_and_generate - All-in-one convenience task |
| @@ -443,7 +520,7 @@ addtask discover_and_generate after do_unpack | |||
| 443 | do_discover_and_generate[depends] = "${PN}:do_prepare_recipe_sysroot" | 520 | do_discover_and_generate[depends] = "${PN}:do_prepare_recipe_sysroot" |
| 444 | do_discover_and_generate[network] = "1" | 521 | do_discover_and_generate[network] = "1" |
| 445 | do_discover_and_generate[nostamp] = "1" | 522 | do_discover_and_generate[nostamp] = "1" |
| 446 | do_discover_and_generate[postfuncs] = "do_discover_modules do_extract_modules do_generate_modules" | 523 | do_discover_and_generate[postfuncs] = "do_discover_modules do_extract_modules do_generate_modules do_show_hybrid_recommendation" |
| 447 | 524 | ||
| 448 | # ============================================================================= | 525 | # ============================================================================= |
| 449 | # TASK: do_clean_discovery - Clean the persistent cache | 526 | # TASK: do_clean_discovery - Clean the persistent cache |
