aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/meson.go
blob: 737a727cc27e6db7351430b6cdb2917ba2d9b09c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package rosa

import (
	"slices"
	"strings"
)

// Meson is the meson package used by [MesonHelper].
var Meson = H("meson")

// 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.
	Setup []KV
	// Whether to skip meson test.
	SkipTest bool
}

var _ Helper = new(MesonHelper)

// extra returns hardcoded meson runtime dependencies.
func (*MesonHelper) extra(int) P { return P{Meson} }

// 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(t Toolchain, name string) string {
	if attr == nil {
		attr = new(MesonHelper)
	}

	scriptCompiled := attr.ScriptCompiled
	if len(scriptCompiled) > 0 && scriptCompiled[0] != '\n' {
		scriptCompiled = "\n" + scriptCompiled
	}

	var scriptTest string
	if !attr.SkipTest && t.opts&OptSkipCheck == 0 {
		scriptTest = `
meson test \
	--print-errorlogs`
	}

	return `
cd "$(mktemp -d)"
meson setup \
	` + strings.Join(slices.Collect(func(yield func(string) bool) {
		for _, v := range append([]KV{
			{"wrap-mode", "nofallback"},
			{"prefix", "/system"},
			{"buildtype", "release"},
		}, attr.Setup...) {
			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 + scriptTest + `
meson install \
	--destdir=/work
` + attr.Script
}