|
| 1 | +#!/bin/bash |
| 2 | +# Don't run this file directly. It's executed as part of TestGopherJSCanBeVendored. |
| 3 | + |
| 4 | +set -e |
| 5 | + |
| 6 | +tmp=$(mktemp -d "${TMPDIR:-/tmp}/gopherjsvendored_test.XXXXXXXXXX") |
| 7 | + |
| 8 | +cleanup() { |
| 9 | + rm -rf "$tmp" |
| 10 | + exit |
| 11 | +} |
| 12 | + |
| 13 | +trap cleanup EXIT SIGHUP SIGINT SIGTERM |
| 14 | + |
| 15 | +# Make a hello project that will vendor GopherJS. |
| 16 | +mkdir -p "$tmp/src/example.org/hello" |
| 17 | +echo 'package main |
| 18 | +
|
| 19 | +import "github.com/gopherjs/gopherjs/js" |
| 20 | +
|
| 21 | +func main() { |
| 22 | + js.Global.Get("console").Call("log", "hello using js pkg") |
| 23 | +}' > "$tmp/src/example.org/hello/main.go" |
| 24 | + |
| 25 | +# Vendor GopherJS and its dependencies into hello project. |
| 26 | +mkdir -p "$tmp/src/example.org/hello/vendor/github.com/gopherjs" \ |
| 27 | + "$tmp/src/example.org/hello/vendor/github.com/fsnotify" \ |
| 28 | + "$tmp/src/example.org/hello/vendor/github.com/kisielk" \ |
| 29 | + "$tmp/src/example.org/hello/vendor/github.com/neelance" \ |
| 30 | + "$tmp/src/example.org/hello/vendor/github.com/shurcooL" \ |
| 31 | + "$tmp/src/example.org/hello/vendor/github.com/spf13" \ |
| 32 | + "$tmp/src/example.org/hello/vendor/golang.org/x" |
| 33 | +cp -r $(go list -e -f '{{.Dir}}' github.com/gopherjs/gopherjs) "$tmp/src/example.org/hello/vendor/github.com/gopherjs/gopherjs" |
| 34 | +cp -r $(go list -e -f '{{.Dir}}' github.com/fsnotify/fsnotify) "$tmp/src/example.org/hello/vendor/github.com/fsnotify/fsnotify" |
| 35 | +cp -r $(go list -e -f '{{.Dir}}' github.com/kisielk/gotool) "$tmp/src/example.org/hello/vendor/github.com/kisielk/gotool" |
| 36 | +cp -r $(go list -e -f '{{.Dir}}' github.com/neelance/sourcemap) "$tmp/src/example.org/hello/vendor/github.com/neelance/sourcemap" |
| 37 | +cp -r $(go list -e -f '{{.Dir}}' github.com/shurcooL/httpfs) "$tmp/src/example.org/hello/vendor/github.com/shurcooL/httpfs" |
| 38 | +cp -r $(go list -e -f '{{.Dir}}' github.com/spf13/cobra) "$tmp/src/example.org/hello/vendor/github.com/spf13/cobra" |
| 39 | +cp -r $(go list -e -f '{{.Dir}}' github.com/spf13/pflag) "$tmp/src/example.org/hello/vendor/github.com/spf13/pflag" |
| 40 | +cp -r $(go list -e -f '{{.Dir}}' golang.org/x/crypto) "$tmp/src/example.org/hello/vendor/golang.org/x/crypto" |
| 41 | +cp -r $(go list -e -f '{{.Dir}}' golang.org/x/sys) "$tmp/src/example.org/hello/vendor/golang.org/x/sys" |
| 42 | +cp -r $(go list -e -f '{{.Dir}}' golang.org/x/tools) "$tmp/src/example.org/hello/vendor/golang.org/x/tools" |
| 43 | + |
| 44 | +# Make $tmp our GOPATH workspace. |
| 45 | +export GOPATH="$tmp" |
| 46 | + |
| 47 | +# Build the vendored copy of GopherJS. |
| 48 | +go install example.org/hello/vendor/github.com/gopherjs/gopherjs |
| 49 | + |
| 50 | +# Use it to build and run the hello command. |
| 51 | +(cd "$GOPATH/src/example.org/hello" && "$GOPATH/bin/gopherjs" run main.go) |
0 commit comments