Update iOS codesign options

This commit is contained in:
Kostiantyn Syrykh 2021-03-17 17:20:49 +02:00
parent 1a3fb61b37
commit e587305308
3 changed files with 39 additions and 28 deletions

View file

@ -307,9 +307,15 @@ ios.codesign.allowed = false
# Get a list of available identities: buildozer ios list_identities # Get a list of available identities: buildozer ios list_identities
#ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)" #ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)"
# (str) The development team to use for signing the debug version
#ios.codesign.development_team.debug = <hexstring>
# (str) Name of the certificate to use for signing the release version # (str) Name of the certificate to use for signing the release version
#ios.codesign.release = %(ios.codesign.debug)s #ios.codesign.release = %(ios.codesign.debug)s
# (str) The development team to use for signing the release version
#ios.codesign.development_team.release = <hexstring>
[buildozer] [buildozer]

View file

@ -115,8 +115,8 @@ class TargetIos(Target):
kwargs.setdefault('cwd', self.ios_dir) kwargs.setdefault('cwd', self.ios_dir)
return self.buildozer.cmd(self._toolchain_cmd + cmd, **kwargs) return self.buildozer.cmd(self._toolchain_cmd + cmd, **kwargs)
def xcodebuild(self, cmd='', **kwargs): def xcodebuild(self, *args, **kwargs):
return self.buildozer.cmd(self._xcodebuild_cmd + cmd, **kwargs) return self.buildozer.cmd(self._xcodebuild_cmd + ' '.join(arg for arg in args if arg is not None), **kwargs)
@property @property
def code_signing_allowed(self): def code_signing_allowed(self):
@ -124,6 +124,11 @@ class TargetIos(Target):
allowed = "YES" if allowed else "NO" allowed = "YES" if allowed else "NO"
return f"CODE_SIGNING_ALLOWED={allowed}" return f"CODE_SIGNING_ALLOWED={allowed}"
@property
def code_signing_development_team(self):
team = self.buildozer.config.getdefault("app", f"ios.codesign.development_team.{self.build_mode}", None)
return f"DEVELOPMENT_TEAM={team}" if team else None
def get_available_packages(self): def get_available_packages(self):
available_modules = self.toolchain("recipes --compact", get_stdout=True)[0] available_modules = self.toolchain("recipes --compact", get_stdout=True)[0]
return available_modules.splitlines()[0].split() return available_modules.splitlines()[0].split()
@ -216,7 +221,12 @@ class TargetIos(Target):
mode = self.build_mode.capitalize() mode = self.build_mode.capitalize()
self.xcodebuild( self.xcodebuild(
f"-configuration {mode} ENABLE_BITCODE=NO {self.code_signing_allowed} clean build", f'-configuration {mode}',
'-allowProvisioningUpdates',
'ENABLE_BITCODE=NO',
self.code_signing_allowed,
self.code_signing_development_team,
'clean build',
cwd=self.app_project_dir) cwd=self.app_project_dir)
ios_app_dir = '{app_lower}-ios/build/{mode}-iphoneos/{app_lower}.app'.format( ios_app_dir = '{app_lower}-ios/build/{mode}-iphoneos/{app_lower}.app'.format(
app_lower=app_name.lower(), mode=mode) app_lower=app_name.lower(), mode=mode)
@ -242,25 +252,24 @@ class TargetIos(Target):
self.buildozer.rmdir(intermediate_dir) self.buildozer.rmdir(intermediate_dir)
self.buildozer.info('Creating archive...') self.buildozer.info('Creating archive...')
self.xcodebuild(( self.xcodebuild(
' -alltargets' '-alltargets',
' -configuration {mode}' f'-configuration {mode}',
' -scheme {scheme}' f'-scheme {app_name.lower()}',
' -archivePath "{xcarchive}"' f'-archivePath "{xcarchive}"',
' archive' 'archive',
' ENABLE_BITCODE=NO' 'ENABLE_BITCODE=NO',
).format(mode=mode, xcarchive=xcarchive, scheme=app_name.lower()), self.code_signing_development_team,
cwd=build_dir) cwd=build_dir)
self.buildozer.info('Creating IPA...') self.buildozer.info('Creating IPA...')
self.xcodebuild(( self.xcodebuild(
' -exportArchive' '-exportArchive',
' -exportFormat IPA' f'-archivePath "{xcarchive}"',
' -archivePath "{xcarchive}"' f'-exportOptionsPlist "{plist_rfn}"',
' -exportPath "{ipa}"' f'-exportPath "{ipa_tmp}"',
' CODE_SIGN_IDENTITY={ioscodesign}' f'CODE_SIGN_IDENTITY={ioscodesign}',
' ENABLE_BITCODE=NO' 'ENABLE_BITCODE=NO',
).format(xcarchive=xcarchive, ipa=ipa_tmp, ioscodesign=ioscodesign),
cwd=build_dir) cwd=build_dir)
self.buildozer.info('Moving IPA to bin...') self.buildozer.info('Moving IPA to bin...')

View file

@ -182,7 +182,6 @@ class TestTargetIos:
# fmt: off # fmt: off
with patch_target_ios("_unlock_keychain") as m_unlock_keychain, \ with patch_target_ios("_unlock_keychain") as m_unlock_keychain, \
patch_buildozer_error() as m_error, \ patch_buildozer_error() as m_error, \
patch_target_ios("xcodebuild") as m_xcodebuild, \
mock.patch("buildozer.targets.ios.plistlib.readPlist") as m_readplist, \ mock.patch("buildozer.targets.ios.plistlib.readPlist") as m_readplist, \
mock.patch("buildozer.targets.ios.plistlib.writePlist") as m_writeplist, \ mock.patch("buildozer.targets.ios.plistlib.writePlist") as m_writeplist, \
patch_buildozer_cmd() as m_cmd: patch_buildozer_cmd() as m_cmd:
@ -196,13 +195,6 @@ class TestTargetIos:
'You must fill the "ios.codesign.debug" token.' 'You must fill the "ios.codesign.debug" token.'
) )
] ]
assert m_xcodebuild.call_args_list == [
mock.call(
"-configuration Debug ENABLE_BITCODE=NO "
"CODE_SIGNING_ALLOWED=NO clean build",
cwd="/ios/dir/myapp-ios",
)
]
assert m_readplist.call_args_list == [ assert m_readplist.call_args_list == [
mock.call("/ios/dir/myapp-ios/myapp-Info.plist") mock.call("/ios/dir/myapp-ios/myapp-Info.plist")
] ]
@ -216,4 +208,8 @@ class TestTargetIos:
"/ios/dir/myapp-ios/myapp-Info.plist", "/ios/dir/myapp-ios/myapp-Info.plist",
) )
] ]
assert m_cmd.call_args_list == [mock.call(mock.ANY, cwd=target.ios_dir)] assert m_cmd.call_args_list == [mock.call(mock.ANY, cwd=target.ios_dir), mock.call(
"xcodebuild -configuration Debug -allowProvisioningUpdates ENABLE_BITCODE=NO "
"CODE_SIGNING_ALLOWED=NO clean build",
cwd="/ios/dir/myapp-ios",
)]