Skip to content

Commit a425ddd

Browse files
committed
gogio: [macOS] support custom profile
Signed-off-by: inkeliz <inkeliz@inkeliz.com>
1 parent fbaf9a3 commit a425ddd

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

gogio/help.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ its deletion.
6565
The -x flag will print all the external commands executed by the gogio tool.
6666
6767
The -signkey flag specifies the path of the keystore, used for signing Android apk/aab files
68-
or specifies the name of key on Keychain to sign MacOS app.
68+
or specifies the name of key on Keychain to sign MacOS app. On iOS/macOS it can be used to
69+
specify the path of provisioning profile (.mobileprovision/.provisionprofile).
6970
7071
The -signpass flag specifies the password of the keystore, ignored if -signkey is not provided.
7172

gogio/iosbuild.go

+35-9
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func buildIOS(tmpDir, target string, bi *buildInfo) error {
7777
if err := exeIOS(tmpDir, target, appDir, bi); err != nil {
7878
return err
7979
}
80-
if err := signIOS(bi, tmpDir, appDir); err != nil {
80+
embedded := filepath.Join(appDir, "embedded.mobileprovision")
81+
if err := signApple(bi, tmpDir, embedded, appDir); err != nil {
8182
return err
8283
}
8384
return zipDir(out, tmpDir, "Payload")
@@ -86,16 +87,27 @@ func buildIOS(tmpDir, target string, bi *buildInfo) error {
8687
}
8788
}
8889

89-
func signIOS(bi *buildInfo, tmpDir, app string) error {
90+
// signApple is shared between iOS and macOS.
91+
func signApple(bi *buildInfo, tmpDir, embedded, app string) error {
9092
home, err := os.UserHomeDir()
9193
if err != nil {
9294
return err
9395
}
94-
provPattern := filepath.Join(home, "Library", "MobileDevice", "Provisioning Profiles", "*.mobileprovision")
95-
provisions, err := filepath.Glob(provPattern)
96-
if err != nil {
97-
return err
96+
97+
var provisions []string
98+
if bi.key != "" {
99+
if filepath.Ext(bi.key) != ".mobileprovision" && filepath.Ext(bi.key) != ".provisionprofile" {
100+
return fmt.Errorf("sign: on iOS/macOS -key is a provisioning profile, %q does not end in .mobileprovision/.provisionprofile", bi.key)
101+
}
102+
provisions = []string{bi.key}
103+
} else {
104+
provPattern := filepath.Join(home, "Library", "MobileDevice", "Provisioning Profiles", "*.mobileprovision")
105+
provisions, err = filepath.Glob(provPattern)
106+
if err != nil {
107+
return err
108+
}
98109
}
110+
99111
provInfo := filepath.Join(tmpDir, "provision.plist")
100112
var avail []string
101113
for _, prov := range provisions {
@@ -119,7 +131,14 @@ func signIOS(bi *buildInfo, tmpDir, app string) error {
119131
if err != nil {
120132
return err
121133
}
122-
provAppID, err := runCmd(exec.Command("/usr/libexec/PlistBuddy", "-c", "Print:Entitlements:application-identifier", provInfo))
134+
135+
// iOS/macOS Catalyst
136+
provAppIDSearchKey := "Print:Entitlements:application-identifier"
137+
if filepath.Ext(prov) == ".provisionprofile" {
138+
// macOS
139+
provAppIDSearchKey = "Print:Entitlements:com.apple.application-identifier"
140+
}
141+
provAppID, err := runCmd(exec.Command("/usr/libexec/PlistBuddy", "-c", provAppIDSearchKey, provInfo))
123142
if err != nil {
124143
return err
125144
}
@@ -129,7 +148,6 @@ func signIOS(bi *buildInfo, tmpDir, app string) error {
129148
continue
130149
}
131150
// Copy provisioning file.
132-
embedded := filepath.Join(app, "embedded.mobileprovision")
133151
if err := copyFile(embedded, prov); err != nil {
134152
return err
135153
}
@@ -149,7 +167,15 @@ func signIOS(bi *buildInfo, tmpDir, app string) error {
149167
}
150168
identity := sha1.Sum(certDER)
151169
idHex := hex.EncodeToString(identity[:])
152-
_, err = runCmd(exec.Command("codesign", "-s", idHex, "-v", "--entitlements", entFile, app))
170+
_, err = runCmd(exec.Command(
171+
"codesign",
172+
"--sign", idHex,
173+
"--deep",
174+
"--force",
175+
"--options", "runtime",
176+
"--entitlements",
177+
entFile,
178+
app))
153179
return err
154180
}
155181
return fmt.Errorf("sign: no valid provisioning profile found for bundle id %q among %v", bi.appID, avail)

gogio/macosbuild.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (b *macBuilder) setInfo(buildInfo *buildInfo, name string) error {
151151
<key>NSHighResolutionCapable</key>
152152
<true/>
153153
<key>CFBundlePackageType</key>
154-
<string>APPL</string>
154+
<string>BNDL</string>
155155
{{if .Schemes}}
156156
<key>CFBundleURLTypes</key>
157157
<array>
@@ -237,6 +237,12 @@ func (b *macBuilder) signProgram(buildInfo *buildInfo, binDest string, name stri
237237
return err
238238
}
239239

240+
// If the key is a provisioning profile use the same signing process as iOS
241+
if strings.HasSuffix(buildInfo.key, ".provisionprofile") {
242+
embedded := filepath.Join(binDest, "Contents", "embedded.provisionprofile")
243+
return signApple(buildInfo, b.TempDir, embedded, binDest)
244+
}
245+
240246
cmd := exec.Command(
241247
"codesign",
242248
"--deep",

gogio/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var (
3636
extraLdflags = flag.String("ldflags", "", "extra flags to the Go linker")
3737
extraTags = flag.String("tags", "", "extra tags to the Go tool")
3838
iconPath = flag.String("icon", "", "specify an icon for iOS and Android")
39-
signKey = flag.String("signkey", "", "specify the path of the keystore to be used to sign Android apk files.")
39+
signKey = flag.String("signkey", "", "specify the path of the keystore to be used to sign Android apk files and macOS app. It can be used for iOS and macOS to specify Provisioning Profiles.")
4040
signPass = flag.String("signpass", "", "specify the password to decrypt the signkey.")
4141
schemes = flag.String("schemes", "", "specify a list of comma separated deep-linking schemes that the program accepts")
4242
notaryID = flag.String("notaryid", "", "specify the apple id to use for notarization.")

0 commit comments

Comments
 (0)