-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_xcode.py
More file actions
220 lines (197 loc) · 6.4 KB
/
Copy pathgenerate_xcode.py
File metadata and controls
220 lines (197 loc) · 6.4 KB
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
#!/usr/bin/env python3
"""Generate a valid Xcode project for missingpieces (repo: PiecesTask)."""
import os, hashlib
APP_TARGET = "missingpieces"
BUNDLE_ID = "app.missingpieces"
def xid(s):
return hashlib.sha256(s.encode()).hexdigest()[:24].upper()
# Collect sources with their relative paths
sources = []
for root, _, files in os.walk("PiecesTask"):
for f in sorted(files):
if f.endswith(".swift"):
src = os.path.join(root, f)
relpath = src # e.g. PiecesTask/PiecesTaskApp.swift
sources.append(relpath)
file_ids = {s: xid(f"f:{s}") for s in sources}
bf_ids = {s: xid(f"bf:{s}") for s in sources}
PID = xid("project")
MGID = xid("mainGroup")
PGID = xid("productsGroup")
BCLID = xid("buildConfigList")
BCDID = xid("debugConfig")
BCRID = xid("releaseConfig")
SBPID = xid("sourcesPhase")
RBPID = xid("resourcesPhase")
ASSETS = "PiecesTaskAssets.xcassets"
ASSET_FID = xid(f"f:{ASSETS}")
ASSET_BFID = xid(f"bf:{ASSETS}")
PRID = xid("productRef")
NTID = xid("nativeTarget")
PXPID = xid("PBXProject")
lines = []
def L(txt): lines.append(txt)
L("// !$*UTF8*$!")
L("{")
L("\tarchiveVersion = 1;")
L("\tclasses = {};")
L("\tobjectVersion = 56;")
L("\tobjects = {")
for src in sources:
fid = file_ids[src]
name = os.path.basename(src)
path = src
L(f"\t\t{fid} /* {name} */ = {{")
L(f"\t\t\tisa = PBXFileReference;")
L(f"\t\t\tlastKnownFileType = sourcecode.swift;")
L(f"\t\t\tpath = \"{path}\";")
L(f"\t\t\tsourceTree = SOURCE_ROOT;")
L(f"\t\t}};")
# Asset catalog
L(f"\t\t{ASSET_FID} /* {ASSETS} */ = {{")
L(f"\t\t\tisa = PBXFileReference;")
L(f"\t\t\tlastKnownFileType = folder.assetcatalog;")
L(f"\t\t\tpath = \"{ASSETS}\";")
L(f"\t\t\tsourceTree = SOURCE_ROOT;")
L(f"\t\t}};")
# Product ref
L(f"\t\t{PRID} /* {APP_TARGET}.app */ = {{")
L(f"\t\t\tisa = PBXFileReference;")
L(f"\t\t\texplicitFileType = wrapper.application;")
L(f"\t\t\tincludeInIndex = 0;")
L(f"\t\t\tpath = \"{APP_TARGET}.app\";")
L(f"\t\t\tsourceTree = BUILT_PRODUCTS_DIR;")
L(f"\t\t}};")
# Main group
L(f"\t\t{MGID} = {{")
L(f"\t\t\tisa = PBXGroup;")
L(f"\t\t\tchildren = (")
# Products group
L(f"\t\t\t\t{PGID} /* Products */,")
L(f"\t\t\t\t{ASSET_FID} /* {ASSETS} */,")
# Each source file
for src in sources:
fname = os.path.basename(src)
L(f"\t\t\t\t{file_ids[src]} /* {fname} */,")
L(f"\t\t\t);")
L(f"\t\t\tsourceTree = SOURCE_ROOT;")
L(f"\t\t}};")
# Products group
L(f"\t\t{PGID} = {{")
L(f"\t\t\tisa = PBXGroup;")
L(f"\t\t\tchildren = (")
L(f"\t\t\t\t{PRID} /* {APP_TARGET}.app */,")
L(f"\t\t\t);")
L(f"\t\t\tname = Products;")
L(f"\t\t\tsourceTree = SOURCE_ROOT;")
L(f"\t\t}};")
# Build files
for src in sources:
L(f"\t\t{bf_ids[src]} /* {os.path.basename(src)} in Sources */ = {{")
L(f"\t\t\tisa = PBXBuildFile;")
L(f"\t\t\tfileRef = {file_ids[src]};")
L(f"\t\t}};")
L(f"\t\t{ASSET_BFID} /* {ASSETS} in Resources */ = {{")
L(f"\t\t\tisa = PBXBuildFile;")
L(f"\t\t\tfileRef = {ASSET_FID};")
L(f"\t\t}};")
# Native target
L(f"\t\t{NTID} = {{")
L(f"\t\t\tisa = PBXNativeTarget;")
L(f"\t\t\tbuildConfigurationList = {BCLID};")
L(f"\t\t\tbuildPhases = (")
L(f"\t\t\t\t{SBPID},")
L(f"\t\t\t\t{RBPID},")
L(f"\t\t\t);")
L(f"\t\t\tbuildRules = (")
L(f"\t\t\t);")
L(f"\t\t\tdependencies = (")
L(f"\t\t\t);")
L(f"\t\t\tname = \"{APP_TARGET}\";")
L(f"\t\t\tproductName = \"{APP_TARGET}\";")
L(f"\t\t\tproductReference = {PRID};")
L(f"\t\t\tproductType = \"com.apple.product-type.application\";")
L(f"\t\t}};")
# Sources build phase
L(f"\t\t{SBPID} = {{")
L(f"\t\t\tisa = PBXSourcesBuildPhase;")
L(f"\t\t\trunOnlyForDeploymentPostprocessing = 0;")
L(f"\t\t\tfiles = (")
for src in sources:
L(f"\t\t\t\t{bf_ids[src]},")
L(f"\t\t\t);")
L(f"\t\t}};")
# Resources build phase
L(f"\t\t{RBPID} = {{")
L(f"\t\t\tisa = PBXResourcesBuildPhase;")
L(f"\t\t\trunOnlyForDeploymentPostprocessing = 0;")
L(f"\t\t\tfiles = (")
L(f"\t\t\t\t{ASSET_BFID},")
L(f"\t\t\t);")
L(f"\t\t}};")
# Build config list
L(f"\t\t{BCLID} = {{")
L(f"\t\t\tisa = XCConfigurationList;")
L(f"\t\t\tbuildConfigurations = (")
L(f"\t\t\t\t{BCDID} /* Debug */,")
L(f"\t\t\t\t{BCRID} /* Release */,")
L(f"\t\t\t);")
L(f"\t\t\tdefaultConfigurationIsVisible = 0;")
L(f"\t\t\tdefaultConfigurationName = Release;")
L(f"\t\t}};")
# Build configs
for cid, cname in [(BCDID, "Debug"), (BCRID, "Release")]:
L(f"\t\t{cid} /* {cname} */ = {{")
L(f"\t\t\tisa = XCBuildConfiguration;")
L(f"\t\t\tbuildSettings = {{")
L(f"\t\t\t\tASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;")
if cname == "Release":
L(f"\t\t\t\tCODE_SIGN_ENTITLEMENTS = \"PiecesTask/missingpieces.entitlements\";")
L(f"\t\t\t\tCODE_SIGN_IDENTITY = \"Developer ID Application\";")
L(f"\t\t\t\tCODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;")
L(f"\t\t\t\tCODE_SIGN_STYLE = Manual;")
L(f"\t\t\t\tCURRENT_PROJECT_VERSION = 3;")
L(f"\t\t\t\tDEVELOPMENT_TEAM = P5RB3W3D58;")
L(f"\t\t\t\tENABLE_HARDENED_RUNTIME = YES;")
else:
L(f"\t\t\t\tCODE_SIGN_STYLE = Automatic;")
L(f"\t\t\t\tCOMBINE_HIDPI_IMAGES = YES;")
L(f"\t\t\t\tENABLE_PREVIEWS = YES;")
L(f"\t\t\t\tINFOPLIST_FILE = \"PiecesTask/Info.plist\";")
L(f"\t\t\t\tLD_RUNPATH_SEARCH_PATHS = (")
L(f"\t\t\t\t\t\"$(inherited)\",")
L(f"\t\t\t\t\t\"@executable_path/../Frameworks\",")
L(f"\t\t\t\t);")
if cname == "Release":
L(f"\t\t\t\tMARKETING_VERSION = 1.0.0;")
L(f"\t\t\t\tMACOSX_DEPLOYMENT_TARGET = 14.0;")
L(f"\t\t\t\tPRODUCT_BUNDLE_IDENTIFIER = {BUNDLE_ID};")
L(f"\t\t\t\tPRODUCT_NAME = \"$(TARGET_NAME)\";")
L(f"\t\t\t\tSWIFT_VERSION = 6.0;")
L(f"\t\t\t}};")
L(f"\t\t\tname = {cname};")
L(f"\t\t}};")
# Project
L(f"\t\t{PXPID} = {{")
L(f"\t\t\tisa = PBXProject;")
L(f"\t\t\tattributes = {{ BuildIndependentTargetsInParallel = 1; }};")
L(f"\t\t\tbuildConfigurationList = {BCLID};")
L(f"\t\t\tcompatibilityVersion = \"Xcode 15.0\";")
L(f"\t\t\tdevelopmentRegion = en;")
L(f"\t\t\thasScannedForEncodings = 0;")
L(f"\t\t\tknownRegions = (en, Base);")
L(f"\t\t\tmainGroup = {MGID};")
L(f"\t\t\tproductRefGroup = {PGID};")
L(f"\t\t\tprojectDirPath = \"\";")
L(f"\t\t\tprojectRoot = \"\";")
L(f"\t\t\ttargets = ({NTID},);")
L(f"\t\t}};")
L("\t};")
L(f"\trootObject = {PXPID} /* Project object */;")
L("}")
os.makedirs("PiecesTask.xcodeproj", exist_ok=True)
with open("PiecesTask.xcodeproj/project.pbxproj", "w") as f:
f.write("\n".join(lines))
print(f"Generated Xcode project with {len(sources)} source files")
for s in sources:
print(f" - {s}")