aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-11-22 20:06:11 +0900
committerOphestra <cat@gensokyo.uk>2026-11-22 20:08:14 +0900
commita74b427cbb5cc51cca025fc2c1401c66bee0bf1d (patch)
tree288e7aa9f2327f1f2f1f9542778a3e614623b5a2 /internal
parent4a197313d58abc9ef249be9e1934b98dbbee93cb (diff)
internal/rosa: source TOFU update helperstaging
This replaces the version value of a package declaration to acquire checksum via TOFU. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal')
-rw-r--r--internal/rosa/state.go50
1 files changed, 49 insertions, 1 deletions
diff --git a/internal/rosa/state.go b/internal/rosa/state.go
index 7bb4ebfe..d6b2e65a 100644
--- a/internal/rosa/state.go
+++ b/internal/rosa/state.go
@@ -213,6 +213,13 @@ type S struct {
// Must only be accessed after a call to getFrame.
spool sync.Pool
+ // Whether to perform TOFU attempt.
+ tofu bool
+ // Target of TOFU attempt.
+ tofuName azalea.Ident
+ // TOFU version substitute.
+ tofuVersion string
+
// Options for [pkg.Artifact] created against [S].
opts int
@@ -409,6 +416,16 @@ func (t Toolchain) Load(handle ArtifactH) (*Metadata, pkg.Artifact) {
return r.meta, r.a
}
+// LoadTOFU is like Load, but for a TOFU attempt.
+func (t Toolchain) LoadTOFU(handle ArtifactH, version string) pkg.Artifact {
+ s := t.Clone()
+ s.tofu = true
+ s.tofuName = azalea.Ident(handle.String())
+ s.tofuVersion = version
+ _, a := s.New(t.stage).Load(handle)
+ return a
+}
+
// MustLoad is like Load, but panics if the named [Artifact] is not registered.
func (t Toolchain) MustLoad(handle ArtifactH) (*Metadata, pkg.Artifact) {
meta, a := t.Load(handle)
@@ -1333,12 +1350,43 @@ func (s *S) RegisterAzalea(r io.Reader, name string, b fs.FS) error {
}
}
+ var identVersion = unique.Make(azalea.Ident("version"))
for _, f := range pending {
if !s.Register(string(f.Ident), func(t Toolchain) (*Metadata, pkg.Artifact) {
+ var sub azalea.Substitutions
+ if t.tofu {
+ sub = azalea.Substitutions{
+ t.tofuName: func(
+ name unique.Handle[azalea.Ident],
+ prev any,
+ ) (v any, ok bool) {
+ if name != identVersion {
+ return
+ }
+
+ got, _ok := prev.(string)
+ if !_ok {
+ panic(azalea.TypeError{
+ Concrete: reflect.TypeOf(prev),
+ Asserted: reflect.TypeFor[string](),
+ })
+ }
+
+ if t.tofuVersion == got {
+ panic(fmt.Errorf(
+ "superfluous TOFU attempt for %s-%s",
+ t.tofuName, t.tofuVersion,
+ ))
+ }
+ return t.tofuVersion, true
+ },
+ }
+ }
+
v, set, err := azalea.Evaluate[cachedArtifact](
(&evalContext{b, f, t}).pf,
t.getStack(),
- nil,
+ sub,
*f,
)
if err != nil {