2015-02-16 18:54:31 +00:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os"
|
2015-04-20 21:11:20 +00:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2015-02-16 18:54:31 +00:00
|
|
|
"testing"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
2015-06-19 16:27:15 +00:00
|
|
|
var gopath string
|
|
|
|
|
2015-02-16 18:54:31 +00:00
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
buf := new(bytes.Buffer)
|
2015-06-19 16:27:15 +00:00
|
|
|
gopathorig := os.Getenv("GOPATH")
|
2015-02-16 18:54:31 +00:00
|
|
|
defer func() {
|
|
|
|
xout = os.Stderr
|
|
|
|
buildN = false
|
|
|
|
buildX = false
|
2015-06-19 16:27:15 +00:00
|
|
|
os.Setenv("GOPATH", gopathorig)
|
2015-02-16 18:54:31 +00:00
|
|
|
}()
|
|
|
|
xout = buf
|
|
|
|
buildN = true
|
|
|
|
buildX = true
|
|
|
|
// Test that first GOPATH element is chosen correctly.
|
2015-06-19 16:27:15 +00:00
|
|
|
gopath = "/GOPATH1"
|
|
|
|
paths := []string{"/GOPATH1", "/path2", "/path3"}
|
2015-04-20 21:11:20 +00:00
|
|
|
os.Setenv("GOPATH", strings.Join(paths, string(os.PathListSeparator)))
|
|
|
|
os.Setenv("GOROOT_BOOTSTRAP", "go1.4")
|
|
|
|
if goos == "windows" {
|
|
|
|
os.Setenv("HOMEDRIVE", "C:")
|
|
|
|
}
|
2015-02-16 18:54:31 +00:00
|
|
|
err := runInit(cmdInit)
|
|
|
|
if err != nil {
|
|
|
|
t.Log(buf.String())
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:50:22 +00:00
|
|
|
tmpl := initTmpl
|
|
|
|
|
|
|
|
diff, err := diffOutput(buf.String(), tmpl)
|
2015-02-16 18:54:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("computing diff failed: %v", err)
|
|
|
|
}
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("unexpected output:\n%s", diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func diffOutput(got string, wantTmpl *template.Template) (string, error) {
|
2015-04-20 21:11:20 +00:00
|
|
|
got = filepath.ToSlash(got)
|
|
|
|
|
2015-02-16 18:54:31 +00:00
|
|
|
wantBuf := new(bytes.Buffer)
|
2015-04-20 21:11:20 +00:00
|
|
|
data := outputData{
|
|
|
|
NDK: ndkVersion,
|
|
|
|
GOOS: goos,
|
|
|
|
GOARCH: goarch,
|
2015-06-19 16:27:15 +00:00
|
|
|
GOPATH: gopath,
|
2015-04-20 21:11:20 +00:00
|
|
|
NDKARCH: ndkarch,
|
|
|
|
BuildScript: unixBuildScript,
|
|
|
|
}
|
|
|
|
if goos == "windows" {
|
|
|
|
data.EXE = ".exe"
|
|
|
|
data.BuildScript = windowsBuildScript
|
|
|
|
}
|
2015-02-16 18:54:31 +00:00
|
|
|
if err := wantTmpl.Execute(wantBuf, data); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
want := wantBuf.String()
|
|
|
|
if got != want {
|
|
|
|
return diff(got, want)
|
|
|
|
}
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type outputData struct {
|
2015-04-20 21:11:20 +00:00
|
|
|
NDK string
|
|
|
|
GOOS string
|
|
|
|
GOARCH string
|
2015-06-19 16:27:15 +00:00
|
|
|
GOPATH string
|
2015-04-20 21:11:20 +00:00
|
|
|
NDKARCH string
|
|
|
|
EXE string // .extension for executables. (ex. ".exe" for windows)
|
|
|
|
BuildScript string
|
2015-02-16 18:54:31 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 21:11:20 +00:00
|
|
|
const (
|
2015-06-29 18:37:57 +00:00
|
|
|
unixBuildScript = `TMPDIR=$WORK HOME=$HOME go install std`
|
|
|
|
windowsBuildScript = `TEMP=$WORK TMP=$WORK HOMEDRIVE=C: HOMEPATH=$HOMEPATH go install std`
|
2015-04-20 21:11:20 +00:00
|
|
|
)
|
|
|
|
|
2015-06-19 16:27:15 +00:00
|
|
|
var initTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
|
2015-05-03 14:50:35 +00:00
|
|
|
mkdir -p $GOMOBILE/android-{{.NDK}}
|
2015-06-19 16:27:15 +00:00
|
|
|
WORK=/GOPATH1/pkg/gomobile/work
|
2015-06-19 21:50:22 +00:00
|
|
|
mkdir -p $GOMOBILE/dl
|
|
|
|
curl -o$GOMOBILE/dl/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz https://dl.google.com/go/mobile/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz
|
|
|
|
tar xfz $GOMOBILE/dl/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz
|
|
|
|
mkdir -p $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr
|
|
|
|
mv $WORK/android-{{.NDK}}/platforms/android-15/arch-arm/usr/include $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr/include
|
|
|
|
mv $WORK/android-{{.NDK}}/platforms/android-15/arch-arm/usr/lib $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr/lib
|
|
|
|
mv $WORK/android-{{.NDK}}/toolchains/arm-linux-androideabi-4.8/prebuilt/{{.GOOS}}-{{.NDKARCH}}/bin $GOMOBILE/android-{{.NDK}}/arm/bin
|
|
|
|
mv $WORK/android-{{.NDK}}/toolchains/arm-linux-androideabi-4.8/prebuilt/{{.GOOS}}-{{.NDKARCH}}/lib $GOMOBILE/android-{{.NDK}}/arm/lib
|
|
|
|
mv $WORK/android-{{.NDK}}/toolchains/arm-linux-androideabi-4.8/prebuilt/{{.GOOS}}-{{.NDKARCH}}/libexec $GOMOBILE/android-{{.NDK}}/arm/libexec
|
|
|
|
mkdir -p $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin
|
|
|
|
ln -s $GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-ld{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin/ld{{.EXE}}
|
|
|
|
ln -s $GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-as{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin/as{{.EXE}}
|
|
|
|
ln -s $GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin/gcc{{.EXE}}
|
|
|
|
ln -s $GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin/g++{{.EXE}}
|
|
|
|
mkdir -p $GOMOBILE/dl
|
|
|
|
curl -o$GOMOBILE/dl/gomobile-openal-soft-1.16.0.1.tar.gz https://dl.google.com/go/mobile/gomobile-openal-soft-1.16.0.1.tar.gz
|
|
|
|
tar xfz $GOMOBILE/dl/gomobile-openal-soft-1.16.0.1.tar.gz
|
|
|
|
mv $WORK/openal/include/AL $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr/include/AL
|
|
|
|
mkdir -p $GOMOBILE/android-{{.NDK}}/openal
|
|
|
|
mv $WORK/openal/lib $GOMOBILE/android-{{.NDK}}/openal/lib
|
|
|
|
rm -r -f "$GOROOT/pkg/android_arm"
|
2015-06-29 18:37:57 +00:00
|
|
|
PATH=$PATH GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} CXX=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} {{.BuildScript}}
|
|
|
|
{{if eq .GOOS "darwin"}}rm -r -f "$GOROOT/pkg/darwin_arm"
|
|
|
|
PATH=$PATH GOOS=darwin GOARCH=arm CGO_ENABLED=1 CC=$GOROOT/misc/ios/clangwrap.sh CXX=$GOROOT/misc/ios/clangwrap.sh GOARM=7 {{.BuildScript}}
|
2015-06-19 21:50:22 +00:00
|
|
|
rm -r -f "$GOROOT/pkg/darwin_arm64"
|
2015-06-29 18:37:57 +00:00
|
|
|
PATH=$PATH GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 CC=$GOROOT/misc/ios/clangwrap.sh CXX=$GOROOT/misc/ios/clangwrap.sh {{.BuildScript}}
|
|
|
|
{{end}}go version > $GOMOBILE/version
|
2015-06-19 21:50:22 +00:00
|
|
|
rm -r -f "$WORK"
|
|
|
|
`))
|