This repository has been archived by the owner on Mar 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_ipa.py
107 lines (85 loc) · 3.54 KB
/
build_ipa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2017 ciel <ciel@cieldeMBP>
#
# Distributed under terms of the MIT license.
"""
build ipa
"""
import os
import shutil
from call_cmd import call
import config
def build_ipa(target=None):
build_info = config.config_dic['build'][target]
scheme_name = build_info['scheme']
archive_path = config.config_dic['builds_path'] + scheme_name + '.xcarchive'
log_file = config.config_dic['log_path'] + config.config_dic['builg_log']
file = open(log_file, 'w+')
archive_cmd = "xcodebuild archive -workspace {} -scheme {} -archivePath {} ONLY_ACTIVE_ARCH=NO TARGETED_DEVICE_FAMILY=1 -allowProvisioningUpdates".format(config.config_dic['project_path'] + config.config_dic['worspace_name'], scheme_name, archive_path)
res = call(archive_cmd, file)
if res[0] != 0:
return (1, None, None)
sign_certificate = 'iPhone Distribution'
if build_info['export_mothod'] == 'development':
sign_certificate = 'iPhone Developer'
provisioning_profile_string = """
<key>{}</key>
<string>{}</string>
""".format(build_info['bundle_id'], build_info['provisioning_profile'])
extra_provisioning_profile = None
if 'extra_provisioning_profile' in build_info:
extra_provisioning_profile = build_info['extra_provisioning_profile']
if extra_provisioning_profile:
for provisinging_profile in extra_provisioning_profile:
provisioning_profile_string += """
<key>{}</key>
<string>{}</string>
""".format(provisinging_profile['bundle_id'], provisinging_profile['provisioning_profile'])
export_plist_template = """
<?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>compileBitcode</key>
<false/>
<key>method</key>
<string>{}</string>
<key>provisioningProfiles</key>
<dict>
{}
</dict>
<key>signingCertificate</key>
<string>{}</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>{}</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>
"""
export_plist = export_plist_template.format(build_info['export_mothod'], provisioning_profile_string, sign_certificate, build_info['team_id'])
export_plist_path = config.config_dic["builds_path"] + "export.plist"
with open(export_plist_path, 'w') as f:
f.write(export_plist)
export_cmd = "xcodebuild -exportArchive -archivePath {} -exportOptionsPlist {} -exportPath {} -allowProvisioningUpdates".format(archive_path, export_plist_path, config.config_dic['builds_path'])
res = call(export_cmd, file)
if res[0] != 0:
return (1, None, None)
version = call('''/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" {}'''.format(config.config_dic['project_path'] + build_info['info_plist']))[1]
build_version = call('''/usr/libexec/PlistBuddy -c "Print CFBundleVersion" {}'''.format(config.config_dic['project_path'] + build_info['info_plist']))[1]
ipa_name = '{}-{}-Build-{}.ipa'.format(scheme_name, str.strip(version), str.strip(build_version))
ipa_path = config.config_dic["builds_path"] + ipa_name
shutil.move(config.config_dic['builds_path'] + scheme_name + '.ipa', ipa_path)
if not os.path.exists(ipa_path):
return (1, None, None)
file.close
return (0, archive_path, ipa_path)
if __name__ == "__main__":
build_ipa()