github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/mobile/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{"golang.org/x/mobile/example/basic"}) 29 ctx.BuildTags = []string{"tag1"} 30 err := runBuild(cmdBuild) 31 if err != nil { 32 t.Log(buf.String()) 33 t.Fatal(err) 34 } 35 36 diff, err := diffOutput(buf.String(), iosBuildTmpl) 37 if err != nil { 38 t.Fatalf("computing diff failed: %v", err) 39 } 40 if diff != "" { 41 t.Errorf("unexpected output:\n%s", diff) 42 } 43 } 44 45 var iosBuildTmpl = template.Must(infoplistTmpl.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile 46 WORK=$WORK 47 mkdir -p $WORK/main.xcodeproj 48 echo "{{.Xproj}}" > $WORK/main.xcodeproj/project.pbxproj 49 mkdir -p $WORK/main 50 echo "{{template "infoplist" .Xinfo}}" > $WORK/main/Info.plist 51 mkdir -p $WORK/main/Images.xcassets/AppIcon.appiconset 52 echo "{{.Xcontents}}" > $WORK/main/Images.xcassets/AppIcon.appiconset/Contents.json 53 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="tag1,ios" -x -o=$WORK/arm golang.org/x/mobile/example/basic 54 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="tag1,ios" -x -o=$WORK/arm64 golang.org/x/mobile/example/basic 55 xcrun lipo -create $WORK/arm $WORK/arm64 -o $WORK/main/main 56 mkdir -p $WORK/main/assets 57 xcrun xcodebuild -configuration Release -project $WORK/main.xcodeproj 58 mv $WORK/build/Release-iphoneos/main.app basic.app 59 `))