Skip to content

fix(ebuild): condition-aware inherit extraction and mvdan/sh compat fixes#74

Closed
kolkov wants to merge 1 commit into
mainfrom
feat/conditional-inherit-mvdan-sh
Closed

fix(ebuild): condition-aware inherit extraction and mvdan/sh compat fixes#74
kolkov wants to merge 1 commit into
mainfrom
feat/conditional-inherit-mvdan-sh

Conversation

@kolkov
Copy link
Copy Markdown
Contributor

@kolkov kolkov commented Feb 13, 2026

Summary

  • Condition-aware inherit extraction in script.go: replaces flat syntax.Walk with a recursive AST walker that evaluates [[ ${PV} == literal ]] conditions statically, skipping eclasses behind false conditions (e.g., git-r3 for make-4.4.1 where PV != 9999)
  • mvdan.cc/sh local fixes via go.mod replace: integrates 8 bash-compat fixes from local feat/bash-compat-gentoo branch (array slicing, type -P, arithmetic operators, printf escapes, formatInto OOB panic, etc.)
  • Known vars propagation: executor passes PV/PVR/PN/P/PF to the parser for static condition evaluation

Changes

internal/ebuild/script.go (core)

  • ParseEbuildScript(path, vars) / ParseEbuildScriptFromString(content, vars) — new vars parameter
  • Custom recursive walker: walkStmts, walkNode, walkIfClause, walkCallExpr
  • evalCondition — statically evaluates [[ ${VAR} == literal ]] and glob patterns
  • pvFromPath — extracts PV from ebuild filename for auto-detection
  • Conservative fallback: walks all branches when condition can't be determined

internal/ebuild/executor.go

  • Passes ebuild vars (PV, PVR, PN, P, PF) to ParseEbuildScript

go.mod

  • replace mvdan.cc/sh/v3 => ../reference/mvdan-sh for local patched version

Tests

  • 13 new tests for conditional inherit, pattern matching, PV extraction
  • Updated all ParseEbuildScript callers in tests

Verified

  • findutils, sed, make — all three build successfully on WSL2 Gentoo
  • make no longer loads git-r3 eclass (was causing panic)
  • 23/23 bash-vs-gosh comparison tests pass identically
  • All unit tests pass with race detector

Test plan

  • go test -v -race ./internal/ebuild/... — all pass
  • golangci-lint run — 0 issues
  • WSL2: grpm emerge -k sys-apps/findutils — builds OK
  • WSL2: grpm emerge -k sys-apps/sed — builds OK
  • WSL2: grpm emerge -k dev-build/make — builds OK (no git-r3 panic)

…ixes

Replace unconditional AST walker in script.go with condition-aware
walkIfClause that statically evaluates simple [[ ${PV} == X ]]
conditions. This prevents loading eclasses from dead branches
(e.g., git-r3 for non-live ebuilds like make-4.4.1).

Also integrates local mvdan/sh fixes via go.mod replace directive:
- ${var@a}, ${var@A}, ${var@P} param expansions
- Unset array [@] fix, type -P, read -a, declare -f/-p
- !(pattern) extglob negation
- formatInto OOB panic fix for $'\0' dollar-quoting

All three previously-failing packages now build:
findutils, sed, make (dev-build/make-4.4.1-r102).
@kolkov kolkov closed this Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant