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
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
defer func() {
|
|
|
|
xout = os.Stderr
|
|
|
|
buildN = false
|
|
|
|
buildX = false
|
|
|
|
}()
|
|
|
|
xout = buf
|
|
|
|
buildN = true
|
|
|
|
buildX = true
|
|
|
|
buildO = "basic.app"
|
|
|
|
buildTarget = "ios"
|
2018-03-16 11:20:43 +01:00
|
|
|
gopath = filepath.SplitList(goEnv("GOPATH"))[0]
|
2015-07-25 09:58:42 -04:00
|
|
|
cmdBuild.flag.Parse([]string{"golang.org/x/mobile/example/basic"})
|
2018-03-16 08:34:03 +01:00
|
|
|
oldTags := ctx.BuildTags
|
2015-10-28 12:45:15 -07:00
|
|
|
ctx.BuildTags = []string{"tag1"}
|
2018-03-16 08:34:03 +01:00
|
|
|
defer func() {
|
|
|
|
ctx.BuildTags = oldTags
|
|
|
|
}()
|
2015-07-25 09:58:42 -04:00
|
|
|
err := runBuild(cmdBuild)
|
|
|
|
if err != nil {
|
|
|
|
t.Log(buf.String())
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-07-21 14:45:53 -07:00
|
|
|
|
2017-11-10 14:20:07 -05:00
|
|
|
teamID, err := detectTeamID()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("detecting team ID failed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
data := struct {
|
|
|
|
outputData
|
|
|
|
TeamID string
|
|
|
|
}{
|
|
|
|
outputData: defaultOutputData(),
|
|
|
|
TeamID: teamID,
|
|
|
|
}
|
|
|
|
|
|
|
|
got := filepath.ToSlash(buf.String())
|
|
|
|
|
|
|
|
wantBuf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
if err := iosBuildTmpl.Execute(wantBuf, data); err != nil {
|
|
|
|
t.Fatalf("computing diff failed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
diff, err := diff(got, wantBuf.String())
|
|
|
|
|
2015-07-25 09:58:42 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("computing diff failed: %v", err)
|
|
|
|
}
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("unexpected output:\n%s", diff)
|
|
|
|
}
|
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
|
2015-07-21 14:45:53 -07:00
|
|
|
WORK=$WORK
|
|
|
|
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
|
2015-07-25 21:26:28 -04:00
|
|
|
echo "{{.Xcontents}}" > $WORK/main/Images.xcassets/AppIcon.appiconset/Contents.json
|
2018-04-28 17:36:34 +02:00
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
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}}
|
2015-07-21 14:45:53 -07:00
|
|
|
mv $WORK/build/Release-iphoneos/main.app basic.app
|
|
|
|
`))
|