internal/rosa: represent runtime dependencies
All checks were successful
Test / Create distribution (push) Successful in 1m2s
Test / Sandbox (push) Successful in 3m16s
Test / Hakurei (push) Successful in 4m24s
Test / ShareFS (push) Successful in 4m30s
Test / Sandbox (race detector) (push) Successful in 6m24s
Test / Hakurei (race detector) (push) Successful in 10m8s
Test / Flake checks (push) Successful in 1m21s

This also resolves indirect dependencies, reducing noise.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-12 23:14:12 +09:00
parent faac5c4a83
commit 83653f7a0b
2 changed files with 74 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import (
"slices"
"strconv"
"strings"
"sync"
"hakurei.app/container/fhs"
"hakurei.app/internal/pkg"
@@ -454,6 +455,41 @@ type PackageAttr struct {
Flag int
}
// pa holds whether a [PArtifact] is present.
type pa = [PresetEnd]bool
// paPool holds addresses of pa.
var paPool = sync.Pool{New: func() any { return new(pa) }}
// appendPreset recursively appends a [PArtifact] and its runtime dependencies.
func (t Toolchain) appendPreset(
a []pkg.Artifact,
pv *pa, p PArtifact,
) []pkg.Artifact {
if pv[p] {
return a
}
for _, d := range GetMetadata(p).Dependencies {
a = t.appendPreset(a, pv, d)
}
return append(a, t.Load(p))
}
// AppendPresets recursively appends multiple [PArtifact] and their runtime
// dependencies.
func (t Toolchain) AppendPresets(
a []pkg.Artifact,
presets ...PArtifact,
) []pkg.Artifact {
pv := paPool.Get().(*pa)
for _, p := range presets {
a = t.appendPreset(a, pv, p)
}
paPool.Put(pv)
return a
}
// NewPackage constructs a [pkg.Artifact] via a build system helper.
func (t Toolchain) NewPackage(
name, version string,
@@ -486,12 +522,14 @@ func (t Toolchain) NewPackage(
extraRes := make([]pkg.Artifact, 0, dc)
extraRes = append(extraRes, attr.NonStage0...)
if !t.isStage0() {
pv := paPool.Get().(*pa)
for _, p := range helper.extra(attr.Flag) {
extraRes = append(extraRes, t.Load(p))
extraRes = t.appendPreset(extraRes, pv, p)
}
for _, p := range extra {
extraRes = append(extraRes, t.Load(p))
extraRes = t.appendPreset(extraRes, pv, p)
}
paPool.Put(pv)
}
var scriptEarly string