aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/hakurei.go
blob: be184302be70c4750d09608d5a524d08cb884b7c (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package rosa

import (
	"hakurei.app/internal/pkg"
)

func (t Toolchain) newHakurei(suffix, script string) pkg.Artifact {
	const (
		version  = "0.3.5"
		checksum = "6Tn38NLezRD2d3aGdFg5qFfqn8_KvC6HwMKwJMPvaHmVw8xRgxn8B0PObswl2mOk"
	)
	return t.New("hakurei"+suffix+"-"+version, 0, []pkg.Artifact{
		t.Load(Go),

		t.Load(Gzip),
		t.Load(PkgConfig),

		t.Load(KernelHeaders),
		t.Load(Libseccomp),
		t.Load(ACL),
		t.Load(Attr),
		t.Load(Fuse),

		t.Load(Xproto),
		t.Load(LibXau),
		t.Load(XCBProto),
		t.Load(XCB),

		t.Load(Libffi),
		t.Load(Libexpat),
		t.Load(Libxml2),
		t.Load(Wayland),
		t.Load(WaylandProtocols),
	}, nil, []string{
		"CGO_ENABLED=1",
		"GOCACHE=/tmp/gocache",
		"CC=clang -O3 -Werror",
	}, `
echo '# Building test helper (hostname).'
go build -v -o /bin/hostname /usr/src/hostname/main.go
echo

chmod -R +w /usr/src/hakurei
cd /usr/src/hakurei

HAKUREI_VERSION='v`+version+`'
`+script, pkg.Path(AbsUsrSrc.Append("hakurei"), true, t.NewPatchedSource(
		"hakurei", version, pkg.NewHTTPGetTar(
			nil, "https://git.gensokyo.uk/security/hakurei/archive/"+
				"v"+version+".tar.gz",
			mustDecode(checksum),
			pkg.TarGzip,
		), true, [2]string{"createTemp-error-injection", `diff --git a/container/dispatcher_test.go b/container/dispatcher_test.go
index 5de37fc..fe0c4db 100644
--- a/container/dispatcher_test.go
+++ b/container/dispatcher_test.go
@@ -238,8 +238,11 @@ func sliceAddr[S any](s []S) *[]S { return &s }

 func newCheckedFile(t *testing.T, name, wantData string, closeErr error) osFile {
        f := &checkedOsFile{t: t, name: name, want: wantData, closeErr: closeErr}
-       // check happens in Close, and cleanup is not guaranteed to run, so relying on it for sloppy implementations will cause sporadic test results
-       f.cleanup = runtime.AddCleanup(f, func(name string) { f.t.Fatalf("checkedOsFile %s became unreachable without a call to Close", name) }, f.name)
+       // check happens in Close, and cleanup is not guaranteed to run, so relying
+       // on it for sloppy implementations will cause sporadic test results
+       f.cleanup = runtime.AddCleanup(f, func(name string) {
+               panic("checkedOsFile " + name + " became unreachable without a call to Close")
+       }, name)
        return f
 }

diff --git a/container/initplace_test.go b/container/initplace_test.go
index afeddbe..1c2f20b 100644
--- a/container/initplace_test.go
+++ b/container/initplace_test.go
@@ -21,7 +21,7 @@ func TestTmpfileOp(t *testing.T) {
                        Path: samplePath,
                        Data: sampleData,
                }, nil, nil, []stub.Call{
-                       call("createTemp", stub.ExpectArgs{"/", "tmp.*"}, newCheckedFile(t, "tmp.32768", sampleDataString, nil), stub.UniqueError(5)),
+                       call("createTemp", stub.ExpectArgs{"/", "tmp.*"}, (*checkedOsFile)(nil), stub.UniqueError(5)),
                }, stub.UniqueError(5)},

                {"Write", &Params{ParentPerm: 0700}, &TmpfileOp{
`},
	)), pkg.Path(AbsUsrSrc.Append("hostname", "main.go"), false, pkg.NewFile(
		"hostname.go",
		[]byte(`
package main

import "os"

func main() {
	if name, err := os.Hostname(); err != nil {
		panic(err)
	} else {
		os.Stdout.WriteString(name)
	}
}
`),
	)))
}
func init() {
	artifactsF[Hakurei] = func(t Toolchain) pkg.Artifact {
		return t.newHakurei("", `
mkdir -p /work/system/libexec/hakurei/

echo '# Building hakurei.'
go generate -v ./...
go build -trimpath -v -o /work/system/libexec/hakurei -ldflags="-s -w
	-buildid=
	-extldflags=-static
	-X hakurei.app/internal/info.buildVersion="$HAKUREI_VERSION"
	-X hakurei.app/internal/info.hakureiPath=/system/bin/hakurei
	-X hakurei.app/internal/info.hsuPath=/system/bin/hsu
	-X main.hakureiPath=/system/bin/hakurei" ./...
echo

echo '# Testing hakurei.'
go test -ldflags='-buildid= -extldflags=-static' ./...
echo

mkdir -p /work/system/bin/
(cd /work/system/libexec/hakurei && mv \
	hakurei \
	sharefs \
	../../bin/)
`)
	}
	artifactsF[HakureiDist] = func(t Toolchain) pkg.Artifact {
		return t.newHakurei("-dist", `
export HAKUREI_VERSION
DESTDIR=/work /usr/src/hakurei/dist/release.sh
`)
	}
}