-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest-external-workspaces.sh
executable file
·74 lines (59 loc) · 2.41 KB
/
test-external-workspaces.sh
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
#!/bin/bash
set -ex
if [ -z "$GOROOT" ]; then
GO="go"
else
GO="$GOROOT/bin/go"
fi
pushd src/cmd/makebb
$GO build -covermode=atomic
popd
pushd src/cmd/goanywhere
$GO build -covermode=atomic
popd
MAKEBB=$(pwd)/src/cmd/makebb/makebb
GOANYWHERE=$(pwd)/src/cmd/goanywhere/goanywhere
TMPDIR=$(mktemp -d)
EMPTY_TMPDIR=$(mktemp -d)
pushd $TMPDIR
function ctrl_c() {
popd
rm -rf $TMPDIR
# https://github.com/golang/go/issues/27455
GOPATH=$EMPTY_TMPDIR $GO clean -cache -modcache
rm -rf $EMPTY_TMPDIR
}
trap ctrl_c INT
# u-root checked out NOT in $GOPATH.
# Checkout before 1.20+ was required.
(git clone https://github.com/u-root/u-root && cd u-root && git checkout 6ca118b0a77c23ae859cddeee15762d9cd74c63f)
# Pin to commit before Go 1.20 was required. (We test 1.18+.)
(git clone https://github.com/gokrazy/gokrazy && cd gokrazy && git checkout 254af2bf3c82ff9f56e89794b2c146ef9cc85dc6)
# Pin to commit before Go 1.20 was required. (We test 1.18+.)
(git clone https://github.com/hugelgupf/p9 && cd p9 && git checkout 660eb2337e3c1878298fe550ad03248f329eeb72)
# Test workspaces.
go work init ./u-root && go work use ./gokrazy && go work use ./p9
# Test reproducible builds.
GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly -o bb1 ./u-root/cmds/*/*
GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly -o bb2 ./u-root/cmds/*/*
cmp bb1 bb2 || (echo "building u-root is not reproducible" && exit 1)
rm bb1 bb2
GOARCH=amd64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly ./u-root/cmds/*/* ./gokrazy/cmd/* ./p9/cmd/*
GOARCH=arm64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly ./u-root/cmds/*/* ./gokrazy/cmd/* ./p9/cmd/*
GOARCH=riscv64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=readonly ./u-root/cmds/*/* ./gokrazy/cmd/* ./p9/cmd/*
# Try an offline build in go workspaces.
# go work vendor is a Go 1.22 feature.
if grep -q -v "go1.21" <<< "$($GO version)" && grep -q -v "go1.20" <<< "$($GO version)";
then
go work vendor
GOARCH=amd64 GOROOT=$GOROOT GOPATH=$EMPTY_TMPDIR GO111MODULE=on $MAKEBB -go-mod=vendor ./u-root/cmds/*/* ./gokrazy/cmd/* ./p9/cmd/*
fi
# Remove workspace.
rm -rf vendor
rm go.work go.work.sum
$GOANYWHERE -d ./u-root/cmds/*/* ./p9/cmd/* -- $MAKEBB -o $(pwd)
popd
rm -rf $TMPDIR
# https://github.com/golang/go/issues/27455
GOPATH=$EMPTY_TMPDIR $GO clean -cache -modcache
rm -rf $EMPTY_TMPDIR