-
Notifications
You must be signed in to change notification settings - Fork 18
/
configure.py
executable file
·236 lines (189 loc) · 10.5 KB
/
configure.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env python3
import argparse
import plistlib
import re
import os
from pbxproj import XcodeProject # Install from https://github.com/kronenthaler/mod-pbxproj
# Version numbers
app_version_number = "1.83"
app_version_build_number = app_version_number + ".0"
inform_source_version = "10.1.2"
full_version = app_version_number + "/6.41/" + inform_source_version
# Helper functions
#
# This function should really be in pbxproj, but they seem to have missed it out.
# (Still, easy enough to write it here.)
#
def set_project_flags(project, flag_name, flags, configuration_name=None):
"""
Sets the given flags to the flag_name section of the root project on the given configurations
:param flag_name: name of the flag to be added the values to
:param flags: A string or array of strings
:param configuration_name: Configuration name to add the flag to or None for every configuration
:return: void
"""
for configuration in project.objects.get_project_configurations(configuration_name):
configuration.set_flags(flag_name, flags)
#
# Simple .plist file editing
#
def set_in_plist_file(filename, key, val):
with open(filename, 'rb') as fp:
pl = plistlib.load(fp)
pl[key] = val
with open(filename, 'wb') as fp:
plistlib.dump(pl, fp)
#
# Simple .strings file editing
#
def replace_in_strings_file(filename, key, val):
new_lines = []
with open(filename, "r") as file:
for line in file:
# Looking for line with "key = "
find_pattern = '(^[ \\t]*' + key +' *= *)(.*)'
replace_pattern = r'\1"' + str(val) + r'";'
new = re.sub(find_pattern, replace_pattern, line)
new_lines.append(new)
with open(filename, "w") as file:
for line in new_lines:
file.write(line)
pass
#########################################################################################
# Argument parsing
#########################################################################################
parser = argparse.ArgumentParser(description='Configure the macOS Inform App for different build types.')
# Add arguments to the parser
build_type = parser.add_mutually_exclusive_group(required=True)
build_type.add_argument('--develop', action='store_true', help="for day to day development; using 'Apple Development' code signing")
build_type.add_argument('--standalone', action='store_true', help="for releasing a non-Mac App Store build; using 'Developer ID' code signing")
build_type.add_argument('--mas', action='store_true', help="for releasing a Mac App Store build; using 'Apple Distribution' code signing")
parser.add_argument('--team', dest='development_team_id')
args = vars(parser.parse_args())
develop = args['develop']
standalone = args['standalone']
mas = args['mas']
development_team = args['development_team_id']
# Default to my development team id
if development_team == None:
development_team = '97V36B3QYK'
#########################################################################################
# Code signing identity is based on the build type specified
#########################################################################################
if standalone:
code_sign_identity = 'Developer ID Application'
sandbox = False
sign_child_projects = True
elif develop:
code_sign_identity = 'Apple Development'
sandbox = False
sign_child_projects = True
elif mas:
code_sign_identity = 'Apple Distribution' # Was '3rd Party Mac Developer Application'
sandbox = True
sign_child_projects = False
else:
print("ERROR: Unknown configuration option")
exit(1)
#########################################################################################
# Submodule XCode Project editing
#########################################################################################
# These are the project files found in various submodules. We are going to edit each of them.
project_filenames = [
'zoom/ZoomCocoa.xcodeproj/project.pbxproj',
'zoom/depends/CocoaGlk/CocoaGlk.xcodeproj/project.pbxproj',
'zoom/depends/CocoaGlk/GlkSound/SFBAudioEngine/Libraries/dumb/dumb.xcodeproj/project.pbxproj',
'zoom/depends/CocoaGlk/GlkSound/SFBAudioEngine/Libraries/ogg/ogg.xcodeproj/project.pbxproj',
'zoom/depends/CocoaGlk/GlkSound/SFBAudioEngine/Libraries/vorbis/macosx/Vorbis.xcodeproj/project.pbxproj',
'zoom/depends/CocoaGlk/GlkSound/SFBAudioEngine/SFBAudioEngine.xcodeproj/project.pbxproj',
]
script_dir = os.path.abspath(os.path.dirname(__file__))
# Edit each project file in turn
for proj_name in project_filenames:
# load the project
project = XcodeProject.load(proj_name)
# Set code signing flags for the Project
set_project_flags(project, 'CODE_SIGN_STYLE', 'Manual')
set_project_flags(project, 'CODE_SIGN_IDENTITY', code_sign_identity)
set_project_flags(project, 'DEVELOPMENT_TEAM', development_team)
# project.remove_project_flags('CODE_SIGN_ENTITLEMENTS', None)
set_project_flags(project, 'CODE_SIGN_ENTITLEMENTS', '')
if not sign_child_projects:
set_project_flags(project, 'CODE_SIGN_STYLE', 'Manual', 'git')
project.remove_project_flags('CODE_SIGN_IDENTITY', '', 'git')
project.remove_project_flags('DEVELOPMENT_TEAM', None, 'git')
set_project_flags(project, 'CODE_SIGN_STYLE', 'Manual', 'glulxe')
project.remove_project_flags('CODE_SIGN_IDENTITY', '', 'glulxe')
project.remove_project_flags('DEVELOPMENT_TEAM', None, 'glulxe')
# Remove code signing flags from all Targets, so that they follow the Project settings
project.remove_flags('CODE_SIGN_IDENTITY', None)
project.remove_flags('DEVELOPMENT_TEAM', None)
project.remove_flags('CODE_SIGN_STYLE', None)
project.remove_flags('PROVISIONING_PROFILE_SPECIFIER', None)
# project.remove_flags('PRODUCT_BUNDLE_IDENTIFIER', None)
# Set sandboxing as needed
set_project_flags(project, 'ENABLE_APP_SANDBOX', 'YES' if sandbox else 'NO')
# set_project_flags(project, 'ENABLE_USER_SELECTED_FILES', 'readwrite' if sandbox else '""')
set_project_flags(project, 'CODE_SIGN_ENTITLEMENTS', script_dir + '/inform/Inform-inherit.entitlements', 'git')
set_project_flags(project, 'CODE_SIGN_ENTITLEMENTS', script_dir + '/inform/Inform-inherit.entitlements', 'glulxe')
# Make both Intel and Apple Silicon versions, always
project.remove_project_flags('ONLY_ACTIVE_ARCH', None)
project.remove_flags('ONLY_ACTIVE_ARCH', None) # Remove setting from all Targets, so they follow the Project settings
# Set 'Hardened runtime' for the Project
set_project_flags(project, 'ENABLE_HARDENED_RUNTIME', 'YES')
project.remove_flags('ENABLE_HARDENED_RUNTIME', None) # Remove setting from all Targets, so they follow the Project settings
# Skip install for a few of targets of the ZoomCocoa project
if proj_name.__contains__('ZoomCocoa.xcodeproj'):
project.set_flags('SKIP_INSTALL', 'YES', "babel")
project.set_flags('SKIP_INSTALL', 'YES', "Builder")
project.set_flags('SKIP_INSTALL', 'YES', "ZoomServer")
if proj_name.__contains__('CocoaGlk.xcodeproj'):
project.set_flags('SKIP_INSTALL', 'YES', "GlkView")
# Set plist and entitlements only for the real executables git-client and glulxe-client
project.set_flags('INFOPLIST_FILE', script_dir + "/inform/Distribution/git-client.plist", 'git')
project.set_flags('INFOPLIST_FILE', script_dir + "/inform/Distribution/glulxe-client.plist", 'glulxe')
project.set_flags('CREATE_INFOPLIST_IN_BINARY', 'YES', 'git')
project.set_flags('CREATE_INFOPLIST_IN_BINARY', 'YES', 'glulxe')
project.set_flags('CODE_SIGN_ENTITLEMENTS', script_dir + '/inform/Inform-inherit.entitlements', 'git')
project.set_flags('CODE_SIGN_ENTITLEMENTS', script_dir + '/inform/Inform-inherit.entitlements', 'glulxe')
# save the project
project.save()
#########################################################################################
# Main Inform XCode Project Editing
#########################################################################################
# load the main project
project = XcodeProject.load('inform/Inform.xcodeproj/project.pbxproj')
# Set code signing flags for the Project
set_project_flags(project, 'CODE_SIGN_IDENTITY', code_sign_identity)
set_project_flags(project, 'DEVELOPMENT_TEAM', development_team)
set_project_flags(project, 'CODE_SIGN_STYLE', 'Manual')
# Set sandboxing as needed
set_project_flags(project, 'ENABLE_APP_SANDBOX', 'YES' if sandbox else 'NO')
set_project_flags(project, 'ENABLE_USER_SELECTED_FILES', 'readwrite' if sandbox else '""')
set_project_flags(project, 'PRODUCT_BUNDLE_IDENTIFIER', 'com.inform7.inform-compiler')
# Remove code signing flags from all Targets, so that they follow the Project settings
project.remove_flags('CODE_SIGN_IDENTITY', None)
project.remove_flags('DEVELOPMENT_TEAM', None)
project.remove_flags('CODE_SIGN_STYLE', None)
project.remove_flags('PROVISIONING_PROFILE_SPECIFIER', None)
# Set version number
set_project_flags(project, 'CURRENT_PROJECT_VERSION', app_version_build_number)
set_project_flags(project, 'MARKETING_VERSION', app_version_build_number)
# Make both Intel and Apple Silicon versions, always
project.remove_project_flags('ONLY_ACTIVE_ARCH', None)
project.remove_flags('ONLY_ACTIVE_ARCH', None) # Remove setting from all Targets, so they follow the Project settings
# Set 'Hardened runtime' for the Project
set_project_flags(project, 'ENABLE_HARDENED_RUNTIME', 'YES')
project.remove_flags('ENABLE_HARDENED_RUNTIME', None) # Remove setting from all Targets, so they follow the Project settings
# save the project
project.save()
#########################################################################################
# plist editing
#########################################################################################
set_in_plist_file("inform/Inform.entitlements", "com.apple.security.app-sandbox", sandbox)
set_in_plist_file("inform/Inform-inherit.entitlements", "com.apple.security.app-sandbox", sandbox)
# Set app version number
set_in_plist_file("inform/Inform-Info.plist", "CFBundleVersion", app_version_build_number)
set_in_plist_file("inform/Inform-Info.plist", "CFBundleShortVersionString", app_version_number)
replace_in_strings_file("inform/Resources/en.lproj/InfoPlist.strings", "CFBundleGetInfoString", "Inform version " + full_version)
replace_in_strings_file("inform/Resources/en.lproj/Localizable.strings", '"Build Version"', inform_source_version)