func main() {
devID := detectDevID()
- fmt.Printf("export GOIOS_DEV_ID=%s\n", devID)
udid := detectUDID()
- mp := detectMobileProvisionFile(udid)
-
- 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, "ApplicationIdentifierPrefix:0")
- check(err)
- fmt.Printf("export GOIOS_APP_ID=%s\n", appID)
+ mps := detectMobileProvisionFiles(udid)
+ if len(mps) == 0 {
+ fail("did not find mobile provision matching device udid %s", udid)
+ }
- teamID, err := plistExtract(fname, "Entitlements:com.apple.developer.team-identifier")
- check(err)
- fmt.Printf("export GOIOS_TEAM_ID=%s\n", teamID)
+ fmt.Println("Available provisioning profiles below.")
+ fmt.Println("NOTE: Any existing app on the device with the app id specified by GOIOS_APP_ID")
+ 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 {
panic("unreachable")
}
-func detectMobileProvisionFile(udid []byte) string {
+func detectMobileProvisionFiles(udid []byte) []string {
cmd := exec.Command("mdfind", "-name", ".mobileprovision")
lines := getLines(cmd)
+ var files []string
for _, line := range lines {
if len(line) == 0 {
continue
xmlLines := getLines(parseMobileProvision(string(line)))
for _, xmlLine := range xmlLines {
if bytes.Contains(xmlLine, udid) {
- return string(line)
+ files = append(files, string(line))
}
}
}
- fail("did not find mobile provision matching device udid %s", udid)
- panic("ureachable")
+ return files
}
func parseMobileProvision(fname string) *exec.Cmd {
var tmpdir string
var (
- devID string
- appID string
- teamID string
+ devID string
+ appID string
+ teamID string
+ bundleID string
)
// lock is a file lock to serialize iOS runs. It is global to avoid the
// https://developer.apple.com/membercenter/index.action#accountSummary as 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
tmpdir, err = ioutil.TempDir("", "go_darwin_arm_exec_")
if err != nil {
if err := ioutil.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil {
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
}
if err := ioutil.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil {
)
}
-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">
<plist version="1.0">
<dict>
<key>CFBundleSupportedPlatforms</key><array><string>iPhoneOS</string></array>
<key>CFBundleExecutable</key><string>gotest</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>LSRequiresIPhoneOS</key><true/>
<key>CFBundleDisplayName</key><string>gotest</string>
</dict>
</plist>
`
+}
func entitlementsPlist() string {
return `<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>keychain-access-groups</key>
- <array><string>` + appID + `.golang.gotest</string></array>
+ <array><string>` + appID + `</string></array>
<key>get-task-allow</key>
<true/>
<key>application-identifier</key>
- <string>` + appID + `.golang.gotest</string>
+ <string>` + appID + `</string>
<key>com.apple.developer.team-identifier</key>
<string>` + teamID + `</string>
</dict>