internal/rosa: read-only access to built-ins

This removes potential footguns caused by mutable builtins without requiring unnecessary clones.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
cat
2026-08-25 14:00:42 +09:00
parent 7ee5d5368d
commit ac7abbbe3f
16 changed files with 123 additions and 94 deletions
+41 -1
View File
@@ -25,7 +25,7 @@ const (
loadFlagE = `"-l$` + pkg.EnvLoad + `"`
)
// newTar wraps [pkg.NewHTTPGetTar] with a simpler function signature.
// newTar is a helper for downloading compressed tarballs.
func newTar(url, checksum string, compress uint32) pkg.Artifact {
return pkg.NewTar(
pkg.NewDecompress(
@@ -114,3 +114,43 @@ func skipGNUTests(tests ...int64) string {
}
return buf.String()
}
// builtin contains native and embedded [Artifact] registrations.
var builtin S
// New returns the address of a newly populated [S] derived from built-ins.
func New() *S { return builtin.Clone() }
// Collect returns all built-in non-excluded [ArtifactH].
func Collect() (handles P) { return builtin.Collect() }
// CollectAll returns all built-in [ArtifactH].
func CollectAll() (handles P) { return builtin.CollectAll() }
// builtinStd is the [Std] toolchain stage on builtin.
var builtinStd = builtin.Std()
// Load satisfies an [Artifact] referred to by an [ArtifactH].
func Load(handle ArtifactH) (*Metadata, pkg.Artifact) {
return builtinStd.Load(handle)
}
// LoadAt satisfies an [Artifact] referred to by an [ArtifactH] at the
// specified stage.
func LoadAt(stage Stage, handle ArtifactH) (*Metadata, pkg.Artifact) {
return builtin.New(stage).Load(handle)
}
// MustLoad is like Load, but panics if the named [Artifact] is not registered.
func MustLoad(handle ArtifactH) (*Metadata, pkg.Artifact) {
return builtinStd.MustLoad(handle)
}
// MustLoadAt is like LoadAt, but panics if the named [Artifact] is not
// registered.
func MustLoadAt(stage Stage, handle ArtifactH) (*Metadata, pkg.Artifact) {
return builtin.New(stage).MustLoad(handle)
}
// HasStageEarly returns whether a stage0 distribution is available.
func HasStageEarly() (ok bool) { return builtin.HasStageEarly() }