github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/tests/gopherjsvendored_test.sh (about) 1 #!/bin/sh 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 HUP INT TERM 14 15 # copyGoPackage copies Go package with import path $1 to directory $2. 16 # The target directory is created if it doesn't exist. 17 copyGoPackage() { 18 mkdir -p "$2" 19 pkgDir=$(go list -f '{{.Dir}}' "$1") 20 # Copy all files (not directories), other than ones that start with "." or "_". 21 for f in $(find -H "$pkgDir" -maxdepth 1 -name "[^._]*" -type f); do 22 cp "$f" "$2" 23 done 24 } 25 26 # Make a hello project that will vendor GopherJS. 27 mkdir -p "$tmp/src/example.org/hello" 28 echo 'package main 29 30 import "github.com/gopherjs/gopherjs/js" 31 32 func main() { 33 js.Global.Get("console").Call("log", "hello using js pkg") 34 }' > "$tmp/src/example.org/hello/main.go" 35 36 # Vendor GopherJS and its dependencies into hello project. 37 for pkg in $(go list -f '{{if not .Goroot}}{{.ImportPath}}{{end}}' $(go list -f '{{.ImportPath}} {{join .Deps " "}}' github.com/goplusjs/gopherjs)); do 38 copyGoPackage "$pkg" "$tmp/src/example.org/hello/vendor/$pkg" 39 done 40 41 # Make $tmp our GOPATH workspace. 42 export GOPATH="$tmp" 43 export GO111MODULE=off 44 # Build the vendored copy of GopherJS. 45 go install example.org/hello/vendor/github.com/goplusjs/gopherjs 46 47 # Use it to build and run the hello command. 48 (cd "$GOPATH/src/example.org/hello" && "$GOPATH/bin/gopherjs" run main.go)