peachsim 0.1.750 → 0.1.752
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/commands/inspect/settling.ts +7 -2
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +571 -300
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +5 -3
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +1 -1
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +5 -3
- package/dist-lib/sdk.mjs +5 -3
- package/dist-lib/skills.cjs +752 -479
- package/dist-lib/swift-compile.cjs +1 -1
- package/dist-lib/swift-compile.mjs +1 -1
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +465 -194
- package/dist-lib/vite.cjs +1 -1
- package/package.json +1 -1
- package/src/swift-host.ts +51 -18
- package/src/vite-plugin.ts +3 -1
- package/src/xcode-project.ts +590 -245
package/src/xcode-project.ts
CHANGED
|
@@ -119,11 +119,8 @@ export interface XcodeRemoteProduct {
|
|
|
119
119
|
repositoryURL: string
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
/**
|
|
123
|
-
export interface
|
|
124
|
-
/** the directory holding the .xcodeproj: every relative path starts here. */
|
|
125
|
-
projectDir: string
|
|
126
|
-
pbxproj: string
|
|
122
|
+
/** a target whose swift compiles as one module: the app, or a framework it builds. */
|
|
123
|
+
export interface XcodeModuleTarget {
|
|
127
124
|
name: string
|
|
128
125
|
/** the module name the target's sources compile as. */
|
|
129
126
|
moduleName: string
|
|
@@ -131,29 +128,61 @@ export interface XcodeAppTarget {
|
|
|
131
128
|
sources: string[]
|
|
132
129
|
/** absolute paths of every resource file the target copies, bundles expanded. */
|
|
133
130
|
resources: string[]
|
|
131
|
+
languageMode: number
|
|
132
|
+
mainActorIsolation: boolean
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** an application target, resolved to files on disk with everything it builds. */
|
|
136
|
+
export interface XcodeAppTarget extends XcodeModuleTarget {
|
|
137
|
+
/**
|
|
138
|
+
* the deepest directory holding the workspace, every project and every
|
|
139
|
+
* local package the app builds from: every compile path is relative to it.
|
|
140
|
+
*/
|
|
141
|
+
rootDir: string
|
|
142
|
+
/** every project.pbxproj the app's build reads. */
|
|
143
|
+
pbxprojs: string[]
|
|
134
144
|
/** the target's processed launch plist, including generated build settings. */
|
|
135
145
|
infoPlist: string
|
|
136
146
|
infoPlistFile: string | null
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/**
|
|
147
|
+
/** the target's compiled sources in every language, swift or not. */
|
|
148
|
+
allSources: string[]
|
|
149
|
+
/**
|
|
150
|
+
* framework and library targets of any project in the workspace that the
|
|
151
|
+
* app depends on or links, dependencies first. xcode builds them into one
|
|
152
|
+
* products directory, so every one is importable from every other.
|
|
153
|
+
*/
|
|
154
|
+
frameworks: XcodeModuleTarget[]
|
|
155
|
+
/** directories of the local swift packages whose products the build links. */
|
|
140
156
|
localPackages: string[]
|
|
141
157
|
remoteProducts: XcodeRemoteProduct[]
|
|
142
158
|
/** the Package.resolved pinning the remote packages' revisions, when resolved. */
|
|
143
159
|
packageResolved: string | null
|
|
144
160
|
/** linked product names no local or remote package reference supplies. */
|
|
145
161
|
unresolvedProducts: string[]
|
|
146
|
-
/** every application target in the
|
|
162
|
+
/** every application target in the workspace, for a chooser. */
|
|
147
163
|
appTargets: string[]
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
const APPLICATION = 'com.apple.product-type.application'
|
|
167
|
+
// product types a dependent target imports as a module from the products directory.
|
|
168
|
+
const MODULE_PRODUCTS = new Set([
|
|
169
|
+
'com.apple.product-type.framework',
|
|
170
|
+
'com.apple.product-type.framework.static',
|
|
171
|
+
'com.apple.product-type.library.static',
|
|
172
|
+
'com.apple.product-type.library.dynamic',
|
|
173
|
+
])
|
|
151
174
|
// files xcode never builds into a target even inside a synchronized folder.
|
|
152
175
|
const NEVER_MEMBER =
|
|
153
176
|
/(?:^|\/)(?:Info\.plist|[^/]+\.entitlements|[^/]+\.xcconfig|\.DS_Store)$/
|
|
154
177
|
// directories xcode copies as a whole resource.
|
|
155
178
|
const BUNDLE_DIR =
|
|
156
179
|
/\.(xcassets|bundle|lproj|xcdatamodeld|scnassets|spriteatlas|rcproject|storyboardc|icon)$/
|
|
180
|
+
// the sdk and architecture peach builds for, as build setting conditions see them.
|
|
181
|
+
const CONDITIONS: Record<string, string> = {
|
|
182
|
+
sdk: 'iphonesimulator',
|
|
183
|
+
arch: 'arm64',
|
|
184
|
+
variant: 'normal',
|
|
185
|
+
}
|
|
157
186
|
|
|
158
187
|
function walkFiles(dir: string): string[] {
|
|
159
188
|
if (!fs.existsSync(dir)) return []
|
|
@@ -169,6 +198,9 @@ function walkFiles(dir: string): string[] {
|
|
|
169
198
|
return out
|
|
170
199
|
}
|
|
171
200
|
|
|
201
|
+
const isDirectory = (dir: string) => fs.existsSync(dir) && fs.statSync(dir).isDirectory()
|
|
202
|
+
|
|
203
|
+
// an xcconfig's assignments, conditions kept in the key, includes inlined in order.
|
|
172
204
|
function readXcconfig(file: string, seen = new Set<string>()): Record<string, string> {
|
|
173
205
|
if (seen.has(file) || !fs.existsSync(file)) return {}
|
|
174
206
|
seen.add(file)
|
|
@@ -183,77 +215,155 @@ function readXcconfig(file: string, seen = new Set<string>()): Record<string, st
|
|
|
183
215
|
)
|
|
184
216
|
continue
|
|
185
217
|
}
|
|
186
|
-
const setting = /^([A-
|
|
187
|
-
if (setting)
|
|
218
|
+
const setting = /^([A-Za-z_][A-Za-z0-9_]*(?:\[[^\]]*\])*)\s*=\s*(.*)$/.exec(line)
|
|
219
|
+
if (setting)
|
|
220
|
+
settings[setting[1]!.replace(/\s+/g, '')] = setting[2]!.replace(/;$/, '').trim()
|
|
188
221
|
}
|
|
189
222
|
return settings
|
|
190
223
|
}
|
|
191
224
|
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
225
|
+
// one level's settings as xcode applies them: a key whose conditions all
|
|
226
|
+
// match the build overrides the unconditional key; others never apply.
|
|
227
|
+
function applyConditions(
|
|
228
|
+
raw: Record<string, string>,
|
|
229
|
+
configuration: string,
|
|
230
|
+
): Record<string, string> {
|
|
231
|
+
const plain: Record<string, string> = {}
|
|
232
|
+
const conditional: Record<string, string> = {}
|
|
233
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
234
|
+
const bracket = key.indexOf('[')
|
|
235
|
+
if (bracket === -1) {
|
|
236
|
+
plain[key] = value
|
|
237
|
+
continue
|
|
238
|
+
}
|
|
239
|
+
const matches = [...key.slice(bracket).matchAll(/\[([^=\]]+)=([^\]]*)\]/g)].every(
|
|
240
|
+
([, name, pattern]) => {
|
|
241
|
+
const actual = name === 'config' ? configuration : CONDITIONS[name!]
|
|
242
|
+
return (
|
|
243
|
+
actual !== undefined &&
|
|
244
|
+
new RegExp(
|
|
245
|
+
`^${pattern!
|
|
246
|
+
.replace(/[.+^${}()|\\]/g, '\\$&')
|
|
247
|
+
.replaceAll('*', '.*')
|
|
248
|
+
.replaceAll('?', '.')}$`,
|
|
249
|
+
).test(actual)
|
|
250
|
+
)
|
|
251
|
+
},
|
|
252
|
+
)
|
|
253
|
+
if (matches) conditional[key.slice(0, bracket)] = value
|
|
254
|
+
}
|
|
255
|
+
return { ...plain, ...conditional }
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// xcode's build setting operators, as measured against xcodebuild.
|
|
259
|
+
function applyOperator(value: string, operator: string): string {
|
|
260
|
+
if (operator.startsWith('default=')) return value === '' ? operator.slice(8) : value
|
|
261
|
+
switch (operator) {
|
|
262
|
+
case 'lower':
|
|
263
|
+
return value.toLowerCase()
|
|
264
|
+
case 'upper':
|
|
265
|
+
return value.toUpperCase()
|
|
266
|
+
case 'rfc1034identifier':
|
|
267
|
+
return value.replace(/[^A-Za-z0-9-]/g, '-').replace(/^[0-9]/, '-')
|
|
268
|
+
case 'identifier':
|
|
269
|
+
case 'c99extidentifier':
|
|
270
|
+
return value.replace(/[^A-Za-z0-9_]/g, '_').replace(/^[0-9]/, '_')
|
|
271
|
+
}
|
|
272
|
+
throw new Error(`unsupported build setting operator :${operator}`)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function decodeXml(text: string): string {
|
|
276
|
+
return text
|
|
277
|
+
.replaceAll('"', '"')
|
|
278
|
+
.replaceAll(''', "'")
|
|
279
|
+
.replaceAll('<', '<')
|
|
280
|
+
.replaceAll('>', '>')
|
|
281
|
+
.replaceAll('&', '&')
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// what a workspace lists, resolved through its nested groups: projects and folders.
|
|
285
|
+
function workspaceReferences(workspace: string): string[] {
|
|
286
|
+
const data = path.join(workspace, 'contents.xcworkspacedata')
|
|
287
|
+
if (!fs.existsSync(data))
|
|
288
|
+
throw new Error(`${workspace} has no contents.xcworkspacedata`)
|
|
289
|
+
const container = path.dirname(workspace)
|
|
290
|
+
const locate = (location: string, base: string): string => {
|
|
291
|
+
const colon = location.indexOf(':')
|
|
292
|
+
const kind = location.slice(0, colon)
|
|
293
|
+
const rest = location.slice(colon + 1)
|
|
294
|
+
if (kind === 'group') return path.resolve(base, rest)
|
|
295
|
+
if (kind === 'container' || kind === 'self') return path.resolve(container, rest)
|
|
296
|
+
if (kind === 'absolute') return path.resolve(rest)
|
|
297
|
+
throw new Error(`${path.basename(workspace)} has an unsupported location ${location}`)
|
|
298
|
+
}
|
|
299
|
+
const groups = [container]
|
|
300
|
+
const references: string[] = []
|
|
301
|
+
for (const [, closing, tag, attributes, selfClosing] of fs
|
|
302
|
+
.readFileSync(data, 'utf8')
|
|
303
|
+
.matchAll(/<(\/?)(Group|FileRef)\b([^>]*?)(\/?)>/g)) {
|
|
304
|
+
if (closing) {
|
|
305
|
+
if (tag === 'Group') groups.pop()
|
|
306
|
+
continue
|
|
307
|
+
}
|
|
308
|
+
const base = groups.at(-1)!
|
|
309
|
+
const location = /\blocation\s*=\s*"([^"]*)"/.exec(attributes!)?.[1]
|
|
310
|
+
const resolved = location ? locate(decodeXml(location), base) : base
|
|
311
|
+
if (tag === 'FileRef') references.push(resolved)
|
|
312
|
+
else if (!selfClosing) groups.push(resolved)
|
|
313
|
+
}
|
|
314
|
+
return references
|
|
196
315
|
}
|
|
197
316
|
|
|
198
|
-
/**
|
|
317
|
+
/**
|
|
318
|
+
* the workspace or project a path names: the bundle itself, or in a
|
|
319
|
+
* directory its one workspace, else its one project, as xcode opens it.
|
|
320
|
+
*/
|
|
199
321
|
export function findXcodeProject(input: string): string | null {
|
|
200
322
|
const resolved = path.resolve(input)
|
|
201
|
-
if (resolved.endsWith('.xcodeproj')) return resolved
|
|
202
323
|
if (resolved.endsWith('.xcworkspace')) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
?
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (projects.length !== 1) {
|
|
324
|
+
// a project's own workspace opens that project
|
|
325
|
+
return path.dirname(resolved).endsWith('.xcodeproj')
|
|
326
|
+
? path.dirname(resolved)
|
|
327
|
+
: resolved
|
|
328
|
+
}
|
|
329
|
+
if (resolved.endsWith('.xcodeproj')) return resolved
|
|
330
|
+
if (!isDirectory(resolved)) return null
|
|
331
|
+
for (const extension of ['.xcworkspace', '.xcodeproj']) {
|
|
332
|
+
const found = fs.readdirSync(resolved).filter((name) => name.endsWith(extension))
|
|
333
|
+
if (found.length > 1) {
|
|
214
334
|
throw new Error(
|
|
215
|
-
`${
|
|
335
|
+
`${resolved} holds ${found.length} ${extension} bundles (${found.join(', ')}); pass one`,
|
|
216
336
|
)
|
|
217
337
|
}
|
|
218
|
-
return
|
|
338
|
+
if (found.length === 1) return path.join(resolved, found[0]!)
|
|
219
339
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
340
|
+
return null
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
interface LoadedProject {
|
|
344
|
+
xcodeproj: string
|
|
345
|
+
pbxproj: string
|
|
346
|
+
objects: PlistDict
|
|
347
|
+
project: PlistDict
|
|
348
|
+
/** the directory holding the .xcodeproj: every relative path starts here. */
|
|
349
|
+
projectDir: string
|
|
350
|
+
object: (id: string | undefined) => PlistDict | undefined
|
|
351
|
+
resolvePath: (id: string) => string | null
|
|
228
352
|
}
|
|
229
353
|
|
|
230
|
-
const
|
|
354
|
+
const loaded = new Map<string, { mtimeMs: number; project: LoadedProject }>()
|
|
231
355
|
|
|
232
|
-
function
|
|
356
|
+
function loadProject(xcodeproj: string): LoadedProject {
|
|
357
|
+
const pbxproj = path.join(xcodeproj, 'project.pbxproj')
|
|
358
|
+
if (!fs.existsSync(pbxproj)) throw new Error(`${xcodeproj} has no project.pbxproj`)
|
|
233
359
|
const mtimeMs = fs.statSync(pbxproj).mtimeMs
|
|
234
|
-
const cached =
|
|
235
|
-
if (cached?.mtimeMs === mtimeMs) return cached.
|
|
360
|
+
const cached = loaded.get(pbxproj)
|
|
361
|
+
if (cached?.mtimeMs === mtimeMs) return cached.project
|
|
236
362
|
const root = parseOpenStepPlist(fs.readFileSync(pbxproj, 'utf8'))
|
|
237
363
|
if (!isDict(root) || !isDict(root.objects)) {
|
|
238
364
|
throw new Error(`${pbxproj} has no objects table`)
|
|
239
365
|
}
|
|
240
|
-
|
|
241
|
-
return root
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* the application target `targetName` names (or the project's only one),
|
|
246
|
-
* with its member files listed fresh from disk: a file added to a
|
|
247
|
-
* synchronized folder joins the target without any project change.
|
|
248
|
-
*/
|
|
249
|
-
export function readXcodeAppTarget(
|
|
250
|
-
xcodeproj: string,
|
|
251
|
-
targetName?: string,
|
|
252
|
-
): XcodeAppTarget {
|
|
253
|
-
const pbxproj = path.join(xcodeproj, 'project.pbxproj')
|
|
254
|
-
if (!fs.existsSync(pbxproj)) throw new Error(`${xcodeproj} has no project.pbxproj`)
|
|
255
|
-
const root = readProject(pbxproj)
|
|
256
|
-
const objects = root.objects as PlistDict
|
|
366
|
+
const objects = root.objects
|
|
257
367
|
const object = (id: string | undefined): PlistDict | undefined => {
|
|
258
368
|
const found = id === undefined ? undefined : objects[id]
|
|
259
369
|
return isDict(found) ? found : undefined
|
|
@@ -266,7 +376,6 @@ export function readXcodeAppTarget(
|
|
|
266
376
|
const projectDir = fs.realpathSync(
|
|
267
377
|
path.resolve(path.dirname(xcodeproj), str(project.projectDirPath) ?? ''),
|
|
268
378
|
)
|
|
269
|
-
|
|
270
379
|
// every group child's parent, so a "<group>" path resolves up the tree.
|
|
271
380
|
const parent = new Map<string, string>()
|
|
272
381
|
for (const [id, entry] of Object.entries(objects)) {
|
|
@@ -294,163 +403,145 @@ export function readXcodeAppTarget(
|
|
|
294
403
|
resolvedPaths.set(id, result)
|
|
295
404
|
return result
|
|
296
405
|
}
|
|
406
|
+
const result = { xcodeproj, pbxproj, objects, project, projectDir, object, resolvePath }
|
|
407
|
+
loaded.set(pbxproj, { mtimeMs, project: result })
|
|
408
|
+
return result
|
|
409
|
+
}
|
|
297
410
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
)
|
|
304
|
-
const appTargets = targets.filter((entry) => entry.target.productType === APPLICATION)
|
|
305
|
-
const appTargetNames = appTargets.map((entry) => str(entry.target.name) ?? entry.id)
|
|
306
|
-
const chosen = targetName
|
|
307
|
-
? appTargets.find((entry) => entry.target.name === targetName)
|
|
308
|
-
: appTargets.length === 1
|
|
309
|
-
? appTargets[0]
|
|
310
|
-
: undefined
|
|
311
|
-
if (!chosen) {
|
|
312
|
-
throw new Error(
|
|
313
|
-
targetName
|
|
314
|
-
? `${path.basename(xcodeproj)} has no application target ${targetName}; it has ${appTargetNames.join(', ') || 'none'}`
|
|
315
|
-
: `${path.basename(xcodeproj)} has ${appTargetNames.length} application targets (${appTargetNames.join(', ') || 'none'}); pass --target`,
|
|
316
|
-
)
|
|
317
|
-
}
|
|
318
|
-
const { id: targetId, target } = chosen
|
|
411
|
+
interface TargetRef {
|
|
412
|
+
project: LoadedProject
|
|
413
|
+
id: string
|
|
414
|
+
target: PlistDict
|
|
415
|
+
}
|
|
319
416
|
|
|
320
|
-
|
|
321
|
-
|
|
417
|
+
// the build settings of one target, evaluated as xcode does: project then
|
|
418
|
+
// target level, each an xcconfig under its own settings; `$(inherited)` reads
|
|
419
|
+
// the level below and an undefined setting is empty.
|
|
420
|
+
function targetSettings(
|
|
421
|
+
ref: TargetRef,
|
|
422
|
+
builtins: Record<string, string>,
|
|
423
|
+
): { get: (key: string) => string; keys: Set<string> } {
|
|
424
|
+
const { project, target } = ref
|
|
425
|
+
const level = (listId: string | undefined): Record<string, string>[] => {
|
|
426
|
+
const configs = list(project.object(listId)?.buildConfigurations).map(project.object)
|
|
322
427
|
const config =
|
|
323
428
|
configs.find((entry) => entry?.name === 'Debug') ?? configs.find(Boolean)
|
|
324
|
-
if (!config) return
|
|
429
|
+
if (!config) return []
|
|
430
|
+
const name = str(config.name) ?? 'Debug'
|
|
325
431
|
const base = str(config.baseConfigurationReference)
|
|
326
|
-
const fromFile = base ? readXcconfig(resolvePath(base) ?? '') : {}
|
|
327
432
|
const own = isDict(config.buildSettings) ? config.buildSettings : {}
|
|
328
|
-
return
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
Object.
|
|
332
|
-
|
|
433
|
+
return [
|
|
434
|
+
applyConditions(base ? readXcconfig(project.resolvePath(base) ?? '') : {}, name),
|
|
435
|
+
applyConditions(
|
|
436
|
+
Object.fromEntries(
|
|
437
|
+
Object.entries(own).flatMap(([key, value]) =>
|
|
438
|
+
typeof value === 'string'
|
|
439
|
+
? [[key, value]]
|
|
440
|
+
: Array.isArray(value)
|
|
441
|
+
? [[key, list(value).join(' ')]]
|
|
442
|
+
: [],
|
|
443
|
+
),
|
|
333
444
|
),
|
|
445
|
+
name,
|
|
334
446
|
),
|
|
335
|
-
|
|
447
|
+
]
|
|
336
448
|
}
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
...
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
settings.DEVELOPMENT_LANGUAGE ?? str(project.developmentRegion) ?? 'en',
|
|
356
|
-
TARGET_NAME: name,
|
|
357
|
-
PRODUCT_NAME: productName,
|
|
358
|
-
PRODUCT_MODULE_NAME: moduleName,
|
|
359
|
-
SRCROOT: projectDir,
|
|
360
|
-
SOURCE_ROOT: projectDir,
|
|
361
|
-
}
|
|
362
|
-
const expand = (value: string): string => {
|
|
363
|
-
const seen = new Set<string>()
|
|
364
|
-
while (/\$[({][A-Za-z_][A-Za-z0-9_]*[)}]/.test(value)) {
|
|
365
|
-
if (seen.has(value)) throw new Error(`${name} has cyclic Info.plist build settings`)
|
|
366
|
-
seen.add(value)
|
|
367
|
-
value = value.replace(
|
|
368
|
-
/\$[({]([A-Za-z_][A-Za-z0-9_]*)[)}]/g,
|
|
369
|
-
(match, key: string) => {
|
|
370
|
-
const replacement = Object.entries(variables).find(
|
|
371
|
-
([name]) => name === key,
|
|
372
|
-
)?.[1]
|
|
373
|
-
if (replacement === undefined)
|
|
374
|
-
throw new Error(`${name} Info.plist has unresolved setting ${match}`)
|
|
375
|
-
return replacement
|
|
376
|
-
},
|
|
377
|
-
)
|
|
378
|
-
}
|
|
449
|
+
const levels = [
|
|
450
|
+
builtins,
|
|
451
|
+
...level(str(project.project.buildConfigurationList)),
|
|
452
|
+
...level(str(target.buildConfigurationList)),
|
|
453
|
+
]
|
|
454
|
+
const resolving = new Set<string>()
|
|
455
|
+
const valueAt = (key: string, top: number): string => {
|
|
456
|
+
let at = top
|
|
457
|
+
while (at >= 0 && levels[at]![key] === undefined) at--
|
|
458
|
+
if (at < 0) return derived(key)
|
|
459
|
+
const marker = `${key}@${at}`
|
|
460
|
+
if (resolving.has(marker))
|
|
461
|
+
throw new Error(`${str(target.name)} has a cyclic build setting ${key}`)
|
|
462
|
+
resolving.add(marker)
|
|
463
|
+
const value = expand(levels[at]![key]!, (name) =>
|
|
464
|
+
name === 'inherited' ? valueAt(key, at - 1) : valueAt(name, levels.length - 1),
|
|
465
|
+
)
|
|
466
|
+
resolving.delete(marker)
|
|
379
467
|
return value
|
|
380
468
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
469
|
+
// settings xcode derives from others when the project leaves them unset.
|
|
470
|
+
const derived = (key: string): string => {
|
|
471
|
+
const get = (name: string) => valueAt(name, levels.length - 1)
|
|
472
|
+
switch (key) {
|
|
473
|
+
case 'PRODUCT_NAME':
|
|
474
|
+
return get('TARGET_NAME')
|
|
475
|
+
case 'PRODUCT_MODULE_NAME':
|
|
476
|
+
return applyOperator(get('PRODUCT_NAME'), 'c99extidentifier')
|
|
477
|
+
case 'EXECUTABLE_NAME':
|
|
478
|
+
return get('PRODUCT_NAME')
|
|
479
|
+
case 'AppIdentifierPrefix':
|
|
480
|
+
case 'TeamIdentifierPrefix': {
|
|
481
|
+
// only a signed build has a team prefix
|
|
482
|
+
const team = get('DEVELOPMENT_TEAM')
|
|
483
|
+
return get('CODE_SIGNING_ALLOWED') !== 'NO' && team ? `${team}.` : ''
|
|
484
|
+
}
|
|
392
485
|
}
|
|
393
|
-
return
|
|
486
|
+
return ''
|
|
394
487
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
:
|
|
398
|
-
const sourceInfo = infoPlistFile
|
|
399
|
-
? plist.parse(fs.readFileSync(infoPlistFile, 'utf8'))
|
|
400
|
-
: {}
|
|
401
|
-
if (
|
|
402
|
-
!sourceInfo ||
|
|
403
|
-
typeof sourceInfo !== 'object' ||
|
|
404
|
-
Array.isArray(sourceInfo) ||
|
|
405
|
-
sourceInfo instanceof Date ||
|
|
406
|
-
Buffer.isBuffer(sourceInfo)
|
|
407
|
-
) {
|
|
408
|
-
throw new Error(`${name} Info.plist must contain a dictionary`)
|
|
409
|
-
}
|
|
410
|
-
const info: Record<string, plist.PlistValue> = {}
|
|
411
|
-
for (const [key, value] of Object.entries(sourceInfo)) info[key] = expandValue(value)
|
|
412
|
-
for (const [key, value] of Object.entries(settings)) {
|
|
413
|
-
if (!key.startsWith('INFOPLIST_KEY_') || key.endsWith('_Generation')) continue
|
|
414
|
-
info[key.slice('INFOPLIST_KEY_'.length)] =
|
|
415
|
-
value === 'YES' ? true : value === 'NO' ? false : expand(value)
|
|
416
|
-
}
|
|
417
|
-
if (
|
|
418
|
-
settings.INFOPLIST_KEY_UIApplicationSceneManifest_Generation === 'YES' &&
|
|
419
|
-
info.UIApplicationSceneManifest === undefined
|
|
420
|
-
) {
|
|
421
|
-
info.UIApplicationSceneManifest = {
|
|
422
|
-
UIApplicationSupportsMultipleScenes: true,
|
|
423
|
-
UISceneConfigurations: {},
|
|
424
|
-
}
|
|
488
|
+
return {
|
|
489
|
+
get: (key) => valueAt(key, levels.length - 1),
|
|
490
|
+
keys: new Set(levels.flatMap((values) => Object.keys(values))),
|
|
425
491
|
}
|
|
492
|
+
}
|
|
426
493
|
|
|
494
|
+
function expand(value: string, lookup: (name: string) => string): string {
|
|
495
|
+
return value.replace(
|
|
496
|
+
/\$(?:\(([A-Za-z_][A-Za-z0-9_]*)((?::[^)]*)?)\)|\{([A-Za-z_][A-Za-z0-9_]*)((?::[^}]*)?)\}|([A-Za-z_][A-Za-z0-9_]*))/g,
|
|
497
|
+
(_match, paren, parenOps, brace, braceOps, bare) => {
|
|
498
|
+
const name: string = paren ?? brace ?? bare
|
|
499
|
+
const operators: string = parenOps ?? braceOps ?? ''
|
|
500
|
+
return operators
|
|
501
|
+
.split(':')
|
|
502
|
+
.slice(1)
|
|
503
|
+
.reduce((current, operator) => applyOperator(current, operator), lookup(name))
|
|
504
|
+
},
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// the swift sources and resources that are members of a target.
|
|
509
|
+
function targetMembers(ref: TargetRef): {
|
|
510
|
+
sources: string[]
|
|
511
|
+
resources: string[]
|
|
512
|
+
allSources: string[]
|
|
513
|
+
} {
|
|
514
|
+
const { project, target, id: targetId } = ref
|
|
427
515
|
const sources = new Set<string>()
|
|
516
|
+
const allSources = new Set<string>()
|
|
428
517
|
const resources = new Set<string>()
|
|
429
518
|
const addResource = (file: string) => {
|
|
430
|
-
if (
|
|
519
|
+
if (isDirectory(file)) {
|
|
431
520
|
for (const inner of walkFiles(file)) resources.add(inner)
|
|
432
521
|
} else if (fs.existsSync(file)) resources.add(file)
|
|
433
522
|
}
|
|
434
523
|
const fileRefPaths = (refId: string): string[] => {
|
|
435
|
-
const
|
|
436
|
-
if (!
|
|
437
|
-
if (
|
|
438
|
-
return list(
|
|
439
|
-
const resolved = resolvePath(child)
|
|
524
|
+
const entry = project.object(refId)
|
|
525
|
+
if (!entry) return []
|
|
526
|
+
if (entry.isa === 'PBXVariantGroup') {
|
|
527
|
+
return list(entry.children).flatMap((child) => {
|
|
528
|
+
const resolved = project.resolvePath(child)
|
|
440
529
|
return resolved ? [resolved] : []
|
|
441
530
|
})
|
|
442
531
|
}
|
|
443
|
-
const resolved = resolvePath(refId)
|
|
532
|
+
const resolved = project.resolvePath(refId)
|
|
444
533
|
return resolved ? [resolved] : []
|
|
445
534
|
}
|
|
446
535
|
for (const phaseId of list(target.buildPhases)) {
|
|
447
|
-
const phase = object(phaseId)
|
|
536
|
+
const phase = project.object(phaseId)
|
|
448
537
|
if (phase?.isa !== 'PBXSourcesBuildPhase' && phase?.isa !== 'PBXResourcesBuildPhase')
|
|
449
538
|
continue
|
|
450
539
|
for (const buildFileId of list(phase.files)) {
|
|
451
|
-
for (const file of fileRefPaths(str(object(buildFileId)?.fileRef) ?? '')) {
|
|
452
|
-
if (phase.isa === 'PBXSourcesBuildPhase'
|
|
453
|
-
if (fs.existsSync(file))
|
|
540
|
+
for (const file of fileRefPaths(str(project.object(buildFileId)?.fileRef) ?? '')) {
|
|
541
|
+
if (phase.isa === 'PBXSourcesBuildPhase') {
|
|
542
|
+
if (!fs.existsSync(file)) continue
|
|
543
|
+
allSources.add(file)
|
|
544
|
+
if (file.endsWith('.swift')) sources.add(file)
|
|
454
545
|
} else if (phase.isa === 'PBXResourcesBuildPhase') addResource(file)
|
|
455
546
|
}
|
|
456
547
|
}
|
|
@@ -463,20 +554,22 @@ export function readXcodeAppTarget(
|
|
|
463
554
|
const file = path.join(folder, relative)
|
|
464
555
|
if (NEVER_MEMBER.test(relative)) return
|
|
465
556
|
if (file.endsWith('.swift')) {
|
|
466
|
-
if (!relative.split('/').some((segment) => BUNDLE_DIR.test(segment)))
|
|
557
|
+
if (!relative.split('/').some((segment) => BUNDLE_DIR.test(segment))) {
|
|
467
558
|
sources.add(file)
|
|
559
|
+
allSources.add(file)
|
|
560
|
+
}
|
|
468
561
|
} else if (/\.(h|m|mm|c|cpp|metal)$/.test(file)) {
|
|
469
|
-
|
|
562
|
+
if (!file.endsWith('.h')) allSources.add(file)
|
|
470
563
|
} else resources.add(file)
|
|
471
564
|
}
|
|
472
565
|
const owned = new Set(list(target.fileSystemSynchronizedGroups))
|
|
473
|
-
for (const [groupId, group] of Object.entries(objects)) {
|
|
566
|
+
for (const [groupId, group] of Object.entries(project.objects)) {
|
|
474
567
|
if (!isDict(group) || group.isa !== 'PBXFileSystemSynchronizedRootGroup') continue
|
|
475
|
-
const folder = resolvePath(groupId)
|
|
568
|
+
const folder = project.resolvePath(groupId)
|
|
476
569
|
if (!folder) continue
|
|
477
570
|
const exceptions = new Set<string>()
|
|
478
571
|
for (const exceptionId of list(group.exceptions)) {
|
|
479
|
-
const exception = object(exceptionId)
|
|
572
|
+
const exception = project.object(exceptionId)
|
|
480
573
|
if (exception?.target !== targetId) continue
|
|
481
574
|
for (const relative of list(exception.membershipExceptions))
|
|
482
575
|
exceptions.add(relative)
|
|
@@ -495,7 +588,7 @@ export function readXcodeAppTarget(
|
|
|
495
588
|
} else {
|
|
496
589
|
for (const relative of exceptions) {
|
|
497
590
|
const file = path.join(folder, relative)
|
|
498
|
-
if (
|
|
591
|
+
if (isDirectory(file)) {
|
|
499
592
|
for (const inner of walkFiles(file))
|
|
500
593
|
addSynchronized(
|
|
501
594
|
folder,
|
|
@@ -505,21 +598,263 @@ export function readXcodeAppTarget(
|
|
|
505
598
|
}
|
|
506
599
|
}
|
|
507
600
|
}
|
|
601
|
+
return {
|
|
602
|
+
sources: [...sources].sort(),
|
|
603
|
+
resources: [...resources].sort(),
|
|
604
|
+
allSources: [...allSources].sort(),
|
|
605
|
+
}
|
|
606
|
+
}
|
|
508
607
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
608
|
+
function commonAncestor(dirs: string[]): string {
|
|
609
|
+
let common = dirs[0]!
|
|
610
|
+
for (const dir of dirs) {
|
|
611
|
+
while (common !== path.dirname(common) && path.relative(common, dir).startsWith('..'))
|
|
612
|
+
common = path.dirname(common)
|
|
613
|
+
}
|
|
614
|
+
return common
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// every project a workspace or project builds: listed ones and the projects
|
|
618
|
+
// nested in them. cocoapods' generated project builds objective-c pods, never
|
|
619
|
+
// app swift.
|
|
620
|
+
function workspaceProjects(xcodeprojOrWorkspace: string): {
|
|
621
|
+
listed: string[]
|
|
622
|
+
projects: LoadedProject[]
|
|
623
|
+
projectAt: Map<string, LoadedProject>
|
|
624
|
+
} {
|
|
625
|
+
const listed = xcodeprojOrWorkspace.endsWith('.xcworkspace')
|
|
626
|
+
? workspaceReferences(xcodeprojOrWorkspace)
|
|
627
|
+
: [xcodeprojOrWorkspace]
|
|
628
|
+
const projects: LoadedProject[] = []
|
|
629
|
+
const projectAt = new Map<string, LoadedProject>()
|
|
630
|
+
const addProject = (xcodeproj: string) => {
|
|
631
|
+
const key = path.resolve(xcodeproj)
|
|
632
|
+
if (projectAt.has(key) || key.split(path.sep).includes('Pods')) return
|
|
633
|
+
if (!fs.existsSync(path.join(key, 'project.pbxproj'))) return
|
|
634
|
+
const project = loadProject(key)
|
|
635
|
+
projectAt.set(key, project)
|
|
636
|
+
projects.push(project)
|
|
637
|
+
const nested = project.project.projectReferences
|
|
638
|
+
if (Array.isArray(nested)) {
|
|
639
|
+
for (const entry of nested) {
|
|
640
|
+
const ref = isDict(entry) ? str(entry.ProjectRef) : undefined
|
|
641
|
+
const resolved = ref ? project.resolvePath(ref) : null
|
|
642
|
+
if (resolved) addProject(resolved)
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
for (const reference of listed)
|
|
647
|
+
if (reference.endsWith('.xcodeproj')) addProject(reference)
|
|
648
|
+
if (projects.length === 0) {
|
|
649
|
+
throw new Error(`${path.basename(xcodeprojOrWorkspace)} lists no Xcode project`)
|
|
650
|
+
}
|
|
651
|
+
return { listed, projects, projectAt }
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const nativeTargets = (project: LoadedProject): TargetRef[] =>
|
|
655
|
+
list(project.project.targets).flatMap((id) => {
|
|
656
|
+
const target = project.object(id)
|
|
657
|
+
return target?.isa === 'PBXNativeTarget' ? [{ project, id, target }] : []
|
|
522
658
|
})
|
|
659
|
+
|
|
660
|
+
/** the names of every application target a workspace or project builds. */
|
|
661
|
+
export function listXcodeAppTargets(xcodeprojOrWorkspace: string): string[] {
|
|
662
|
+
return workspaceProjects(xcodeprojOrWorkspace)
|
|
663
|
+
.projects.flatMap(nativeTargets)
|
|
664
|
+
.filter((ref) => ref.target.productType === APPLICATION)
|
|
665
|
+
.map((ref) => str(ref.target.name) ?? ref.id)
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* the application target `targetName` names (or the workspace's only one),
|
|
670
|
+
* with every framework, library and package it builds: its member files
|
|
671
|
+
* listed fresh from disk, so a file added to a synchronized folder joins the
|
|
672
|
+
* target without any project change.
|
|
673
|
+
*/
|
|
674
|
+
export function readXcodeAppTarget(
|
|
675
|
+
xcodeprojOrWorkspace: string,
|
|
676
|
+
targetName?: string,
|
|
677
|
+
): XcodeAppTarget {
|
|
678
|
+
const workspace = xcodeprojOrWorkspace.endsWith('.xcworkspace')
|
|
679
|
+
? xcodeprojOrWorkspace
|
|
680
|
+
: null
|
|
681
|
+
const { listed, projects, projectAt } = workspaceProjects(xcodeprojOrWorkspace)
|
|
682
|
+
const allTargets = projects.flatMap(nativeTargets)
|
|
683
|
+
const appTargets = allTargets.filter((ref) => ref.target.productType === APPLICATION)
|
|
684
|
+
const appTargetNames = appTargets.map((ref) => str(ref.target.name) ?? ref.id)
|
|
685
|
+
const container = path.basename(xcodeprojOrWorkspace)
|
|
686
|
+
const named = targetName
|
|
687
|
+
? appTargets.filter((ref) => ref.target.name === targetName)
|
|
688
|
+
: appTargets
|
|
689
|
+
if (named.length !== 1) {
|
|
690
|
+
throw new Error(
|
|
691
|
+
targetName && named.length === 0
|
|
692
|
+
? `${container} has no application target ${targetName}; it has ${appTargetNames.join(', ') || 'none'}`
|
|
693
|
+
: targetName
|
|
694
|
+
? `${container} has ${named.length} application targets named ${targetName}; open its .xcodeproj`
|
|
695
|
+
: `${container} has ${appTargetNames.length} application targets (${appTargetNames.join(', ') || 'none'}); pass --target`,
|
|
696
|
+
)
|
|
697
|
+
}
|
|
698
|
+
const app = named[0]!
|
|
699
|
+
|
|
700
|
+
// dependencies: explicit target dependencies, in this project or another
|
|
701
|
+
// through a container proxy, and products linked by file name, which xcode
|
|
702
|
+
// finds implicitly across the workspace.
|
|
703
|
+
const byProduct = new Map<string, TargetRef>()
|
|
704
|
+
for (const ref of allTargets) {
|
|
705
|
+
const product = ref.project.object(str(ref.target.productReference))
|
|
706
|
+
const file = str(product?.path)
|
|
707
|
+
if (file && !byProduct.has(path.basename(file)))
|
|
708
|
+
byProduct.set(path.basename(file), ref)
|
|
709
|
+
}
|
|
710
|
+
const proxied = (
|
|
711
|
+
project: LoadedProject,
|
|
712
|
+
proxyId: string | undefined,
|
|
713
|
+
): TargetRef | undefined => {
|
|
714
|
+
const proxy = project.object(proxyId)
|
|
715
|
+
if (proxy?.isa !== 'PBXContainerItemProxy') return undefined
|
|
716
|
+
const portal = str(proxy.containerPortal)
|
|
717
|
+
const owner =
|
|
718
|
+
project.object(portal)?.isa === 'PBXProject'
|
|
719
|
+
? project
|
|
720
|
+
: projectAt.get(path.resolve(project.resolvePath(portal ?? '') ?? ''))
|
|
721
|
+
const remote = str(proxy.remoteGlobalIDString)
|
|
722
|
+
if (!owner || !remote) return undefined
|
|
723
|
+
return nativeTargets(owner).find(
|
|
724
|
+
(ref) => ref.id === remote || str(ref.target.productReference) === remote,
|
|
725
|
+
)
|
|
726
|
+
}
|
|
727
|
+
const dependenciesOf = (ref: TargetRef): TargetRef[] => {
|
|
728
|
+
const { project, target } = ref
|
|
729
|
+
const found: TargetRef[] = []
|
|
730
|
+
for (const dependencyId of list(target.dependencies)) {
|
|
731
|
+
const dependency = project.object(dependencyId)
|
|
732
|
+
const direct = str(dependency?.target)
|
|
733
|
+
const resolved = direct
|
|
734
|
+
? nativeTargets(project).find((candidate) => candidate.id === direct)
|
|
735
|
+
: proxied(project, str(dependency?.targetProxy))
|
|
736
|
+
if (resolved) found.push(resolved)
|
|
737
|
+
}
|
|
738
|
+
for (const phaseId of list(target.buildPhases)) {
|
|
739
|
+
const phase = project.object(phaseId)
|
|
740
|
+
if (phase?.isa !== 'PBXFrameworksBuildPhase') continue
|
|
741
|
+
for (const buildFileId of list(phase.files)) {
|
|
742
|
+
const file = project.object(str(project.object(buildFileId)?.fileRef))
|
|
743
|
+
const resolved =
|
|
744
|
+
file?.isa === 'PBXReferenceProxy'
|
|
745
|
+
? proxied(project, str(file.remoteRef))
|
|
746
|
+
: file && str(file.sourceTree) === 'BUILT_PRODUCTS_DIR'
|
|
747
|
+
? byProduct.get(path.basename(str(file.path) ?? ''))
|
|
748
|
+
: undefined
|
|
749
|
+
if (resolved) found.push(resolved)
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return found.filter((candidate) =>
|
|
753
|
+
MODULE_PRODUCTS.has(str(candidate.target.productType) ?? ''),
|
|
754
|
+
)
|
|
755
|
+
}
|
|
756
|
+
const order: TargetRef[] = []
|
|
757
|
+
const visited = new Set<TargetRef>()
|
|
758
|
+
const visit = (ref: TargetRef) => {
|
|
759
|
+
if (visited.has(ref)) return
|
|
760
|
+
visited.add(ref)
|
|
761
|
+
for (const dependency of dependenciesOf(ref)) visit(dependency)
|
|
762
|
+
order.push(ref)
|
|
763
|
+
}
|
|
764
|
+
visit(app)
|
|
765
|
+
|
|
766
|
+
const moduleTarget = (ref: TargetRef) => {
|
|
767
|
+
const name = str(ref.target.name) ?? ref.id
|
|
768
|
+
const { get: settings, keys } = targetSettings(ref, {
|
|
769
|
+
TARGET_NAME: name,
|
|
770
|
+
PROJECT_NAME: path.basename(ref.project.xcodeproj, '.xcodeproj'),
|
|
771
|
+
SRCROOT: ref.project.projectDir,
|
|
772
|
+
SOURCE_ROOT: ref.project.projectDir,
|
|
773
|
+
PROJECT_DIR: ref.project.projectDir,
|
|
774
|
+
DEVELOPMENT_LANGUAGE: str(ref.project.project.developmentRegion) ?? 'en',
|
|
775
|
+
})
|
|
776
|
+
const swiftVersion = Number.parseFloat(settings('SWIFT_VERSION') || '5')
|
|
777
|
+
return {
|
|
778
|
+
settings,
|
|
779
|
+
keys,
|
|
780
|
+
module: {
|
|
781
|
+
name,
|
|
782
|
+
moduleName: applyOperator(settings('PRODUCT_MODULE_NAME'), 'c99extidentifier'),
|
|
783
|
+
...targetMembers(ref),
|
|
784
|
+
languageMode: swiftVersion >= 6 ? 6 : 5,
|
|
785
|
+
mainActorIsolation: settings('SWIFT_DEFAULT_ACTOR_ISOLATION') === 'MainActor',
|
|
786
|
+
} satisfies XcodeModuleTarget,
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
const { settings, keys: settingKeys, module } = moduleTarget(app)
|
|
790
|
+
const frameworks = order.slice(0, -1).map((ref) => moduleTarget(ref).module)
|
|
791
|
+
|
|
792
|
+
const expandValue = (value: plist.PlistValue): plist.PlistValue => {
|
|
793
|
+
if (typeof value === 'string') return expand(value, settings)
|
|
794
|
+
if (Array.isArray(value)) return value.map(expandValue)
|
|
795
|
+
if (
|
|
796
|
+
typeof value === 'object' &&
|
|
797
|
+
!(value instanceof Date) &&
|
|
798
|
+
!Buffer.isBuffer(value)
|
|
799
|
+
) {
|
|
800
|
+
return Object.fromEntries(
|
|
801
|
+
Object.entries(value).map(([key, value]) => [key, expandValue(value)]),
|
|
802
|
+
)
|
|
803
|
+
}
|
|
804
|
+
return value
|
|
805
|
+
}
|
|
806
|
+
const infoPlistFile = settings('INFOPLIST_FILE')
|
|
807
|
+
? path.resolve(app.project.projectDir, settings('INFOPLIST_FILE'))
|
|
808
|
+
: null
|
|
809
|
+
const sourceInfo = infoPlistFile
|
|
810
|
+
? plist.parse(fs.readFileSync(infoPlistFile, 'utf8'))
|
|
811
|
+
: {}
|
|
812
|
+
if (
|
|
813
|
+
!sourceInfo ||
|
|
814
|
+
typeof sourceInfo !== 'object' ||
|
|
815
|
+
Array.isArray(sourceInfo) ||
|
|
816
|
+
sourceInfo instanceof Date ||
|
|
817
|
+
Buffer.isBuffer(sourceInfo)
|
|
818
|
+
) {
|
|
819
|
+
throw new Error(`${module.name} Info.plist must contain a dictionary`)
|
|
820
|
+
}
|
|
821
|
+
const info: Record<string, plist.PlistValue> = {}
|
|
822
|
+
for (const [key, value] of Object.entries(sourceInfo)) info[key] = expandValue(value)
|
|
823
|
+
for (const key of settingKeys) {
|
|
824
|
+
if (!key.startsWith('INFOPLIST_KEY_') || key.endsWith('_Generation')) continue
|
|
825
|
+
const value = settings(key)
|
|
826
|
+
info[key.slice('INFOPLIST_KEY_'.length)] =
|
|
827
|
+
value === 'YES' ? true : value === 'NO' ? false : value
|
|
828
|
+
}
|
|
829
|
+
if (
|
|
830
|
+
settings('INFOPLIST_KEY_UIApplicationSceneManifest_Generation') === 'YES' &&
|
|
831
|
+
info.UIApplicationSceneManifest === undefined
|
|
832
|
+
) {
|
|
833
|
+
info.UIApplicationSceneManifest = {
|
|
834
|
+
UIApplicationSupportsMultipleScenes: true,
|
|
835
|
+
UISceneConfigurations: {},
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// linked products: a remote reference names its repository; one without a
|
|
840
|
+
// package comes from a local package folder a project or the workspace references.
|
|
841
|
+
const localPackageDirs = [
|
|
842
|
+
...listed.filter((reference) => fs.existsSync(path.join(reference, 'Package.swift'))),
|
|
843
|
+
...projects.flatMap((project) =>
|
|
844
|
+
Object.entries(project.objects).flatMap(([id, entry]) => {
|
|
845
|
+
if (!isDict(entry)) return []
|
|
846
|
+
const candidate =
|
|
847
|
+
entry.isa === 'XCLocalSwiftPackageReference'
|
|
848
|
+
? path.resolve(project.projectDir, str(entry.relativePath) ?? '')
|
|
849
|
+
: entry.isa === 'PBXFileReference'
|
|
850
|
+
? project.resolvePath(id)
|
|
851
|
+
: null
|
|
852
|
+
return candidate && fs.existsSync(path.join(candidate, 'Package.swift'))
|
|
853
|
+
? [candidate]
|
|
854
|
+
: []
|
|
855
|
+
}),
|
|
856
|
+
),
|
|
857
|
+
]
|
|
523
858
|
const graphs = new Map<string, ReturnType<typeof swiftManifestGraph>>()
|
|
524
859
|
const graphOf = (dir: string) => {
|
|
525
860
|
const cached = graphs.get(dir)
|
|
@@ -532,26 +867,40 @@ export function readXcodeAppTarget(
|
|
|
532
867
|
}
|
|
533
868
|
const localProducts = new Map<string, string>()
|
|
534
869
|
for (const dir of localPackageDirs) {
|
|
535
|
-
for (const product of graphOf(dir).products.keys())
|
|
870
|
+
for (const product of graphOf(dir).products.keys()) {
|
|
871
|
+
if (!localProducts.has(product)) localProducts.set(product, dir)
|
|
872
|
+
}
|
|
536
873
|
}
|
|
537
874
|
const localPackages = new Set<string>()
|
|
538
875
|
const remoteProducts: XcodeRemoteProduct[] = []
|
|
539
876
|
const unresolvedProducts: string[] = []
|
|
540
|
-
for (const
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
877
|
+
for (const { project, target } of order) {
|
|
878
|
+
const productDependencies = [
|
|
879
|
+
...list(target.packageProductDependencies),
|
|
880
|
+
...list(target.dependencies).flatMap((id) => {
|
|
881
|
+
const productRef = str(project.object(id)?.productRef)
|
|
882
|
+
return productRef ? [productRef] : []
|
|
883
|
+
}),
|
|
884
|
+
]
|
|
885
|
+
for (const dependencyId of productDependencies) {
|
|
886
|
+
const dependency = project.object(dependencyId)
|
|
887
|
+
const product = str(dependency?.productName)?.replace(/^plugin:/, '')
|
|
888
|
+
if (!dependency || !product) continue
|
|
889
|
+
const reference = project.object(str(dependency.package))
|
|
890
|
+
if (reference?.isa === 'XCRemoteSwiftPackageReference') {
|
|
891
|
+
if (!remoteProducts.some((entry) => entry.product === product))
|
|
892
|
+
remoteProducts.push({
|
|
893
|
+
product,
|
|
894
|
+
repositoryURL: str(reference.repositoryURL) ?? '',
|
|
895
|
+
})
|
|
896
|
+
} else if (reference?.isa === 'XCLocalSwiftPackageReference') {
|
|
897
|
+
localPackages.add(
|
|
898
|
+
path.resolve(project.projectDir, str(reference.relativePath) ?? ''),
|
|
899
|
+
)
|
|
900
|
+
} else if (localProducts.has(product)) {
|
|
901
|
+
localPackages.add(localProducts.get(product)!)
|
|
902
|
+
} else if (!unresolvedProducts.includes(product)) unresolvedProducts.push(product)
|
|
903
|
+
}
|
|
555
904
|
}
|
|
556
905
|
|
|
557
906
|
// local packages depend on further local packages by path, and on remote
|
|
@@ -577,35 +926,31 @@ export function readXcodeAppTarget(
|
|
|
577
926
|
}
|
|
578
927
|
}
|
|
579
928
|
|
|
580
|
-
// xcode keeps the pins
|
|
581
|
-
const
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
.map((entry) => path.join(projectDir, entry)),
|
|
588
|
-
]
|
|
589
|
-
.map((workspace) =>
|
|
590
|
-
path.join(workspace, 'xcshareddata', 'swiftpm', 'Package.resolved'),
|
|
591
|
-
)
|
|
592
|
-
.find((file) => fs.existsSync(file)) ?? null
|
|
929
|
+
// xcode keeps the pins in the workspace it opened: the named one, or the project's own
|
|
930
|
+
const resolvedFile = path.join(
|
|
931
|
+
workspace ?? path.join(xcodeprojOrWorkspace, 'project.xcworkspace'),
|
|
932
|
+
'xcshareddata',
|
|
933
|
+
'swiftpm',
|
|
934
|
+
'Package.resolved',
|
|
935
|
+
)
|
|
593
936
|
|
|
594
|
-
const
|
|
937
|
+
const used = [app, ...order].map((ref) => ref.project)
|
|
595
938
|
return {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
939
|
+
...module,
|
|
940
|
+
rootDir: commonAncestor(
|
|
941
|
+
[
|
|
942
|
+
workspace ? path.dirname(workspace) : app.project.projectDir,
|
|
943
|
+
...used.map((project) => project.projectDir),
|
|
944
|
+
...localPackages,
|
|
945
|
+
].map((dir) => fs.realpathSync(dir)),
|
|
946
|
+
),
|
|
947
|
+
pbxprojs: [...new Set(used.map((project) => project.pbxproj))].sort(),
|
|
602
948
|
infoPlist: plist.build(info),
|
|
603
949
|
infoPlistFile,
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
localPackages: [...localPackages].sort(),
|
|
950
|
+
frameworks,
|
|
951
|
+
localPackages: [...localPackages].map((dir) => fs.realpathSync(dir)).sort(),
|
|
607
952
|
remoteProducts,
|
|
608
|
-
packageResolved,
|
|
953
|
+
packageResolved: fs.existsSync(resolvedFile) ? resolvedFile : null,
|
|
609
954
|
unresolvedProducts,
|
|
610
955
|
appTargets: appTargetNames,
|
|
611
956
|
}
|