Skip to content

Commit c322678

Browse files
committed
Overhaul playground update script.
- Make it compatible with Go Modules build environment. - Simplify isolated GOROOT setup, avoid copying and chmodding. - Precompile all standard library packages except few known incompatible ones. - Precompile packages in non-minified mode, since the sourcemap is not available in the playground and function names may get mangled.
1 parent ce7cd49 commit c322678

File tree

1 file changed

+39
-141
lines changed

1 file changed

+39
-141
lines changed

playground/update.sh

Lines changed: 39 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,58 @@
11
#!/bin/sh
2-
set -e
2+
set -e;
33

4-
tmp=$(mktemp -d "${TMPDIR:-/tmp}/gopherjs_playground.XXXXXXXXXX")
4+
tmp=$(mktemp -d "${TMPDIR:-/tmp}/gopherjs_playground.XXXXXXXXXX");
55

66
cleanup() {
7-
rm -rf "$tmp"
8-
exit
7+
chmod -R u+w "$tmp";
8+
rm -rf "$tmp";
9+
exit;
910
}
1011

11-
trap cleanup EXIT HUP INT TERM
12-
13-
# This script relies on GOPATH mode. The GOPATH workspace
14-
# must contain both github.com/gopherjs/gopherjs and
15-
# github.com/gopherjs/gopherjs.github.io repositories.
16-
export GO111MODULE=off
12+
isolated_goroot() {
13+
REAL_GOROOT="$(go env GOROOT)"
14+
export GOROOT="$tmp/goroot"
15+
unset GOPHERJS_GOROOT # force $GOROOT to be used
16+
mkdir -p "$GOROOT/pkg"
17+
for f in $(ls $REAL_GOROOT | grep -v pkg); do
18+
ln -s "$REAL_GOROOT/$f" "$GOROOT/$f"
19+
done
20+
export GOPATH="$tmp/gopath" # Intentionally doesn't exist.
21+
}
1722

18-
go install github.com/gopherjs/gopherjs/...
23+
trap cleanup EXIT HUP INT TERM;
1924

20-
go generate github.com/gopherjs/gopherjs.github.io/playground/internal/imports
25+
export GO111MODULE=on;
2126

22-
# The GOPATH workspace where the GopherJS project is.
23-
gopherjsgopath=$(go list -f '{{.Root}}' github.com/gopherjs/gopherjs)
27+
# Stage 1: Install latest released GopherJS version.
28+
go install github.com/gopherjs/gopherjs@latest;
2429

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
30+
# Stage 2: Regenerate stdlib API information for auto-imports.
31+
go generate github.com/gopherjs/gopherjs.github.io/playground/internal/imports;
3332

34-
# Build playground itself.
35-
gopherjs build -m
33+
# Stage 3: Build playground itself.
34+
gopherjs build -m .;
3635

