Skip to content

Commit 9fc05fc

Browse files
committed
playground: make update.sh work when GOROOT is user-writable
Previously, the script relied on GOROOT not being user-writable and failed when that wasn't the case. This change makes it succeed in both cases. Fixes #69
1 parent 86419bc commit 9fc05fc

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

Diff for: playground/update.sh

+17-15
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,43 @@ trap cleanup EXIT HUP INT TERM
1515
# github.com/gopherjs/gopherjs.github.io repositories.
1616
export GO111MODULE=off
1717

18-
# TODO: This script relies on $(go env GOROOT) not being user-writable.
19-
# It can be improved to work even when $(go env GOROOT) is user-writable
20-
# by making a GOROOT copy here, immediately chmod-ing it to be non-user-writable,
21-
# and later on chmod-ing it be user-writable again.
22-
# See https://github.com/gopherjs/gopherjs.github.io/issues/69.
23-
2418
go install github.com/gopherjs/gopherjs/...
2519

2620
go generate github.com/gopherjs/gopherjs.github.io/playground/internal/imports
2721

28-
# Build playground itself.
29-
gopherjs build -m
30-
3122
# The GOPATH workspace where the GopherJS project is.
3223
gopherjsgopath=$(go list -f '{{.Root}}' github.com/gopherjs/gopherjs)
3324

34-
rm -rf pkg/
25+
# Make a copy of GOROOT that is non-user-writable,
26+
# to prevent any GopherJS packages being written to it for now.
27+
echo "copying GOROOT from $(go env GOROOT) to $tmp/goroot"
28+
cp -a "$(go env GOROOT)" "$tmp/goroot"
29+
echo "making our copy of GOROOT non-user-writable for now"
30+
chmod -R -w "$tmp/goroot"
31+
export GOROOT="$tmp/goroot"
32+
unset GOPHERJS_GOROOT # force $GOROOT to be used
33+
34+
# Build playground itself.
35+
gopherjs build -m
3536

3637
# Use an empty GOPATH workspace with just gopherjs,
3738
# so that all the standard library packages get written to GOROOT/pkg.
3839
export GOPATH="$tmp/gopath"
3940
mkdir -p "$GOPATH"/src/github.com/gopherjs/gopherjs
4041
cp -a "$gopherjsgopath"/src/github.com/gopherjs/gopherjs/* "$GOPATH"/src/github.com/gopherjs/gopherjs
4142

43+
rm -rf pkg/
44+
4245
gopherjs install -m github.com/gopherjs/gopherjs/js github.com/gopherjs/gopherjs/nosync
4346
mkdir -p pkg/github.com/gopherjs/gopherjs
4447
cp "$GOPATH"/pkg/*_js_min/github.com/gopherjs/gopherjs/js.a pkg/github.com/gopherjs/gopherjs/js.a
4548
cp "$GOPATH"/pkg/*_js_min/github.com/gopherjs/gopherjs/nosync.a pkg/github.com/gopherjs/gopherjs/nosync.a
4649

47-
# Make a copy of GOROOT that is user-writable,
50+
# Make our GOROOT copy user-writable now, then
4851
# use it to build and copy out standard library packages.
49-
echo "copying GOROOT from $(go env GOROOT) to $tmp/goroot"
50-
cp -a "$(go env GOROOT)" "$tmp/goroot"
51-
export GOROOT="$tmp/goroot"
52-
unset GOPHERJS_GOROOT # force $GOROOT to be used
52+
echo "making our copy of GOROOT user-writable again"
53+
chmod -R u+w "$tmp/goroot"
54+
5355
gopherjs install -m \
5456
archive/tar \
5557
archive/zip \

0 commit comments

Comments
 (0)