internal/rosa: meson helper
All checks were successful
Test / Create distribution (push) Successful in 1m1s
Test / Sandbox (push) Successful in 2m34s
Test / Hakurei (push) Successful in 4m1s
Test / ShareFS (push) Successful in 4m0s
Test / Hpkg (push) Successful in 4m31s
Test / Sandbox (race detector) (push) Successful in 5m9s
Test / Hakurei (race detector) (push) Successful in 5m58s
Test / Flake checks (push) Successful in 2m0s
All checks were successful
Test / Create distribution (push) Successful in 1m1s
Test / Sandbox (push) Successful in 2m34s
Test / Hakurei (push) Successful in 4m1s
Test / ShareFS (push) Successful in 4m0s
Test / Hpkg (push) Successful in 4m31s
Test / Sandbox (race detector) (push) Successful in 5m9s
Test / Hakurei (race detector) (push) Successful in 5m58s
Test / Flake checks (push) Successful in 2m0s
This is used by quite a few projects. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package rosa
|
||||
|
||||
import "hakurei.app/internal/pkg"
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"hakurei.app/internal/pkg"
|
||||
)
|
||||
|
||||
func (t Toolchain) newMeson() pkg.Artifact {
|
||||
const (
|
||||
@@ -25,3 +30,96 @@ 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.
|
||||
ScriptCompiled string
|
||||
// Runs after install.
|
||||
Script string
|
||||
|
||||
// Flags passed to the setup command.
|
||||
Configure [][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
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
if attr == nil {
|
||||
attr = new(MesonAttr)
|
||||
}
|
||||
|
||||
scriptCompiled := attr.ScriptCompiled
|
||||
if len(scriptCompiled) > 0 && scriptCompiled[0] != '\n' {
|
||||
scriptCompiled = "\n" + scriptCompiled
|
||||
}
|
||||
|
||||
var check string
|
||||
if !attr.SkipCheck {
|
||||
check = "\nmeson test \\\n\t--print-errorlogs" + attr.AppendTest
|
||||
}
|
||||
|
||||
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+`
|
||||
cd "$(mktemp -d)"
|
||||
meson setup \
|
||||
`+strings.Join(slices.Collect(func(yield func(string) bool) {
|
||||
for _, v := range append([][2]string{
|
||||
{"prefix", "/system"},
|
||||
{"buildtype", "release"},
|
||||
}, attr.Configure...) {
|
||||
s := "-" + v[0]
|
||||
if len(v[0]) > 0 && v[0][0] != 'D' {
|
||||
s = "-" + s
|
||||
}
|
||||
if v[1] != "" {
|
||||
s += "=" + v[1]
|
||||
}
|
||||
if !yield(s) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}), " \\\n\t")+` \
|
||||
. /usr/src/`+name+`
|
||||
meson compile`+scriptCompiled+check+`
|
||||
meson install \
|
||||
--destdir=/work
|
||||
`+attr.Script, slices.Concat(attr.Paths, []pkg.ExecPath{
|
||||
pkg.Path(AbsUsrSrc.Append(
|
||||
name+attr.SourceSuffix,
|
||||
), attr.Writable, source),
|
||||
})...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user