aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/state.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-05-18 22:00:52 +0900
committerOphestra <cat@gensokyo.uk>2026-05-18 22:06:00 +0900
commit594221eb78fede12840121982782a470e6ed29d0 (patch)
tree84142dce80eb59e4b8b0a2babad2777de5c37c85 /internal/rosa/state.go
parent34822925e18cb35e1815d3837a8b55169953d876 (diff)
internal/rosa/package: migrate gnutls
This is the first nontrivial package to be migrated to azalea. Validated to generate identical IR. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/rosa/state.go')
-rw-r--r--internal/rosa/state.go71
1 files changed, 68 insertions, 3 deletions
diff --git a/internal/rosa/state.go b/internal/rosa/state.go
index fd363faf..efb51d96 100644
--- a/internal/rosa/state.go
+++ b/internal/rosa/state.go
@@ -8,6 +8,7 @@ import (
"io/fs"
"net/http"
"path/filepath"
+ "reflect"
"runtime"
"slices"
"strconv"
@@ -373,6 +374,13 @@ func (s *S) Collect() (handles P) {
return
}
+// deferredGit is a call to Toolchain.newTagRemote from azalea.
+type deferredGit struct {
+ url string
+ tag string
+ checksum string
+}
+
// getS must be called before accessing s. This value is not currently safe for
// concurrent use, but the underlying frame is immutable.
func (s *S) getS() []azalea.Frame {
@@ -381,6 +389,12 @@ func (s *S) getS() []azalea.Frame {
k := func(name string) unique.Handle[azalea.Ident] {
return unique.Make(azalea.Ident(name))
}
+
+ var (
+ identDefault = k("default")
+ identArch = k(s.arch)
+ )
+
s.s = make([]azalea.Frame, 1, 1<<4)
s.s[0].Val = map[unique.Handle[azalea.Ident]]any{
k("jobsE"): jobsE,
@@ -428,9 +442,45 @@ func (s *S) getS() []azalea.Frame {
return
}},
+ // state helpers
+
+ k("arch"): {F: func(
+ args azalea.FArgs,
+ ) (v any, set bool, err error) {
+ var fallback any
+ for _, arg := range args {
+ switch arg.K {
+ case identDefault:
+ fallback = arg.V
+ continue
+
+ case identArch:
+ return arg.V, true, nil
+ }
+ }
+
+ return fallback, fallback != nil, nil
+ }},
+
// convenience functions
- unique.Make(azalea.Ident("remoteGitLab")): {F: func(
+ k("remoteGit"): {F: func(
+ args azalea.FArgs,
+ ) (v any, set bool, err error) {
+ var a deferredGit
+ if err = args.Apply(map[unique.Handle[azalea.Ident]]any{
+ k("url"): &a.url,
+ k("tag"): &a.tag,
+ k("checksum"): &a.checksum,
+ }); err != nil {
+ return
+ }
+ v = a
+ set = true
+ return
+ }},
+
+ k("remoteGitLab"): {F: func(
args azalea.FArgs,
) (v any, set bool, err error) {
var domain, suffix, ref, checksum string
@@ -526,7 +576,7 @@ func (ctx *evalContext) f(
anitya int64
version string
- source pkg.Artifact
+ sourceA any
helper Helper
inputs, runtimes azalea.Array
@@ -537,7 +587,7 @@ func (ctx *evalContext) f(
k("anitya"): &anitya,
k("version"): &version,
- k("source"): &source,
+ k("source"): &sourceA,
k("writable"): &attr.Writable,
k("chmod"): &attr.Chmod,
@@ -581,6 +631,21 @@ func (ctx *evalContext) f(
meta.ID = int(anitya)
meta.f = func(t Toolchain) (pkg.Artifact, string) {
+ var source pkg.Artifact
+ switch p := sourceA.(type) {
+ case pkg.Artifact:
+ source = p
+
+ case deferredGit:
+ source = t.newTagRemote(p.url, p.tag, p.checksum)
+
+ default:
+ panic(azalea.TypeError{
+ Concrete: reflect.TypeOf(sourceA),
+ Asserted: reflect.TypeFor[pkg.Artifact](),
+ })
+ }
+
return t.NewPackage(
meta.Name,
version,