diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-08-25 13:57:38 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-08-25 14:00:42 +0900 |
| commit | ac7abbbe3fa2eea01defb670abc7dc1dc336cf21 (patch) | |
| tree | cb8c451110acbd394667e94ae66c53dc422398b8 /internal/rosa/builtins.go | |
| parent | 7ee5d5368de5494350e7766a595c2bdc8f01ce80 (diff) | |
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>
Diffstat (limited to 'internal/rosa/builtins.go')
| -rw-r--r-- | internal/rosa/builtins.go | 42 |
1 files changed, 41 insertions, 1 deletions
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() } |
