2015-02-16 13:54:31 -05: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 17:11:20 -04:00
|
|
|
"path/filepath"
|
2015-07-28 09:03:49 -04:00
|
|
|
"runtime"
|
|
|
|
"strconv"
|
2015-04-20 17:11:20 -04:00
|
|
|
"strings"
|
2015-02-16 13:54:31 -05:00
|
|
|
"testing"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
2015-06-19 12:27:15 -04:00
|
|
|
var gopath string
|
|
|
|
|
2015-02-16 13:54:31 -05:00
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
buf := new(bytes.Buffer)
|
2015-06-19 12:27:15 -04:00
|
|
|
gopathorig := os.Getenv("GOPATH")
|
2015-02-16 13:54:31 -05:00
|
|
|
defer func() {
|
|
|
|
xout = os.Stderr
|
|
|
|
buildN = false
|
|
|
|
buildX = false
|
2015-07-27 11:57:10 -07:00
|
|
|
initU = false
|
2015-06-19 12:27:15 -04:00
|
|
|
os.Setenv("GOPATH", gopathorig)
|
2015-02-16 13:54:31 -05:00
|
|
|
}()
|
|
|
|
xout = buf
|
|
|
|
buildN = true
|
|
|
|
buildX = true
|
2015-07-27 11:57:10 -07:00
|
|
|
initU = true
|
|
|
|
|
2015-02-16 13:54:31 -05:00
|
|
|
// Test that first GOPATH element is chosen correctly.
|
2015-06-19 12:27:15 -04:00
|
|
|
gopath = "/GOPATH1"
|
2015-08-24 17:32:49 -04:00
|
|
|
paths := []string{gopath, "/path2", "/path3"}
|
|
|
|
if goos == "windows" {
|
|
|
|
gopath = filepath.ToSlash(`C:\GOPATH1`)
|
|
|
|
paths = []string{gopath, `C:\PATH2`, `C:\PATH3`}
|
|
|
|
}
|
2015-04-20 17:11:20 -04:00
|
|
|
os.Setenv("GOPATH", strings.Join(paths, string(os.PathListSeparator)))
|
|
|
|
os.Setenv("GOROOT_BOOTSTRAP", "go1.4")
|
|
|
|
if goos == "windows" {
|
|
|
|
os.Setenv("HOMEDRIVE", "C:")
|
|
|
|
}
|
2015-07-27 11:57:10 -07:00
|
|
|
|
2015-02-16 13:54:31 -05:00
|
|
|
err := runInit(cmdInit)
|
|
|
|
if err != nil {
|
|
|
|
t.Log(buf.String())
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-07-27 11:57:10 -07:00
|
|
|
diff, err := diffOutput(buf.String(), initTmpl)
|
2015-02-16 13:54:31 -05: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 17:11:20 -04:00
|
|
|
got = filepath.ToSlash(got)
|
|
|
|
|
2015-02-16 13:54:31 -05:00
|
|
|
wantBuf := new(bytes.Buffer)
|
2015-04-20 17:11:20 -04:00
|
|
|
data := outputData{
|
2015-07-25 21:26:28 -04:00
|
|
|
NDK: ndkVersion,
|
|
|
|
GOOS: goos,
|
|
|
|
GOARCH: goarch,
|
|
|
|
GOPATH: gopath,
|
|
|
|
NDKARCH: ndkarch,
|
|
|
|
Xproj: projPbxproj,
|
|
|
|
Xcontents: contentsJSON,
|
2015-08-02 19:52:31 -04:00
|
|
|
Xinfo: infoplistTmplData{BundleID: "org.golang.todo.basic", Name: "Basic"},
|
2015-07-28 09:03:49 -04:00
|
|
|
NumCPU: strconv.Itoa(runtime.NumCPU()),
|
2015-04-20 17:11:20 -04:00
|
|
|
}
|
|
|
|
if goos == "windows" {
|
|
|
|
data.EXE = ".exe"
|
|
|
|
}
|
2015-02-16 13:54:31 -05: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-07-25 21:26:28 -04:00
|
|
|
NDK string
|
|
|
|
GOOS string
|
|
|
|
GOARCH string
|
|
|
|
GOPATH string
|
|
|
|
NDKARCH string
|
|
|
|
EXE string // .extension for executables. (ex. ".exe" for windows)
|
|
|
|
Xproj string
|
|
|
|
Xcontents string
|
|
|
|
Xinfo infoplistTmplData
|
2015-07-28 09:03:49 -04:00
|
|
|
NumCPU string
|
2015-02-16 13:54:31 -05:00
|
|
|
}
|
|
|
|
|
2015-06-19 12:27:15 -04:00
|
|
|
var initTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
|
2015-05-03 10:50:35 -04:00
|
|
|
mkdir -p $GOMOBILE/android-{{.NDK}}
|
2015-07-16 20:36:27 -04:00
|
|
|
WORK={{.GOPATH}}/pkg/gomobile/work
|
2015-06-19 14:50:22 -07: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
|
2015-08-24 17:32:49 -04:00
|
|
|
mv $WORK/openal/lib $GOMOBILE/android-{{.NDK}}/openal/lib{{if eq .GOOS "darwin"}}
|
2015-08-20 13:50:18 -04:00
|
|
|
go install -p={{.NumCPU}} -x golang.org/x/mobile/gl
|
|
|
|
go install -p={{.NumCPU}} -x golang.org/x/mobile/app
|
2015-08-27 12:19:47 -04:00
|
|
|
go install -p={{.NumCPU}} -x golang.org/x/mobile/exp/app/debug{{end}}
|
2015-08-24 17:32:49 -04:00
|
|
|
GOOS=android GOARCH=arm GOARM=7 CC=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} CXX=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} CGO_ENABLED=1 go install -p={{.NumCPU}} -pkgdir=$GOMOBILE/pkg_android_arm -x std
|
2015-07-30 17:29:19 -04:00
|
|
|
{{if eq .GOOS "darwin"}}GOOS=darwin GOARCH=arm GOARM=7 CC=clang-iphoneos CXX=clang-iphoneos CGO_CFLAGS=-isysroot=iphoneos -arch armv7 CGO_LDFLAGS=-isysroot=iphoneos -arch armv7 CGO_ENABLED=1 go install -p={{.NumCPU}} -pkgdir=$GOMOBILE/pkg_darwin_arm -x std
|
2015-07-28 09:03:49 -04:00
|
|
|
GOOS=darwin GOARCH=arm64 CC=clang-iphoneos CXX=clang-iphoneos CGO_CFLAGS=-isysroot=iphoneos -arch arm64 CGO_LDFLAGS=-isysroot=iphoneos -arch arm64 CGO_ENABLED=1 go install -p={{.NumCPU}} -pkgdir=$GOMOBILE/pkg_darwin_arm64 -x std
|
2015-08-20 13:50:18 -04:00
|
|
|
GOOS=darwin GOARCH=amd64 CC=clang-iphonesimulator CXX=clang-iphonesimulator CGO_CFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=6.1 -arch x86_64 CGO_LDFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=6.1 -arch x86_64 CGO_ENABLED=1 go install -p={{.NumCPU}} -tags=ios -pkgdir=$GOMOBILE/pkg_darwin_amd64 -x std
|
2015-06-29 14:37:57 -04:00
|
|
|
{{end}}go version > $GOMOBILE/version
|
2015-06-19 14:50:22 -07:00
|
|
|
rm -r -f "$WORK"
|
|
|
|
`))
|