github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/cmd/gomobile/build_darwin_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 func TestIOSBuild(t *testing.T) { 16 buf := new(bytes.Buffer) 17 defer func() { 18 xout = os.Stderr 19 buildN = false 20 buildX = false 21 }() 22 xout = buf 23 buildN = true 24 buildX = true 25 buildO = "basic.app" 26 buildTarget = "ios" 27 gopath = filepath.SplitList(os.Getenv("GOPATH"))[0] 28 cmdBuild.flag.Parse([]string{"github.com/c-darwin/mobile/example/basic"}) 29 err := runBuild(cmdBuild) 30 if err != nil { 31 t.Log(buf.String()) 32 t.Fatal(err) 33 } 34 35 diff, err := diffOutput(buf.String(), iosBuildTmpl) 36 if err != nil { 37 t.Fatalf("computing diff failed: %v", err) 38 } 39 if diff != "" { 40 t.Errorf("unexpected output:\n%s", diff) 41 } 42 } 43 44 var iosBuildTmpl = template.Must(infoplistTmpl.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile 45 WORK=$WORK 46 mkdir -p $WORK/main.xcodeproj 47 echo "{{.Xproj}}" > $WORK/main.xcodeproj/project.pbxproj 48 mkdir -p $WORK/main 49 echo "{{template "infoplist" .Xinfo}}" > $WORK/main/Info.plist 50 mkdir -p $WORK/main/Images.xcassets/AppIcon.appiconset 51 echo "{{.Xcontents}}" > $WORK/main/Images.xcassets/AppIcon.appiconset/Contents.json 52 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 build -p={{.NumCPU}} -pkgdir=$GOMOBILE/pkg_darwin_arm -tags="" -x -tags=ios -o=$WORK/arm github.com/c-darwin/mobile/example/basic 53 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 build -p={{.NumCPU}} -pkgdir=$GOMOBILE/pkg_darwin_arm64 -tags="" -x -tags=ios -o=$WORK/arm64 github.com/c-darwin/mobile/example/basic 54 xcrun lipo -create $WORK/arm $WORK/arm64 -o $WORK/main/main 55 mkdir -p $WORK/main/assets 56 xcrun xcodebuild -configuration Release -project $WORK/main.xcodeproj 57 mv $WORK/build/Release-iphoneos/main.app basic.app 58 `))