2020-07-20 18:46:15 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
# ----------------------------------------------------------------------------
|
2021-05-18 16:40:30 +08:00
|
|
|
# adxe "dist" plugin
|
2020-07-20 18:46:15 +08:00
|
|
|
#
|
|
|
|
# Copyright 2014 (C) Luis Parravicini
|
|
|
|
#
|
|
|
|
# License: MIT
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
'''
|
2021-05-18 16:40:30 +08:00
|
|
|
"dist" plugin for adxe command line tool
|
2020-07-20 18:46:15 +08:00
|
|
|
'''
|
|
|
|
|
|
|
|
__docformat__ = 'restructuredtext'
|
|
|
|
|
|
|
|
import re
|
|
|
|
import os
|
2021-05-18 16:40:30 +08:00
|
|
|
import adxe
|
2020-07-20 18:46:15 +08:00
|
|
|
|
2021-05-18 16:40:30 +08:00
|
|
|
class CCPluginDist(adxe.CCPlugin):
|
2020-07-20 18:46:15 +08:00
|
|
|
"""
|
|
|
|
builds a project for distribution
|
|
|
|
"""
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def plugin_name():
|
|
|
|
return "dist"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def brief_description():
|
|
|
|
return "builds a project for distribution"
|
|
|
|
|
|
|
|
def init(self, options, working_dir):
|
|
|
|
super(CCPluginDist, self).init(options, working_dir)
|
|
|
|
|
|
|
|
if self._platforms.is_ios_active():
|
|
|
|
if not options.provisioning:
|
2021-05-18 16:40:30 +08:00
|
|
|
raise adxe.CCPluginError("Provisioning profile is needed")
|
2020-07-20 18:46:15 +08:00
|
|
|
else:
|
|
|
|
self._provisioning = options.provisioning
|
|
|
|
|
|
|
|
def _add_custom_options(self, parser):
|
|
|
|
parser.add_option("-f", "--provisioning",
|
|
|
|
dest="provisioning",
|
|
|
|
help="provisioning profile to use (needed for iOS distribution)")
|
|
|
|
|
|
|
|
def dist_android(self):
|
|
|
|
if not self._platforms.is_android_active():
|
|
|
|
return
|
|
|
|
project_dir = self._platforms.project_path()
|
|
|
|
|
2021-05-18 16:40:30 +08:00
|
|
|
raise adxe.CCPluginError("unimplemented")
|
2020-07-20 18:46:15 +08:00
|
|
|
|
|
|
|
def _find_ios_scheme(self, project_dir):
|
|
|
|
out = self._output_for("cd \"%s\" && xcodebuild -list" % project_dir)
|
|
|
|
|
|
|
|
match = re.search('Schemes:(.*)', out, re.DOTALL)
|
|
|
|
if match is None:
|
2021-05-18 16:40:30 +08:00
|
|
|
raise adxe.CCPluginError("Couldn't find the schemes list")
|
2020-07-20 18:46:15 +08:00
|
|
|
|
|
|
|
schemes = match.group(1).split()
|
|
|
|
if len(schemes) == 0:
|
2021-05-18 16:40:30 +08:00
|
|
|
raise adxe.CCPluginError("Couldn't find a scheme")
|
2020-07-20 18:46:15 +08:00
|
|
|
|
|
|
|
return schemes[0]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def target_path(project_dir):
|
|
|
|
return os.path.join(project_dir, '..', 'target')
|
|
|
|
|
|
|
|
def dist_ios(self):
|
|
|
|
if not self._platforms.is_ios_active():
|
|
|
|
return
|
|
|
|
project_dir = self._platforms.project_path()
|
|
|
|
|
|
|
|
scheme = self._find_ios_scheme(project_dir)
|
2021-05-18 16:40:30 +08:00
|
|
|
adxe.Logging.info("using scheme %s" % scheme)
|
2020-07-20 18:46:15 +08:00
|
|
|
|
|
|
|
archive_path = os.path.join(CCPluginDist.target_path(project_dir), scheme + '.xcarchive')
|
2021-05-18 16:40:30 +08:00
|
|
|
adxe.Logging.info("archiving")
|
2020-07-20 18:46:15 +08:00
|
|
|
self._run_cmd("cd '%s' && xcodebuild -scheme '%s' -archivePath '%s' archive" % (project_dir, scheme, archive_path))
|
|
|
|
|
2021-05-18 16:40:30 +08:00
|
|
|
adxe.Logging.info("exporting archive")
|
2020-07-20 18:46:15 +08:00
|
|
|
ipa_path = os.path.join(os.path.dirname(archive_path), scheme + '.ipa')
|
|
|
|
if os.path.exists(ipa_path):
|
|
|
|
os.remove(ipa_path)
|
|
|
|
self._run_cmd("cd '%s' && xcodebuild -exportArchive -exportFormat IPA -archivePath '%s' -exportPath '%s' -exportProvisioningProfile '%s'" % (project_dir, archive_path, ipa_path, self._provisioning))
|
2021-05-18 16:40:30 +08:00
|
|
|
adxe.Logging.info("\nThe ipa was created at:\n%s" % os.path.abspath(ipa_path))
|
|
|
|
adxe.Logging.info("\nNow you can use 'Application Loader' to submit the .ipa\n")
|
2020-07-20 18:46:15 +08:00
|
|
|
|
|
|
|
def run(self, argv, dependencies):
|
|
|
|
self.parse_args(argv)
|
|
|
|
self.dist_android()
|
|
|
|
self.dist_ios()
|