github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/cmd/gomobile/bind_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "bytes" 9 "os" 10 "path/filepath" 11 "testing" 12 "text/template" 13 ) 14 15 // TODO(crawshaw): TestBindIOS 16 17 func TestBindAndroid(t *testing.T) { 18 if os.Getenv("ANDROID_HOME") == "" { 19 t.Skip("ANDROID_HOME not found, skipping bind") 20 } 21 22 buf := new(bytes.Buffer) 23 defer func() { 24 xout = os.Stderr 25 buildN = false 26 buildX = false 27 }() 28 xout = buf 29 buildN = true 30 buildX = true 31 buildO = "asset.aar" 32 buildTarget = "android" 33 gopath = filepath.SplitList(os.Getenv("GOPATH"))[0] 34 if goos == "windows" { 35 os.Setenv("HOMEDRIVE", "C:") 36 } 37 cmdBind.flag.Parse([]string{"github.com/c-darwin/mobile/asset"}) 38 err := runBind(cmdBind) 39 if err != nil { 40 t.Log(buf.String()) 41 t.Fatal(err) 42 } 43 44 diff, err := diffOutput(buf.String(), bindAndroidTmpl) 45 if err != nil { 46 t.Fatalf("computing diff failed: %v", err) 47 } 48 if diff != "" { 49 t.Errorf("unexpected output:\n%s", diff) 50 } 51 } 52 53 var bindAndroidTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile 54 WORK=$WORK 55 gobind -lang=go github.com/c-darwin/mobile/asset > $WORK/go_asset/go_assetmain.go 56 mkdir -p $WORK/go_asset 57 mkdir -p $WORK/androidlib 58 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 build -p={{.NumCPU}} -pkgdir=$GOMOBILE/pkg_android_arm -tags="" -x -buildmode=c-shared -o=$WORK/android/src/main/jniLibs/armeabi-v7a/libgojni.so $WORK/androidlib/main.go 59 gobind -lang=java github.com/c-darwin/mobile/asset > $WORK/android/src/main/java/go/asset/Asset.java 60 mkdir -p $WORK/android/src/main/java/go/asset 61 mkdir -p $WORK/android/src/main/java/go 62 rm $WORK/android/src/main/java/go/Seq.java 63 ln -s $GOPATH/src/github.com/c-darwin/mobile/bind/java/Seq.java $WORK/android/src/main/java/go/Seq.java 64 PWD=$WORK/android/src/main/java javac -d $WORK/javac-output -source 1.7 -target 1.7 -bootclasspath $ANDROID_HOME/platforms/android-22/android.jar *.java 65 jar c -C $WORK/javac-output . 66 `))