37-
# Use an empty GOPATH workspace with just gopherjs,
38-
# so that all the standard library packages get written to GOROOT/pkg.
39-
export GOPATH="$tmp/gopath"
40-
mkdir -p "$GOPATH"/src/github.com/gopherjs/gopherjs
41-
cp -a "$gopherjsgopath"/src/github.com/gopherjs/gopherjs/* "$GOPATH"/src/github.com/gopherjs/gopherjs
36+
# Stage 4: Precompile standard library and GopherJS packages.
4237

43-
rm -rf pkg/
38+
# Stage 4.1: Set up isolated GOROOT/GOPATH directory so that we can easily
39+
# extract all compiled archives.
40+
isolated_goroot;
4441

45-
gopherjs install -m github.com/gopherjs/gopherjs/js github.com/gopherjs/gopherjs/nosync
46-
mkdir -p pkg/github.com/gopherjs/gopherjs
47-
cp "$GOPATH"/pkg/*_js_min/github.com/gopherjs/gopherjs/js.a pkg/github.com/gopherjs/gopherjs/js.a
48-
cp "$GOPATH"/pkg/*_js_min/github.com/gopherjs/gopherjs/nosync.a pkg/github.com/gopherjs/gopherjs/nosync.a
42+
# Stage 4.2: Wipe out all previously built archives.
43+
rm -rf pkg/;
4944

50-
# Make our GOROOT copy user-writable now, then
51-
# use it to build and copy out standard library packages.
52-
echo "making our copy of GOROOT user-writable again"
53-
chmod -R u+w "$tmp/goroot"
45+
# Stage 4.3: Precompile GopherJS libraries.
46+
mkdir -p pkg/github.com/gopherjs/gopherjs;
47+
gopherjs build -o pkg/github.com/gopherjs/gopherjs/js.a github.com/gopherjs/gopherjs/js;
48+
gopherjs build -o pkg/github.com/gopherjs/gopherjs/nosync.a github.com/gopherjs/gopherjs/nosync;
5449

55-
gopherjs install -m \
56-
archive/tar \
57-
archive/zip \
58-
bufio \
59-
bytes \
60-
compress/bzip2 \
61-
compress/flate \
62-
compress/gzip \
63-
compress/lzw \
64-
compress/zlib \
65-
container/heap \
66-
container/list \
67-
container/ring \
68-
crypto/aes \
69-
crypto/cipher \
70-
crypto/des \
71-
crypto/dsa \
72-
crypto/ecdsa \
73-
crypto/elliptic \
74-
crypto/hmac \
75-
crypto/md5 \
76-
crypto/rand \
77-
crypto/rc4 \
78-
crypto/rsa \
79-
crypto/sha1 \
80-
crypto/sha256 \
81-
crypto/sha512 \
82-
crypto/subtle \
83-
database/sql/driver \
84-
debug/gosym \
85-
debug/pe \
86-
encoding/ascii85 \
87-
encoding/asn1 \
88-
encoding/base32 \
89-
encoding/base64 \
90-
encoding/binary \
91-
encoding/csv \
92-
encoding/gob \
93-
encoding/hex \
94-
encoding/json \
95-
encoding/pem \
96-
encoding/xml \
97-
errors \
98-
fmt \
99-
go/ast \
100-
go/doc \
101-
go/format \
102-
go/printer \
103-
go/token \
104-
hash/adler32 \
105-
hash/crc32 \
106-
hash/crc64 \
107-
hash/fnv \
108-
html \
109-
html/template \
110-
image \
111-
image/color \
112-
image/draw \
113-
image/gif \
114-
image/jpeg \
115-
image/png \
116-
index/suffixarray \
117-
io \
118-
io/ioutil \
119-
math \
120-
math/big \
121-
math/bits \
122-
math/cmplx \
123-
math/rand \
124-
mime \
125-
net/http/cookiejar \
126-
net/http/fcgi \
127-
net/http/httptest \
128-
net/http/httputil \
129-
net/mail \
130-
net/smtp \
131-
net/textproto \
132-
net/url \
133-
path \
134-
path/filepath \
135-
reflect \
136-
regexp \
137-
regexp/syntax \
138-
runtime/internal/sys \
139-
sort \
140-
strconv \
141-
strings \
142-
sync/atomic \
143-
syscall/js \
144-
testing \
145-
testing/iotest \
146-
testing/quick \
147-
text/scanner \
148-
text/tabwriter \
149-
text/template \
150-
text/template/parse \
151-
time \
152-
unicode \
153-
unicode/utf16 \
154-
unicode/utf8
50+
# Stage 4.4: Precompile standard library.
51+
gopherjs install $(GOOS=js GOARCH=wasm go list std | grep -v -E "internal/|vendor/|pprof|plugin")
15552

156-
cp -a "$GOROOT"/pkg/*_js_min/* pkg/
157-
cp -a "$GOROOT"/pkg/*_amd64_js_min/* pkg/
53+
# Stage 4.5: Copy compiled archives into the repository tree.
54+
cp -a "$GOROOT"/pkg/*_js/* pkg/
55+
cp -a "$GOROOT"/pkg/*_amd64_amd64/* pkg/ # This is for the syscall package, which is built with a different GOARCH.
15856

159-
# Rename all *.a files in pkg/ to *.a.js.
57+
# Stage 4.6 Rename all *.a files in pkg/ to *.a.js.
16058
find pkg -name "*.a" -exec sh -c 'mv $0 $0.js' {} \;

0 commit comments

Comments
 (0)