2015-07-21 14:45:53 -07: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 (
|
2015-07-25 09:58:42 -04:00
|
|
|
"bytes"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"text/template"
|
2015-07-21 14:45:53 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIOSBuild(t *testing.T) {
|
2015-07-25 09:58:42 -04:00
|
|
|
defer func() {
|
|
|
|
xout = os.Stderr
|
|
|
|
buildN = false
|
|
|
|
buildX = false
|
|
|
|
}()
|
|
|
|
buildN = true
|
|
|
|
buildX = true
|
|
|
|
buildTarget = "ios"
|
2019-03-06 01:10:55 +01:00
|
|
|
buildBundleID = "org.golang.todo"
|
2018-03-16 11:20:43 +01:00
|
|
|
gopath = filepath.SplitList(goEnv("GOPATH"))[0]
|
2019-11-20 16:55:32 +09:00
|
|
|
oldTags := buildTags
|
|
|
|
buildTags = []string{"tag1"}
|
2018-03-16 08:34:03 +01:00
|
|
|
defer func() {
|
2019-11-20 16:55:32 +09:00
|
|
|
buildTags = oldTags
|
2018-03-16 08:34:03 +01:00
|
|
|
}()
|
2018-06-18 22:54:52 +02:00
|
|
|
tests := []struct {
|
|
|
|
pkg string
|
|
|
|
main bool
|
|
|
|
}{
|
|
|
|
{"golang.org/x/mobile/example/basic", true},
|
|
|
|
{"golang.org/x/mobile/bind/testdata/testpkg", false},
|
2015-07-25 09:58:42 -04:00
|
|
|
}
|
2018-06-18 22:54:52 +02:00
|
|
|
for _, test := range tests {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
xout = buf
|
|
|
|
if test.main {
|
|
|
|
buildO = "basic.app"
|
|
|
|
} else {
|
|
|
|
buildO = ""
|
|
|
|
}
|
|
|
|
cmdBuild.flag.Parse([]string{test.pkg})
|
|
|
|
err := runBuild(cmdBuild)
|
|
|
|
if err != nil {
|
|
|
|
t.Log(buf.String())
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-07-21 14:45:53 -07:00
|
|
|
|
2018-06-18 22:54:52 +02:00
|
|
|
teamID, err := detectTeamID()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("detecting team ID failed: %v", err)
|
|
|
|
}
|
2017-11-10 14:20:07 -05:00
|
|
|
|
2018-06-18 22:54:52 +02:00
|
|
|
data := struct {
|
|
|
|
outputData
|
|
|
|
TeamID string
|
|
|
|
Pkg string
|
|
|
|
Main bool
|
|
|
|
}{
|
|
|
|
outputData: defaultOutputData(),
|
|
|
|
TeamID: teamID,
|
|
|
|
Pkg: test.pkg,
|
|
|
|
Main: test.main,
|
|
|
|
}
|
2017-11-10 14:20:07 -05:00
|
|
|
|
2018-06-18 22:54:52 +02:00
|
|
|
got := filepath.ToSlash(buf.String())
|
2017-11-10 14:20:07 -05:00
|
|
|
|
2018-06-18 22:54:52 +02:00
|
|
|
wantBuf := new(bytes.Buffer)
|
2017-11-10 14:20:07 -05:00
|
|
|
|
2018-06-18 22:54:52 +02:00
|
|
|
if err := iosBuildTmpl.Execute(wantBuf, data); err != nil {
|
|
|
|
t.Fatalf("computing diff failed: %v", err)
|
|
|
|
}
|
2017-11-10 14:20:07 -05:00
|
|
|
|
2018-06-18 22:54:52 +02:00
|
|
|
diff, err := diff(got, wantBuf.String())
|
2017-11-10 14:20:07 -05:00
|
|
|
|
2018-06-18 22:54:52 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("computing diff failed: %v", err)
|
|
|
|
}
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("unexpected output:\n%s", diff)
|
|
|
|
}
|
2015-07-25 09:58:42 -04:00
|
|
|
}
|
2015-07-21 14:45:53 -07:00
|
|
|
}
|
|
|
|
|
2015-07-25 21:26:28 -04:00
|
|
|
var iosBuildTmpl = template.Must(infoplistTmpl.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
|
2018-06-18 22:54:52 +02:00
|
|
|
WORK=$WORK{{if .Main}}
|
2015-07-21 14:45:53 -07:00
|
|
|
mkdir -p $WORK/main.xcodeproj
|
2015-07-25 21:26:28 -04:00
|
|
|
echo "{{.Xproj}}" > $WORK/main.xcodeproj/project.pbxproj
|
2015-07-21 14:45:53 -07:00
|
|
|
mkdir -p $WORK/main
|
2015-07-25 21:26:28 -04:00
|
|
|
echo "{{template "infoplist" .Xinfo}}" > $WORK/main/Info.plist
|
2015-07-21 14:45:53 -07:00
|
|
|
mkdir -p $WORK/main/Images.xcassets/AppIcon.appiconset
|
2018-06-18 22:54:52 +02:00
|
|
|
echo "{{.Xcontents}}" > $WORK/main/Images.xcassets/AppIcon.appiconset/Contents.json{{end}}
|
2019-03-19 17:20:14 +02:00
|
|
|
GOARM=7 GOOS=darwin GOARCH=arm CC=iphoneos-clang CXX=iphoneos-clang++ CGO_CFLAGS=-isysroot=iphoneos -miphoneos-version-min=7.0 -fembed-bitcode -arch armv7 CGO_CXXFLAGS=-isysroot=iphoneos -miphoneos-version-min=7.0 -fembed-bitcode -arch armv7 CGO_LDFLAGS=-isysroot=iphoneos -miphoneos-version-min=7.0 -fembed-bitcode -arch armv7 CGO_ENABLED=1 GO111MODULE=off go build -tags tag1 ios -x {{if .Main}}-ldflags=-w -o=$WORK/arm {{end}}{{.Pkg}}
|
|
|
|
GOOS=darwin GOARCH=arm64 CC=iphoneos-clang CXX=iphoneos-clang++ CGO_CFLAGS=-isysroot=iphoneos -miphoneos-version-min=7.0 -fembed-bitcode -arch arm64 CGO_CXXFLAGS=-isysroot=iphoneos -miphoneos-version-min=7.0 -fembed-bitcode -arch arm64 CGO_LDFLAGS=-isysroot=iphoneos -miphoneos-version-min=7.0 -fembed-bitcode -arch arm64 CGO_ENABLED=1 GO111MODULE=off go build -tags tag1 ios -x {{if .Main}}-ldflags=-w -o=$WORK/arm64 {{end}}{{.Pkg}}
|
|
|
|
GOOS=darwin GOARCH=386 CC=iphonesimulator-clang CXX=iphonesimulator-clang++ CGO_CFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=7.0 -fembed-bitcode -arch i386 CGO_CXXFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=7.0 -fembed-bitcode -arch i386 CGO_LDFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=7.0 -fembed-bitcode -arch i386 CGO_ENABLED=1 GO111MODULE=off go build -tags tag1 ios -x {{if .Main}}-ldflags=-w -o=$WORK/386 {{end}}{{.Pkg}}
|
|
|
|
GOOS=darwin GOARCH=amd64 CC=iphonesimulator-clang CXX=iphonesimulator-clang++ CGO_CFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=7.0 -fembed-bitcode -arch x86_64 CGO_CXXFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=7.0 -fembed-bitcode -arch x86_64 CGO_LDFLAGS=-isysroot=iphonesimulator -mios-simulator-version-min=7.0 -fembed-bitcode -arch x86_64 CGO_ENABLED=1 GO111MODULE=off go build -tags tag1 ios -x {{if .Main}}-ldflags=-w -o=$WORK/amd64 {{end}}{{.Pkg}}{{if .Main}}
|
2018-04-03 16:39:25 +02:00
|
|
|
xcrun lipo -o $WORK/main/main -create $WORK/arm $WORK/arm64 $WORK/386 $WORK/amd64
|
2015-07-21 14:45:53 -07:00
|
|
|
mkdir -p $WORK/main/assets
|
2017-11-10 14:20:07 -05:00
|
|
|
xcrun xcodebuild -configuration Release -project $WORK/main.xcodeproj -allowProvisioningUpdates DEVELOPMENT_TEAM={{.TeamID}}
|
2018-06-18 22:54:52 +02:00
|
|
|
mv $WORK/build/Release-iphoneos/main.app basic.app{{end}}
|
2015-07-21 14:45:53 -07:00
|
|
|
`))
|