internal/rosa/meson: migrate to helper interface
All checks were successful
Test / Create distribution (push) Successful in 57s
Test / Sandbox (push) Successful in 2m57s
Test / Hakurei (push) Successful in 4m4s
Test / ShareFS (push) Successful in 4m21s
Test / Sandbox (race detector) (push) Successful in 5m15s
Test / Hakurei (race detector) (push) Successful in 6m12s
Test / Flake checks (push) Successful in 1m26s

This change also removes some unused options.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-02 14:07:16 +09:00
parent 145ccd1c92
commit 04d9984da0
6 changed files with 123 additions and 124 deletions

View File

@@ -31,49 +31,59 @@ python3 setup.py \
}
func init() { artifactsF[Meson] = Toolchain.newMeson }
// MesonAttr holds the project-specific attributes that will be applied to a new
// [pkg.Artifact] compiled via [Meson].
type MesonAttr struct {
// Mount the source tree writable.
Writable bool
// Additional environment variables.
Env []string
// Runs before setup.
ScriptEarly string
// Runs after configure.
// MesonHelper is the [Meson] build system helper.
type MesonHelper struct {
// Runs after setup.
ScriptCompileEarly string
// Runs after compile.
ScriptCompiled string
// Runs after install.
Script string
// Flags passed to the setup command.
Configure [][2]string
Setup [][2]string
// Whether to skip meson test.
SkipCheck bool
// Appended after the test command.
AppendTest string
// Suffix appended to the source pathname.
SourceSuffix string
// Passed through to [Toolchain.New], before source.
Paths []pkg.ExecPath
// Passed through to [Toolchain.New].
Flag int
SkipTest bool
}
// NewViaMeson returns a [pkg.Artifact] for compiling and installing via [Meson].
func (t Toolchain) NewViaMeson(
name, version string,
source pkg.Artifact,
attr *MesonAttr,
extra ...pkg.Artifact,
) pkg.Artifact {
if name == "" || version == "" {
panic("names must be non-empty")
var _ Helper = new(MesonHelper)
// name returns its arguments joined with '-'.
func (*MesonHelper) name(name, version string) string {
return name + "-" + version
}
// extra returns hardcoded meson runtime dependencies.
func (*MesonHelper) extra(int) []PArtifact {
return []PArtifact{
Python,
Meson,
Ninja,
PkgConfig,
CMake,
}
}
// wantsChmod returns false.
func (*MesonHelper) wantsChmod() bool { return false }
// wantsWrite returns false.
func (*MesonHelper) wantsWrite() bool { return false }
// scriptEarly returns the zero value.
func (*MesonHelper) scriptEarly() string { return "" }
// createDir returns false.
func (*MesonHelper) createDir() bool { return false }
// wantsDir requests a new directory in TMPDIR.
func (*MesonHelper) wantsDir() string { return `"$(mktemp -d)"` }
// script generates the cure script.
func (attr *MesonHelper) script(name string) string {
if attr == nil {
attr = new(MesonAttr)
attr = new(MesonHelper)
}
scriptCompiled := attr.ScriptCompiled
@@ -81,26 +91,21 @@ func (t Toolchain) NewViaMeson(
scriptCompiled = "\n" + scriptCompiled
}
var check string
if !attr.SkipCheck {
check = "\nmeson test \\\n\t--print-errorlogs" + attr.AppendTest
var scriptTest string
if !attr.SkipTest {
scriptTest = `
meson test \
--print-errorlogs`
}
return t.New(name+"-"+version, attr.Flag, slices.Concat([]pkg.Artifact{
t.Load(Python),
t.Load(Meson),
t.Load(Ninja),
t.Load(PkgConfig),
t.Load(CMake),
}, extra), nil, attr.Env, attr.ScriptEarly+`
return `
cd "$(mktemp -d)"
meson setup \
`+strings.Join(slices.Collect(func(yield func(string) bool) {
` + strings.Join(slices.Collect(func(yield func(string) bool) {
for _, v := range append([][2]string{
{"prefix", "/system"},
{"buildtype", "release"},
}, attr.Configure...) {
}, attr.Setup...) {
s := "-" + v[0]
if len(v[0]) > 0 && v[0][0] != 'D' {
s = "-" + s
@@ -112,14 +117,10 @@ meson setup \
return
}
}
}), " \\\n\t")+` \
. /usr/src/`+name+`
meson compile`+scriptCompiled+check+`
}), " \\\n\t") + ` \
. '/usr/src/` + name + `'
meson compile` + scriptCompiled + scriptTest + `
meson install \
--destdir=/work
`+attr.Script, slices.Concat(attr.Paths, []pkg.ExecPath{
pkg.Path(AbsUsrSrc.Append(
name+attr.SourceSuffix,
), attr.Writable, source),
})...)
` + attr.Script
}