From ac7abbbe3fa2eea01defb670abc7dc1dc336cf21 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 25 Aug 2026 13:57:38 +0900 Subject: internal/rosa: read-only access to built-ins This removes potential footguns caused by mutable builtins without requiring unnecessary clones. Signed-off-by: Ophestra --- internal/rosa/builtins.go | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'internal/rosa/builtins.go') diff --git a/internal/rosa/builtins.go b/internal/rosa/builtins.go index 8c46779f..6d457dbd 100644 --- a/internal/rosa/builtins.go +++ b/internal/rosa/builtins.go @@ -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() } -- cgit v1.3.1