Skip to content

Commit 84b8935

Browse files
committed
playground: Improve update.sh to be more general.
It uses a temporary staging folder to perform the operations. - No longer require your GOROOT to be writeable. - No longer require your GOPATH list to contain no more than 1 workspace. - It has no side-effects, for example, it no longer leaves the $GOPATH/bin/playground.js.map file behind. Fixes #36. It doesn't fix a part of #36, but a new issue #43 is created to track that.
1 parent 2068927 commit 84b8935

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

playground/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ A secondary motivation is making the playground usable for other projects, such
66

77
## Development
88

9-
To update the entire playground environment, run the `update.sh` script. It will install your local version of gopherjs compiler, rebuild and copy the standard library into the `pkg` directory, and build the playground.
9+
To update the entire playground environment, just run `go generate github.com/gopherjs/gopherjs.github.io/playground`. It will install your local version of GopherJS compiler, build the playground, make a temporary copy of Go to /tmp/gopherjsplayground_goroot, rebuild and copy the standard library into the `pkg` directory.
1010

11-
Working on the application itself is made easier by using the `gopherjs serve` command to rebuild and serve the playground every time you refresh the browser.
11+
Working on the playground application itself is made easier by using the `gopherjs serve` command to rebuild and serve the playground every time you refresh the browser.
1212

1313
```bash
1414
gopherjs serve

playground/gen.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//go:generate ./update.sh
2+
3+
package main

playground/update.sh

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
#! /bin/sh
1+
#!/bin/sh
22
set -e
33

44
go install github.com/gopherjs/gopherjs/...
55

66
go generate github.com/gopherjs/gopherjs.github.io/playground/internal/imports
77

8-
gopherjs install -m github.com/gopherjs/gopherjs.github.io/playground github.com/gopherjs/gopherjs/js
9-
cp $GOPATH/bin/playground.js $GOPATH/src/github.com/gopherjs/gopherjs.github.io/playground/playground.js
10-
cp $GOPATH/bin/playground.js.map $GOPATH/src/github.com/gopherjs/gopherjs.github.io/playground/playground.js.map
8+
# Build playground itself.
9+
gopherjs build -m
1110

12-
PKG=$GOPATH/src/github.com/gopherjs/gopherjs.github.io/playground/pkg
11+
# The GOPATH workspace where the GopherJS project is.
12+
GOPHERJSGOPATH=$(go list -f '{{.Root}}' github.com/gopherjs/gopherjs)
1313

14+
PKG=pkg
1415
rm -r $PKG
1516

17+
# Use an empty GOPATH workspace with just gopherjs,
18+
# so that all the standard library packages get written to GOROOT/pkg.
19+
export GOPATH=/tmp/gopherjsplayground_gopath
20+
mkdir -p $GOPATH/src/github.com/gopherjs/gopherjs
21+
cp -r $GOPHERJSGOPATH/src/github.com/gopherjs/gopherjs/* $GOPATH/src/github.com/gopherjs/gopherjs
22+
23+
gopherjs install -m github.com/gopherjs/gopherjs/js github.com/gopherjs/gopherjs/nosync
1624
mkdir -p $PKG/github.com/gopherjs/gopherjs
1725
cp $GOPATH/pkg/darwin_js_min/github.com/gopherjs/gopherjs/js.a $PKG/github.com/gopherjs/gopherjs/js.a
1826
cp $GOPATH/pkg/darwin_js_min/github.com/gopherjs/gopherjs/nosync.a $PKG/github.com/gopherjs/gopherjs/nosync.a
1927

20-
gopherjs install -m github.com/gopherjs/gopherjs/js archive/tar archive/zip bufio bytes compress/bzip2 compress/flate compress/gzip compress/lzw compress/zlib container/heap container/list container/ring crypto/aes crypto/cipher crypto/des crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac crypto/md5 crypto/rand crypto/rc4 crypto/rsa crypto/sha1 crypto/sha256 crypto/sha512 crypto/subtle database/sql/driver debug/gosym debug/pe encoding/ascii85 encoding/asn1 encoding/base32 encoding/base64 encoding/binary encoding/csv encoding/gob encoding/hex encoding/json encoding/pem encoding/xml errors fmt go/ast go/doc go/format go/printer go/token hash/adler32 hash/crc32 hash/crc64 hash/fnv html html/template image image/color image/draw image/gif image/jpeg image/png index/suffixarray io io/ioutil math math/big math/cmplx math/rand mime net/http/cookiejar net/http/fcgi net/http/httptest net/http/httputil net/mail net/smtp net/textproto net/url path path/filepath reflect regexp regexp/syntax sort strconv strings sync/atomic testing testing/iotest testing/quick text/scanner text/tabwriter text/template text/template/parse time unicode unicode/utf16 unicode/utf8
28+
# Make a copy of GOROOT that is user-writeable,
29+
# use it to build and copy out standard library packages.
30+
cp -r $(go env GOROOT) /tmp/gopherjsplayground_goroot
31+
export GOROOT=/tmp/gopherjsplayground_goroot
32+
gopherjs install -m archive/tar archive/zip bufio bytes compress/bzip2 compress/flate compress/gzip compress/lzw compress/zlib container/heap container/list container/ring crypto/aes crypto/cipher crypto/des crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac crypto/md5 crypto/rand crypto/rc4 crypto/rsa crypto/sha1 crypto/sha256 crypto/sha512 crypto/subtle database/sql/driver debug/gosym debug/pe encoding/ascii85 encoding/asn1 encoding/base32 encoding/base64 encoding/binary encoding/csv encoding/gob encoding/hex encoding/json encoding/pem encoding/xml errors fmt go/ast go/doc go/format go/printer go/token hash/adler32 hash/crc32 hash/crc64 hash/fnv html html/template image image/color image/draw image/gif image/jpeg image/png index/suffixarray io io/ioutil math math/big math/cmplx math/rand mime net/http/cookiejar net/http/fcgi net/http/httptest net/http/httputil net/mail net/smtp net/textproto net/url path path/filepath reflect regexp regexp/syntax runtime/internal/sys sort strconv strings sync/atomic testing testing/iotest testing/quick text/scanner text/tabwriter text/template text/template/parse time unicode unicode/utf16 unicode/utf8
2133
cp -r $GOROOT/pkg/darwin_js_min/* $PKG
2234
cp -r $GOROOT/pkg/darwin_amd64_js_min/* $PKG
2335

24-
rename 's/\.a/\.a.js/' `find $PKG -name "*.a"`
36+
rm -r /tmp/gopherjsplayground_goroot
37+
rm -r /tmp/gopherjsplayground_gopath
38+
39+
rename 's/\.a/\.a.js/' $(find $PKG -name "*.a")

0 commit comments

Comments
 (0)