Commit 7d889af2 authored by Elias Naur's avatar Elias Naur

misc/ios: include the bundle id in the GOIOS_APP_ID env variable

The iOS exec wrapper use the constant bundle id "golang.gotest" for
running Go programs on iOS. However, that only happens to work on
the old iOS builders where their provisioning profile covers
that bundle id.

Expand the detection script to list all available provisioning
profiles for the attached device and include the bundle id in the
GOIOS_APP_ID environment variable.

To allow the old builders to continue, the "golang.gotest" bundle
id is used as a fallback if only the app id prefix is specified in
GOIOS_APP_ID.

For the new builders.

Change-Id: I8baa1d4d57f845de851c3fad3f178e05e9a01b17
Reviewed-on: https://go-review.googlesource.com/36060Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent ade6bcf1
...@@ -23,28 +23,37 @@ import ( ...@@ -23,28 +23,37 @@ import (
func main() { func main() {
devID := detectDevID() devID := detectDevID()
fmt.Printf("export GOIOS_DEV_ID=%s\n", devID)
udid := detectUDID() udid := detectUDID()
mp := detectMobileProvisionFile(udid) mps := detectMobileProvisionFiles(udid)
if len(mps) == 0 {
f, err := ioutil.TempFile("", "go_ios_detect_") fail("did not find mobile provision matching device udid %s", udid)
check(err) }
fname := f.Name()
defer os.Remove(fname)
out := output(parseMobileProvision(mp))
_, err = f.Write(out)
check(err)
check(f.Close())
appID, err := plistExtract(fname, "ApplicationIdentifierPrefix:0")
check(err)
fmt.Printf("export GOIOS_APP_ID=%s\n", appID)
teamID, err := plistExtract(fname, "Entitlements:com.apple.developer.team-identifier") fmt.Println("Available provisioning profiles below.")
check(err) fmt.Println("NOTE: Any existing app on the device with the app id specified by GOIOS_APP_ID")
fmt.Printf("export GOIOS_TEAM_ID=%s\n", teamID) fmt.Println("will be overwritten when running Go programs.")
for _, mp := range mps {
fmt.Println()
fmt.Printf("export GOIOS_DEV_ID=%s\n", devID)
f, err := ioutil.TempFile("", "go_ios_detect_")
check(err)
fname := f.Name()
defer os.Remove(fname)
out := output(parseMobileProvision(mp))
_, err = f.Write(out)
check(err)
check(f.Close())
appID, err := plistExtract(fname, "Entitlements:application-identifier")
check(err)
fmt.Printf("export GOIOS_APP_ID=%s\n", appID)
teamID, err := plistExtract(fname, "Entitlements:com.apple.developer.team-identifier")
check(err)
fmt.Printf("export GOIOS_TEAM_ID=%s\n", teamID)
}
} }
func detectDevID() string { func detectDevID() string {
...@@ -79,10 +88,11 @@ func detectUDID() []byte { ...@@ -79,10 +88,11 @@ func detectUDID() []byte {
panic("unreachable") panic("unreachable")
} }
func detectMobileProvisionFile(udid []byte) string { func detectMobileProvisionFiles(udid []byte) []string {
cmd := exec.Command("mdfind", "-name", ".mobileprovision") cmd := exec.Command("mdfind", "-name", ".mobileprovision")
lines := getLines(cmd) lines := getLines(cmd)
var files []string
for _, line := range lines { for _, line := range lines {
if len(line) == 0 { if len(line) == 0 {
continue continue
...@@ -90,12 +100,11 @@ func detectMobileProvisionFile(udid []byte) string { ...@@ -90,12 +100,11 @@ func detectMobileProvisionFile(udid []byte) string {
xmlLines := getLines(parseMobileProvision(string(line))) xmlLines := getLines(parseMobileProvision(string(line)))
for _, xmlLine := range xmlLines { for _, xmlLine := range xmlLines {
if bytes.Contains(xmlLine, udid) { if bytes.Contains(xmlLine, udid) {
return string(line) files = append(files, string(line))
} }
} }
} }
fail("did not find mobile provision matching device udid %s", udid) return files
panic("ureachable")
} }
func parseMobileProvision(fname string) *exec.Cmd { func parseMobileProvision(fname string) *exec.Cmd {
......
...@@ -45,9 +45,10 @@ var errRetry = errors.New("failed to start test harness (retry attempted)") ...@@ -45,9 +45,10 @@ var errRetry = errors.New("failed to start test harness (retry attempted)")
var tmpdir string var tmpdir string
var ( var (
devID string devID string
appID string appID string
teamID string teamID string
bundleID string
) )
// lock is a file lock to serialize iOS runs. It is global to avoid the // lock is a file lock to serialize iOS runs. It is global to avoid the
...@@ -76,6 +77,13 @@ func main() { ...@@ -76,6 +77,13 @@ func main() {
// https://developer.apple.com/membercenter/index.action#accountSummary as Team ID. // https://developer.apple.com/membercenter/index.action#accountSummary as Team ID.
teamID = getenv("GOIOS_TEAM_ID") teamID = getenv("GOIOS_TEAM_ID")
parts := strings.SplitN(appID, ".", 2)
// For compatibility with the old builders, use a fallback bundle ID
bundleID = "golang.gotest"
if len(parts) == 2 {
bundleID = parts[1]
}
var err error var err error
tmpdir, err = ioutil.TempDir("", "go_darwin_arm_exec_") tmpdir, err = ioutil.TempDir("", "go_darwin_arm_exec_")
if err != nil { if err != nil {
...@@ -143,7 +151,7 @@ func run(bin string, args []string) (err error) { ...@@ -143,7 +151,7 @@ func run(bin string, args []string) (err error) {
if err := ioutil.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil { if err := ioutil.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil {
return err return err
} }
if err := ioutil.WriteFile(filepath.Join(appdir, "Info.plist"), []byte(infoPlist), 0744); err != nil { if err := ioutil.WriteFile(filepath.Join(appdir, "Info.plist"), []byte(infoPlist()), 0744); err != nil {
return err return err
} }
if err := ioutil.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil { if err := ioutil.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil {
...@@ -562,7 +570,8 @@ func subdir() (pkgpath string, underGoRoot bool, err error) { ...@@ -562,7 +570,8 @@ func subdir() (pkgpath string, underGoRoot bool, err error) {
) )
} }
const infoPlist = `<?xml version="1.0" encoding="UTF-8"?> func infoPlist() string {
return `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
...@@ -570,13 +579,14 @@ const infoPlist = `<?xml version="1.0" encoding="UTF-8"?> ...@@ -570,13 +579,14 @@ const infoPlist = `<?xml version="1.0" encoding="UTF-8"?>
<key>CFBundleSupportedPlatforms</key><array><string>iPhoneOS</string></array> <key>CFBundleSupportedPlatforms</key><array><string>iPhoneOS</string></array>
<key>CFBundleExecutable</key><string>gotest</string> <key>CFBundleExecutable</key><string>gotest</string>
<key>CFBundleVersion</key><string>1.0</string> <key>CFBundleVersion</key><string>1.0</string>
<key>CFBundleIdentifier</key><string>golang.gotest</string> <key>CFBundleIdentifier</key><string>` + bundleID + `</string>
<key>CFBundleResourceSpecification</key><string>ResourceRules.plist</string> <key>CFBundleResourceSpecification</key><string>ResourceRules.plist</string>
<key>LSRequiresIPhoneOS</key><true/> <key>LSRequiresIPhoneOS</key><true/>
<key>CFBundleDisplayName</key><string>gotest</string> <key>CFBundleDisplayName</key><string>gotest</string>
</dict> </dict>
</plist> </plist>
` `
}
func entitlementsPlist() string { func entitlementsPlist() string {
return `<?xml version="1.0" encoding="UTF-8"?> return `<?xml version="1.0" encoding="UTF-8"?>
...@@ -584,11 +594,11 @@ func entitlementsPlist() string { ...@@ -584,11 +594,11 @@ func entitlementsPlist() string {
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>keychain-access-groups</key> <key>keychain-access-groups</key>
<array><string>` + appID + `.golang.gotest</string></array> <array><string>` + appID + `</string></array>
<key>get-task-allow</key> <key>get-task-allow</key>
<true/> <true/>
<key>application-identifier</key> <key>application-identifier</key>
<string>` + appID + `.golang.gotest</string> <string>` + appID + `</string>
<key>com.apple.developer.team-identifier</key> <key>com.apple.developer.team-identifier</key>
<string>` + teamID + `</string> <string>` + teamID + `</string>
</dict> </dict>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment