diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-05-29 13:37:32 +0000 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-05-29 13:37:32 +0000 |
| commit | 07bfa04b7718dd1b2a98c698fb1d1889de885664 (patch) | |
| tree | 61a6634d0a0aa663ec19c373fc146d6cd557d5a2 /classes | |
| parent | 18b5550b69e47883c71d6060a05e0ad69c8e4fa1 (diff) | |
| download | meta-virtualization-07bfa04b7718dd1b2a98c698fb1d1889de885664.tar.gz | |
oe-go-mod-fetcher + go-mod-discovery: add --build-target license-scan filter
The license-scan filter previously had two tiers — walk GOMODCACHE for
unpacked module dirs, falling back to `go list -m all` (the MVS set).
For recipes whose do_compile builds multiple binaries spanning a wider
import graph than the discovery step's single GO_MOD_DISCOVERY_BUILD_TARGET
(incus: 8 cmd/* binaries vs the single ./cmd/incus-migrate used by
discovery), the GOMODCACHE walk under-includes and the MVS fallback
over-includes — producing go-mod-licenses.inc entries that point to
modules bitbake never unpacks, which then trip do_populate_lic's
"invalid file" QA gate.
Add a tier-0 filter: when a recipe declares its full set of build
targets via the new GO_MOD_DISCOVERY_LICENSE_TARGETS variable, the
generator runs `go list -deps` on those targets and uses the union
of their imported modules as the filter set. This is the most accurate
signal for "what bitbake will unpack at build time" — equivalent to
what go build would resolve before bitbake's do_unpack runs.
Mechanism:
- oe-go-mod-fetcher.py: new --build-target flag (repeatable) and
_get_imported_modules() helper. Repeats over `action='append'`
so the per-target paths survive shell word-splitting in the bbclass
invocation without quoting tricks.
- go-mod-discovery.bbclass: when GO_MOD_DISCOVERY_LICENSE_TARGETS is
set, loop over its values and emit --build-target for each. The
list is space-separated in the recipe; the bbclass loop keeps
each target as its own shell word.
Tier order is now:
1. --build-target (this commit): `go list -deps` on declared targets
2. GOMODCACHE walk (existing): modules unpacked by the discovery build
3. `go list -m all` MVS-selected set (existing): full module graph
4. No filter (existing): all go.sum entries
Recipes without GO_MOD_DISCOVERY_LICENSE_TARGETS see no behavior change —
verified against cosign via a real bitbake -c discover_and_generate run
(zero diff vs HEAD on its sidecars). Incus's go-mod-licenses.inc drops
from 418 (MVS fallback) to 176 lines once the new tier is wired up,
matching the build's actual ~170 unpacked modules.
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/go-mod-discovery.bbclass | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/classes/go-mod-discovery.bbclass b/classes/go-mod-discovery.bbclass index 9609ee35..3d58811c 100644 --- a/classes/go-mod-discovery.bbclass +++ b/classes/go-mod-discovery.bbclass | |||
| @@ -79,6 +79,18 @@ | |||
| 79 | # Default: "${FILE_DIRNAME}" (recipe's directory) | 79 | # Default: "${FILE_DIRNAME}" (recipe's directory) |
| 80 | # | 80 | # |
| 81 | # GO_MOD_DISCOVERY_SKIP_LICENSES - Set to "1" to skip license scanning | 81 | # GO_MOD_DISCOVERY_SKIP_LICENSES - Set to "1" to skip license scanning |
| 82 | # | ||
| 83 | # GO_MOD_DISCOVERY_LICENSE_TARGETS - Space-separated list of go build | ||
| 84 | # targets used by the recipe's | ||
| 85 | # do_compile. When set, the license | ||
| 86 | # scan filter is derived from | ||
| 87 | # `go list -deps` on these targets | ||
| 88 | # (the most accurate filter). Useful | ||
| 89 | # when do_compile builds multiple | ||
| 90 | # binaries with a wider import graph | ||
| 91 | # than the discovery's single | ||
| 92 | # BUILD_TARGET. Falls back to the | ||
| 93 | # GOMODCACHE walk when unset. | ||
| 82 | # Default: "" (scan enabled) | 94 | # Default: "" (scan enabled) |
| 83 | # | 95 | # |
| 84 | # WORKFLOW EXAMPLES: | 96 | # WORKFLOW EXAMPLES: |
| @@ -421,6 +433,15 @@ Or run 'bitbake ${PN} -c show_upgrade_commands' to see manual options." | |||
| 421 | LICENSE_FLAGS="" | 433 | LICENSE_FLAGS="" |
| 422 | if [ "${GO_MOD_DISCOVERY_SKIP_LICENSES}" != "1" ]; then | 434 | if [ "${GO_MOD_DISCOVERY_SKIP_LICENSES}" != "1" ]; then |
| 423 | LICENSE_FLAGS="--scan-licenses --common-license-dir ${COMMON_LICENSE_DIR} --discovery-cache ${GO_MOD_DISCOVERY_DIR}/cache" | 435 | LICENSE_FLAGS="--scan-licenses --common-license-dir ${COMMON_LICENSE_DIR} --discovery-cache ${GO_MOD_DISCOVERY_DIR}/cache" |
| 436 | # If the recipe declares its full set of build targets (used by its | ||
| 437 | # own do_compile), pass each one through so the license scan can | ||
| 438 | # scope the filter via `go list -deps` rather than the discovery's | ||
| 439 | # single BUILD_TARGET-derived GOMODCACHE walk. Use repeated | ||
| 440 | # --build-target flags so the values survive shell word-splitting | ||
| 441 | # without quoting tricks. | ||
| 442 | for target in ${GO_MOD_DISCOVERY_LICENSE_TARGETS}; do | ||
| 443 | LICENSE_FLAGS="${LICENSE_FLAGS} --build-target ${target}" | ||
| 444 | done | ||
| 424 | fi | 445 | fi |
| 425 | 446 | ||
| 426 | python3 "${FETCHER_SCRIPT}" \ | 447 | python3 "${FETCHER_SCRIPT}" \ |
