@@ -13,75 +13,92 @@ import (
13
13
)
14
14
15
15
func TestIOSBuild (t * testing.T ) {
16
- buf := new (bytes.Buffer )
17
16
defer func () {
18
17
xout = os .Stderr
19
18
buildN = false
20
19
buildX = false
21
20
}()
22
- xout = buf
23
21
buildN = true
24
22
buildX = true
25
- buildO = "basic.app"
26
23
buildTarget = "ios"
27
24
gopath = filepath .SplitList (goEnv ("GOPATH" ))[0 ]
28
- cmdBuild .flag .Parse ([]string {"golang.org/x/mobile/example/basic" })
29
25
oldTags := ctx .BuildTags
30
26
ctx .BuildTags = []string {"tag1" }
31
27
defer func () {
32
28
ctx .BuildTags = oldTags
33
29
}()
34
- err := runBuild (cmdBuild )
35
- if err != nil {
36
- t .Log (buf .String ())
37
- t .Fatal (err )
30
+ tests := []struct {
31
+ pkg string
32
+ main bool
33
+ }{
34
+ {"golang.org/x/mobile/example/basic" , true },
35
+ {"golang.org/x/mobile/bind/testdata/testpkg" , false },
38
36
}
37
+ for _ , test := range tests {
38
+ buf := new (bytes.Buffer )
39
+ xout = buf
40
+ if test .main {
41
+ buildO = "basic.app"
42
+ } else {
43
+ buildO = ""
44
+ }
45
+ cmdBuild .flag .Parse ([]string {test .pkg })
46
+ err := runBuild (cmdBuild )
47
+ if err != nil {
48
+ t .Log (buf .String ())
49
+ t .Fatal (err )
50
+ }
39
51
40
- teamID , err := detectTeamID ()
41
- if err != nil {
42
- t .Fatalf ("detecting team ID failed: %v" , err )
43
- }
52
+ teamID , err := detectTeamID ()
53
+ if err != nil {
54
+ t .Fatalf ("detecting team ID failed: %v" , err )
55
+ }
44
56
45
- data := struct {
46
- outputData
47
- TeamID string
48
- }{
49
- outputData : defaultOutputData (),
50
- TeamID : teamID ,
51
- }
57
+ data := struct {
58
+ outputData
59
+ TeamID string
60
+ Pkg string
61
+ Main bool
62
+ }{
63
+ outputData : defaultOutputData (),
64
+ TeamID : teamID ,
65
+ Pkg : test .pkg ,
66
+ Main : test .main ,
67
+ }
52
68
53
- got := filepath .ToSlash (buf .String ())
69
+ got := filepath .ToSlash (buf .String ())
54
70
55
- wantBuf := new (bytes.Buffer )
71
+ wantBuf := new (bytes.Buffer )
56
72
57
- if err := iosBuildTmpl .Execute (wantBuf , data ); err != nil {
58
- t .Fatalf ("computing diff failed: %v" , err )
59
- }
73
+ if err := iosBuildTmpl .Execute (wantBuf , data ); err != nil {
74
+ t .Fatalf ("computing diff failed: %v" , err )
75
+ }
60
76
61
- diff , err := diff (got , wantBuf .String ())
77
+ diff , err := diff (got , wantBuf .String ())
62
78
63
- if err != nil {
64
- t .Fatalf ("computing diff failed: %v" , err )
65
- }
66
- if diff != "" {
67
- t .Errorf ("unexpected output:\n %s" , diff )
79
+ if err != nil {
80
+ t .Fatalf ("computing diff failed: %v" , err )
81
+ }
82
+ if diff != "" {
83
+ t .Errorf ("unexpected output:\n %s" , diff )
84
+ }
68
85
}
69
86
}
70
87
71
88
var iosBuildTmpl = template .Must (infoplistTmpl .New ("output" ).Parse (`GOMOBILE={{.GOPATH}}/pkg/gomobile
72
- WORK=$WORK
89
+ WORK=$WORK{{if .Main}}
73
90
mkdir -p $WORK/main.xcodeproj
74
91
echo "{{.Xproj}}" > $WORK/main.xcodeproj/project.pbxproj
75
92
mkdir -p $WORK/main
76
93
echo "{{template "infoplist" .Xinfo}}" > $WORK/main/Info.plist
77
94
mkdir -p $WORK/main/Images.xcassets/AppIcon.appiconset
78
- echo "{{.Xcontents}}" > $WORK/main/Images.xcassets/AppIcon.appiconset/Contents.json
79
- GOARM=7 GOOS=darwin GOARCH=arm CC=clang-iphoneos CXX=clang-iphoneos CGO_CFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch armv7 CGO_LDFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch armv7 CGO_ENABLED=1 go build -tags tag1 ios -x -ldflags=-w -o=$WORK/arm golang.org/x/mobile/example/basic
80
- GOOS=darwin GOARCH=arm64 CC=clang-iphoneos CXX=clang-iphoneos CGO_CFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch arm64 CGO_LDFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch arm64 CGO_ENABLED=1 go build -tags tag1 ios -x -ldflags=-w -o=$WORK/arm64 golang.org/x/mobile/example/basic
81
- GOOS=darwin GOARCH=386 CC=clang-iphonesimulator CXX=clang-iphonesimulator CGO_CFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=6.1 -arch i386 CGO_LDFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=6.1 -arch i386 CGO_ENABLED=1 go build -tags tag1 ios -x -ldflags=-w -o=$WORK/386 golang.org/x/mobile/example/basic
82
- 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 build -tags tag1 ios -x -ldflags=-w -o=$WORK/amd64 golang.org/x/mobile/example/basic
95
+ echo "{{.Xcontents}}" > $WORK/main/Images.xcassets/AppIcon.appiconset/Contents.json{{end}}
96
+ GOARM=7 GOOS=darwin GOARCH=arm CC=clang-iphoneos CXX=clang-iphoneos CGO_CFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch armv7 CGO_LDFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch armv7 CGO_ENABLED=1 go build -tags tag1 ios -x {{if .Main}} -ldflags=-w -o=$WORK/arm {{end}}{{.Pkg}}
97
+ GOOS=darwin GOARCH=arm64 CC=clang-iphoneos CXX=clang-iphoneos CGO_CFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch arm64 CGO_LDFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch arm64 CGO_ENABLED=1 go build -tags tag1 ios -x {{if .Main}} -ldflags=-w -o=$WORK/arm64 {{end}}{{.Pkg}}
98
+ GOOS=darwin GOARCH=386 CC=clang-iphonesimulator CXX=clang-iphonesimulator CGO_CFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=6.1 -arch i386 CGO_LDFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=6.1 -arch i386 CGO_ENABLED=1 go build -tags tag1 ios -x {{if .Main}} -ldflags=-w -o=$WORK/386 {{end}}{{.Pkg}}
99
+ 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 build -tags tag1 ios -x {{if .Main}} -ldflags=-w -o=$WORK/amd64 {{end}}{{.Pkg}}{{if .Main}}
83
100
xcrun lipo -o $WORK/main/main -create $WORK/arm $WORK/arm64 $WORK/386 $WORK/amd64
84
101
mkdir -p $WORK/main/assets
85
102
xcrun xcodebuild -configuration Release -project $WORK/main.xcodeproj -allowProvisioningUpdates DEVELOPMENT_TEAM={{.TeamID}}
86
- mv $WORK/build/Release-iphoneos/main.app basic.app
103
+ mv $WORK/build/Release-iphoneos/main.app basic.app{{end}}
87
104
` ))
0 commit comments