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>
This commit is contained in:
2026-05-18 22:00:52 +09:00
parent 34822925e1
commit 594221eb78
7 changed files with 235 additions and 184 deletions

View File

@@ -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,