peachsim 0.1.759 → 0.1.761
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/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 +888 -735
- 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 +37 -220
- 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 +37 -220
- 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 +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +1185 -1026
- package/dist-lib/swift-compile.cjs +66 -8
- package/dist-lib/swift-compile.mjs +66 -8
- package/dist-lib/swift-package.cjs +1 -110
- package/dist-lib/swift-package.mjs +1 -109
- 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 +672 -519
- package/dist-lib/vite.cjs +1 -1
- package/package.json +1 -1
- package/src/native-seam-manifest.ts +8 -0
- package/src/swift-compile.ts +102 -12
- package/src/swift-host.ts +64 -64
- package/src/swift-package-manifest.ts +307 -0
- package/src/swift-package.ts +2 -135
- package/src/swift-packages.ts +341 -0
- package/src/xcode-project.ts +57 -70
- package/src/swift-remote-packages.ts +0 -255
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// a swift package's manifest as swiftpm evaluates it. a manifest is swift
|
|
2
|
+
// code: names come from constants, products from helper extensions, and a
|
|
3
|
+
// version-specific Package@swift-x.swift can stand in for Package.swift, so
|
|
4
|
+
// only swiftpm reads it right. `swift package dump-package` runs it, through
|
|
5
|
+
// xcode's swiftpm on macOS (the one xcode resolves an app's packages with)
|
|
6
|
+
// and the pinned swift.org toolchain on linux, where no xcode exists.
|
|
7
|
+
|
|
8
|
+
import { execFileSync } from 'node:child_process'
|
|
9
|
+
import { createHash } from 'node:crypto'
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import os from 'node:os'
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import lock from './swift-distribution.lock.json' with { type: 'json' }
|
|
14
|
+
import { swiftToolchainBin } from './swift-toolchain'
|
|
15
|
+
import type { SwiftTargetDependency } from './swift-package'
|
|
16
|
+
|
|
17
|
+
const TARGET_TYPES = [
|
|
18
|
+
'regular',
|
|
19
|
+
'executable',
|
|
20
|
+
'test',
|
|
21
|
+
'binary',
|
|
22
|
+
'system',
|
|
23
|
+
'macro',
|
|
24
|
+
'plugin',
|
|
25
|
+
] as const
|
|
26
|
+
export type SwiftManifestTargetType = (typeof TARGET_TYPES)[number]
|
|
27
|
+
const isTargetType = (value: string | undefined): value is SwiftManifestTargetType =>
|
|
28
|
+
TARGET_TYPES.some((type) => type === value)
|
|
29
|
+
|
|
30
|
+
export interface SwiftManifestTarget {
|
|
31
|
+
name: string
|
|
32
|
+
type: SwiftManifestTargetType
|
|
33
|
+
/** the target directory, absolute. */
|
|
34
|
+
dir: string
|
|
35
|
+
/** the target's `sources:`, relative to `dir`; null means all of `dir`. */
|
|
36
|
+
sources: string[] | null
|
|
37
|
+
/** the target's `exclude:`, relative to `dir`. */
|
|
38
|
+
exclude: string[]
|
|
39
|
+
/** dependencies that link on iOS with the package's default traits. */
|
|
40
|
+
dependencies: SwiftTargetDependency[]
|
|
41
|
+
languageMode: number
|
|
42
|
+
mainActorIsolation: boolean
|
|
43
|
+
/** true when the target declares `resources:`. */
|
|
44
|
+
declaresResources: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SwiftPackageManifest {
|
|
48
|
+
dir: string
|
|
49
|
+
/** library product name to the targets it vends. */
|
|
50
|
+
products: Map<string, string[]>
|
|
51
|
+
targets: Map<string, SwiftManifestTarget>
|
|
52
|
+
/** package dependencies by identity and by any `name:` they carry. */
|
|
53
|
+
packages: Map<string, { url: string } | { dir: string }>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// the dump's tagged unions: `{ "<case>": [payload...] }`
|
|
57
|
+
type Json = null | boolean | number | string | Json[] | { [key: string]: Json }
|
|
58
|
+
const record = (value: Json | undefined): Record<string, Json> =>
|
|
59
|
+
value && typeof value === 'object' && !Array.isArray(value) ? value : {}
|
|
60
|
+
const array = (value: Json | undefined): Json[] => (Array.isArray(value) ? value : [])
|
|
61
|
+
const string = (value: Json | undefined): string | undefined =>
|
|
62
|
+
typeof value === 'string' ? value : undefined
|
|
63
|
+
|
|
64
|
+
function swiftCommand(): { file: string; args: string[] } {
|
|
65
|
+
return process.platform === 'darwin'
|
|
66
|
+
? { file: 'xcrun', args: ['swift'] }
|
|
67
|
+
: { file: path.join(swiftToolchainBin(lock.release), 'swift'), args: [] }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const cacheDir = path.join(os.tmpdir(), 'peach-swift-manifests')
|
|
71
|
+
const evaluated = new Map<string, SwiftPackageManifest>()
|
|
72
|
+
|
|
73
|
+
function dump(dir: string): { key: string; raw: Record<string, Json> } {
|
|
74
|
+
const manifests = fs
|
|
75
|
+
.readdirSync(dir)
|
|
76
|
+
.filter((name) => /^Package(@swift-[\d.]+)?\.swift$/.test(name))
|
|
77
|
+
.sort()
|
|
78
|
+
const command = swiftCommand()
|
|
79
|
+
const key = createHash('sha256')
|
|
80
|
+
.update(JSON.stringify([command, path.resolve(dir)]))
|
|
81
|
+
.update(
|
|
82
|
+
manifests
|
|
83
|
+
.map((name) => `${name}\0${fs.readFileSync(path.join(dir, name), 'utf8')}`)
|
|
84
|
+
.join('\0'),
|
|
85
|
+
)
|
|
86
|
+
.digest('hex')
|
|
87
|
+
.slice(0, 32)
|
|
88
|
+
const cached = path.join(cacheDir, `${key}.json`)
|
|
89
|
+
if (fs.existsSync(cached))
|
|
90
|
+
return { key, raw: record(JSON.parse(fs.readFileSync(cached, 'utf8'))) }
|
|
91
|
+
let output: string
|
|
92
|
+
try {
|
|
93
|
+
output = execFileSync(
|
|
94
|
+
command.file,
|
|
95
|
+
[
|
|
96
|
+
...command.args,
|
|
97
|
+
'package',
|
|
98
|
+
'--package-path',
|
|
99
|
+
dir,
|
|
100
|
+
// swiftpm's scratch files never land in the app's own package
|
|
101
|
+
'--scratch-path',
|
|
102
|
+
path.join(cacheDir, `${key}.build`),
|
|
103
|
+
'dump-package',
|
|
104
|
+
],
|
|
105
|
+
{
|
|
106
|
+
encoding: 'utf8',
|
|
107
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
108
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
109
|
+
},
|
|
110
|
+
)
|
|
111
|
+
} catch (error) {
|
|
112
|
+
const stderr =
|
|
113
|
+
error instanceof Error && 'stderr' in error ? String(error.stderr).trim() : ''
|
|
114
|
+
throw new Error(
|
|
115
|
+
`swiftpm could not evaluate ${path.join(dir, 'Package.swift')}${stderr ? `: ${stderr}` : ''}`,
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
fs.mkdirSync(cacheDir, { recursive: true })
|
|
119
|
+
fs.writeFileSync(cached, output)
|
|
120
|
+
return { key, raw: record(JSON.parse(output)) }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// the traits a consumer gets by default: `default`'s, and what they enable
|
|
124
|
+
function defaultTraits(manifest: Record<string, Json>): Set<string> {
|
|
125
|
+
const traits = new Map(
|
|
126
|
+
array(manifest.traits).map((trait) => [
|
|
127
|
+
string(record(trait).name) ?? '',
|
|
128
|
+
array(record(trait).enabledTraits).flatMap((name) => string(name) ?? []),
|
|
129
|
+
]),
|
|
130
|
+
)
|
|
131
|
+
const enabled = new Set<string>()
|
|
132
|
+
const pending = [...(traits.get('default') ?? [])]
|
|
133
|
+
while (pending.length > 0) {
|
|
134
|
+
const name = pending.pop()!
|
|
135
|
+
if (enabled.has(name)) continue
|
|
136
|
+
enabled.add(name)
|
|
137
|
+
pending.push(...(traits.get(name) ?? []))
|
|
138
|
+
}
|
|
139
|
+
return enabled
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// a condition holds on iOS when it names no platforms or names iOS, and its
|
|
143
|
+
// traits, if any, include one the package enables by default
|
|
144
|
+
function linksOnIOS(condition: Json | undefined, traits: Set<string>): boolean {
|
|
145
|
+
const { platformNames, traits: needed } = record(condition)
|
|
146
|
+
const platforms = array(platformNames)
|
|
147
|
+
if (platforms.length > 0 && !platforms.includes('ios')) return false
|
|
148
|
+
const gates = array(needed)
|
|
149
|
+
return gates.length === 0 || gates.some((name) => traits.has(string(name) ?? ''))
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** the manifest of the package at `dir`, evaluated once per manifest content. */
|
|
153
|
+
export function swiftPackageManifest(dir: string): SwiftPackageManifest {
|
|
154
|
+
dir = fs.realpathSync(dir)
|
|
155
|
+
const { key, raw } = dump(dir)
|
|
156
|
+
const known = evaluated.get(key)
|
|
157
|
+
if (known) return known
|
|
158
|
+
const traits = defaultTraits(raw)
|
|
159
|
+
const tools = Number(
|
|
160
|
+
/^(\d+)/.exec(string(record(raw.toolsVersion)._version) ?? '5')?.[1] ?? 5,
|
|
161
|
+
)
|
|
162
|
+
const declaredModes = array(raw.swiftLanguageVersions).flatMap((mode) => {
|
|
163
|
+
const major = Number(/^(\d+)/.exec(string(mode) ?? '')?.[1])
|
|
164
|
+
return Number.isFinite(major) ? [major] : []
|
|
165
|
+
})
|
|
166
|
+
// swiftpm builds in the newest mode a package declares; with none, tools
|
|
167
|
+
// 6 and later default to 6. peach compiles modes 5 and 6.
|
|
168
|
+
const packageMode = Math.max(
|
|
169
|
+
5,
|
|
170
|
+
declaredModes.length > 0 ? Math.max(...declaredModes) : tools >= 6 ? 6 : 5,
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
const packages: SwiftPackageManifest['packages'] = new Map()
|
|
174
|
+
for (const entry of array(raw.dependencies)) {
|
|
175
|
+
const { sourceControl, fileSystem } = record(entry)
|
|
176
|
+
const source = record(array(sourceControl ?? fileSystem)[0])
|
|
177
|
+
const identity = string(source.identity)
|
|
178
|
+
if (!identity) continue
|
|
179
|
+
const url = string(record(array(record(source.location).remote)[0]).urlString)
|
|
180
|
+
const local = string(source.path)
|
|
181
|
+
const value = url ? { url } : local ? { dir: local } : null
|
|
182
|
+
if (!value) continue
|
|
183
|
+
packages.set(identity, value)
|
|
184
|
+
const alias = string(source.nameForTargetDependencyResolutionOnly)
|
|
185
|
+
if (alias) packages.set(alias.toLowerCase(), value)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const products = new Map<string, string[]>()
|
|
189
|
+
for (const product of array(raw.products)) {
|
|
190
|
+
const { name, targets, type } = record(product)
|
|
191
|
+
if (!string(name) || !('library' in record(type))) continue
|
|
192
|
+
products.set(
|
|
193
|
+
string(name)!,
|
|
194
|
+
array(targets).flatMap((target) => string(target) ?? []),
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const targets = new Map<string, SwiftManifestTarget>()
|
|
199
|
+
const names = new Set(array(raw.targets).map((target) => string(record(target).name)))
|
|
200
|
+
for (const entry of array(raw.targets)) {
|
|
201
|
+
const target = record(entry)
|
|
202
|
+
const name = string(target.name)
|
|
203
|
+
const kind = string(target.type)
|
|
204
|
+
if (!name || !isTargetType(kind)) continue
|
|
205
|
+
const declared = string(target.path)
|
|
206
|
+
const roots = kind === 'test' ? ['Tests'] : ['Sources', 'Source', 'src', 'srcs']
|
|
207
|
+
const targetDir = declared
|
|
208
|
+
? path.resolve(dir, declared)
|
|
209
|
+
: (roots
|
|
210
|
+
.map((root) => path.join(dir, root, name))
|
|
211
|
+
.find((candidate) => fs.existsSync(candidate)) ??
|
|
212
|
+
path.join(dir, roots[0]!, name))
|
|
213
|
+
const dependencies: SwiftTargetDependency[] = []
|
|
214
|
+
for (const dependency of array(target.dependencies)) {
|
|
215
|
+
const { target: local, product, byName } = record(dependency)
|
|
216
|
+
const payload = array(local ?? product ?? byName)
|
|
217
|
+
if (!linksOnIOS(payload[payload.length - 1], traits)) continue
|
|
218
|
+
const dependencyName = string(payload[0])
|
|
219
|
+
if (!dependencyName) continue
|
|
220
|
+
if (product)
|
|
221
|
+
dependencies.push({
|
|
222
|
+
kind: 'product',
|
|
223
|
+
name: dependencyName,
|
|
224
|
+
package: (string(payload[1]) ?? '').toLowerCase(),
|
|
225
|
+
})
|
|
226
|
+
// a by-name dependency that is no target here is the product of that
|
|
227
|
+
// name in the dependency package of the same name
|
|
228
|
+
else if (local || names.has(dependencyName))
|
|
229
|
+
dependencies.push({ kind: 'target', name: dependencyName })
|
|
230
|
+
else
|
|
231
|
+
dependencies.push({
|
|
232
|
+
kind: 'product',
|
|
233
|
+
name: dependencyName,
|
|
234
|
+
package: dependencyName.toLowerCase(),
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
let languageMode = packageMode
|
|
238
|
+
let mainActorIsolation = false
|
|
239
|
+
for (const setting of array(target.settings)) {
|
|
240
|
+
const settingKind = record(record(setting).kind)
|
|
241
|
+
const mode = string(record(settingKind.swiftLanguageMode)._0)
|
|
242
|
+
if (mode)
|
|
243
|
+
languageMode = Math.max(5, Number(/^(\d+)/.exec(mode)?.[1] ?? languageMode))
|
|
244
|
+
if (string(record(settingKind.defaultIsolation)._0) === 'MainActor')
|
|
245
|
+
mainActorIsolation = true
|
|
246
|
+
}
|
|
247
|
+
targets.set(name, {
|
|
248
|
+
name,
|
|
249
|
+
type: kind,
|
|
250
|
+
dir: targetDir,
|
|
251
|
+
sources:
|
|
252
|
+
target.sources == null
|
|
253
|
+
? null
|
|
254
|
+
: array(target.sources).flatMap((file) => string(file) ?? []),
|
|
255
|
+
exclude: array(target.exclude).flatMap((file) => string(file) ?? []),
|
|
256
|
+
dependencies,
|
|
257
|
+
languageMode,
|
|
258
|
+
mainActorIsolation,
|
|
259
|
+
declaresResources: array(target.resources).length > 0,
|
|
260
|
+
})
|
|
261
|
+
}
|
|
262
|
+
const manifest = { dir, products, targets, packages }
|
|
263
|
+
evaluated.set(key, manifest)
|
|
264
|
+
return manifest
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const within = (file: string, roots: string[]) =>
|
|
268
|
+
roots.some((root) => file === root || file.startsWith(`${root}${path.sep}`))
|
|
269
|
+
|
|
270
|
+
function walk(dir: string): string[] {
|
|
271
|
+
if (!fs.existsSync(dir)) return []
|
|
272
|
+
if (fs.statSync(dir).isFile()) return [dir]
|
|
273
|
+
const out: string[] = []
|
|
274
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
275
|
+
if (entry.name.startsWith('.')) continue
|
|
276
|
+
const full = path.join(dir, entry.name)
|
|
277
|
+
if (entry.isDirectory()) out.push(...walk(full))
|
|
278
|
+
else if (entry.isFile()) out.push(full)
|
|
279
|
+
}
|
|
280
|
+
return out
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* the files swiftpm assigns a target, absolute and sorted: its `sources:`
|
|
285
|
+
* (else its whole directory), less its `exclude:` and the directories of
|
|
286
|
+
* the package's other targets nested inside it.
|
|
287
|
+
*/
|
|
288
|
+
export function swiftTargetFiles(
|
|
289
|
+
manifest: SwiftPackageManifest,
|
|
290
|
+
target: SwiftManifestTarget,
|
|
291
|
+
): string[] {
|
|
292
|
+
const included = target.sources
|
|
293
|
+
? target.sources.map((source) => path.resolve(target.dir, source))
|
|
294
|
+
: [target.dir]
|
|
295
|
+
const excluded = [
|
|
296
|
+
...target.exclude.map((file) => path.resolve(target.dir, file)),
|
|
297
|
+
...[...manifest.targets.values()].flatMap((other) =>
|
|
298
|
+
other !== target && within(other.dir, [target.dir]) && other.dir !== target.dir
|
|
299
|
+
? [other.dir]
|
|
300
|
+
: [],
|
|
301
|
+
),
|
|
302
|
+
]
|
|
303
|
+
return included
|
|
304
|
+
.flatMap(walk)
|
|
305
|
+
.filter((file) => !within(file, excluded))
|
|
306
|
+
.sort()
|
|
307
|
+
}
|
package/src/swift-package.ts
CHANGED
|
@@ -108,145 +108,12 @@ export type SwiftTargetDependency =
|
|
|
108
108
|
| { kind: 'target'; name: string }
|
|
109
109
|
| { kind: 'product'; name: string; package: string }
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
/** library product name to the targets it vends. */
|
|
114
|
-
products: Map<string, string[]>
|
|
115
|
-
/** every target, binary ones included, to its dependencies on iOS. */
|
|
116
|
-
dependencies: Map<string, SwiftTargetDependency[]>
|
|
117
|
-
binaryTargets: Set<string>
|
|
118
|
-
/** `.systemLibrary` targets: c modules the system provides. */
|
|
119
|
-
systemLibraries: Set<string>
|
|
120
|
-
/** `.package(url:)` dependencies, by the name a `.product(package:)` uses. */
|
|
121
|
-
packageURLs: Map<string, string>
|
|
122
|
-
/** `.package(path:)` dependencies, as written. */
|
|
123
|
-
packagePaths: string[]
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const NAME = /\bname\s*:\s*"([^"]+)"/
|
|
127
|
-
|
|
128
|
-
// the elements of the `[...]` following `label:` at a call's top level.
|
|
129
|
-
function listArgument(call: string, label: string): string[] {
|
|
130
|
-
const start = new RegExp(`\\b${label}\\s*:\\s*\\[`).exec(call)
|
|
131
|
-
if (!start) return []
|
|
132
|
-
const items: string[] = []
|
|
133
|
-
let depth = 0
|
|
134
|
-
let inString = false
|
|
135
|
-
let item = ''
|
|
136
|
-
for (let i = start.index + start[0].length; i < call.length; i++) {
|
|
137
|
-
const ch = call[i]!
|
|
138
|
-
if (inString) {
|
|
139
|
-
item += ch
|
|
140
|
-
if (ch === '"' && call[i - 1] !== '\\') inString = false
|
|
141
|
-
continue
|
|
142
|
-
}
|
|
143
|
-
if (ch === '"') inString = true
|
|
144
|
-
else if (ch === '(' || ch === '[') depth++
|
|
145
|
-
else if (ch === ')' || ch === ']') {
|
|
146
|
-
if (depth === 0) break
|
|
147
|
-
depth--
|
|
148
|
-
} else if (ch === ',' && depth === 0) {
|
|
149
|
-
items.push(item.trim())
|
|
150
|
-
item = ''
|
|
151
|
-
continue
|
|
152
|
-
}
|
|
153
|
-
item += ch
|
|
154
|
-
}
|
|
155
|
-
if (item.trim()) items.push(item.trim())
|
|
156
|
-
return items
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// swiftpm names a package by its explicit `name:`, else its url's last path
|
|
160
|
-
// component without `.git`; `.product(package:)` may use either spelling.
|
|
111
|
+
// swiftpm's identity for a remote package: its url's last path component
|
|
112
|
+
// without `.git`, lowercased.
|
|
161
113
|
export function swiftPackageIdentity(url: string): string {
|
|
162
114
|
return (url.split('/').pop() ?? url).replace(/\.git$/, '').toLowerCase()
|
|
163
115
|
}
|
|
164
116
|
|
|
165
|
-
/** the products, target dependencies and package urls a manifest declares. */
|
|
166
|
-
export function swiftManifestGraph(manifest: string): SwiftManifestGraph {
|
|
167
|
-
const graph: SwiftManifestGraph = {
|
|
168
|
-
products: new Map(),
|
|
169
|
-
dependencies: new Map(),
|
|
170
|
-
binaryTargets: new Set(),
|
|
171
|
-
systemLibraries: new Set(),
|
|
172
|
-
packageURLs: new Map(),
|
|
173
|
-
packagePaths: [],
|
|
174
|
-
}
|
|
175
|
-
for (const { kind, flat, call } of manifestCalls(manifest, [
|
|
176
|
-
'library',
|
|
177
|
-
'executableTarget',
|
|
178
|
-
'target',
|
|
179
|
-
'binaryTarget',
|
|
180
|
-
'systemLibrary',
|
|
181
|
-
'package',
|
|
182
|
-
])) {
|
|
183
|
-
if (kind === 'package') {
|
|
184
|
-
const local = /\bpath\s*:\s*"([^"]+)"/.exec(flat)?.[1]
|
|
185
|
-
if (local) graph.packagePaths.push(local)
|
|
186
|
-
const url = /\burl\s*:\s*"([^"]+)"/.exec(flat)?.[1]
|
|
187
|
-
if (!url) continue
|
|
188
|
-
graph.packageURLs.set(swiftPackageIdentity(url), url)
|
|
189
|
-
const name = NAME.exec(flat)?.[1]
|
|
190
|
-
if (name) graph.packageURLs.set(name.toLowerCase(), url)
|
|
191
|
-
continue
|
|
192
|
-
}
|
|
193
|
-
const name = NAME.exec(flat)?.[1]
|
|
194
|
-
if (!name) continue
|
|
195
|
-
if (kind === 'library') {
|
|
196
|
-
graph.products.set(
|
|
197
|
-
name,
|
|
198
|
-
listArgument(call, 'targets').flatMap(
|
|
199
|
-
(item) => /^"([^"]+)"$/.exec(item)?.[1] ?? [],
|
|
200
|
-
),
|
|
201
|
-
)
|
|
202
|
-
continue
|
|
203
|
-
}
|
|
204
|
-
if (kind === 'binaryTarget') graph.binaryTargets.add(name)
|
|
205
|
-
if (kind === 'systemLibrary') graph.systemLibraries.add(name)
|
|
206
|
-
const dependencies: SwiftTargetDependency[] = []
|
|
207
|
-
for (const item of listArgument(call, 'dependencies')) {
|
|
208
|
-
// a dependency conditioned to other platforms never links on iOS
|
|
209
|
-
const platforms = /condition\s*:\s*\.when\(\s*platforms\s*:\s*\[([^\]]*)\]/.exec(
|
|
210
|
-
item,
|
|
211
|
-
)?.[1]
|
|
212
|
-
if (platforms !== undefined && !/\.iOS\b/.test(platforms)) continue
|
|
213
|
-
// a trait-gated dependency is opt-in; default traits are swift code a
|
|
214
|
-
// scanner cannot evaluate, and the gated ones are optional backends
|
|
215
|
-
if (/condition\s*:\s*\.when\([^)]*\btraits\s*:/.test(item)) continue
|
|
216
|
-
const plain = /^"([^"]+)"$/.exec(item)?.[1]
|
|
217
|
-
const product =
|
|
218
|
-
/^\.product(?:Item)?\(\s*name\s*:\s*"([^"]+)"\s*,\s*package\s*:\s*"([^"]+)"/.exec(
|
|
219
|
-
item,
|
|
220
|
-
)
|
|
221
|
-
const target = /^\.(?:target|byName)(?:Item)?\(\s*name\s*:\s*"([^"]+)"/.exec(
|
|
222
|
-
item,
|
|
223
|
-
)?.[1]
|
|
224
|
-
if (plain) dependencies.push({ kind: 'target', name: plain })
|
|
225
|
-
else if (product)
|
|
226
|
-
dependencies.push({
|
|
227
|
-
kind: 'product',
|
|
228
|
-
name: product[1]!,
|
|
229
|
-
package: product[2]!.toLowerCase(),
|
|
230
|
-
})
|
|
231
|
-
else if (target) dependencies.push({ kind: 'target', name: target })
|
|
232
|
-
}
|
|
233
|
-
graph.dependencies.set(name, dependencies)
|
|
234
|
-
}
|
|
235
|
-
// a bare name that is no target here is swiftpm's by-name product: the
|
|
236
|
-
// product of that name in the dependency package of the same name
|
|
237
|
-
for (const dependencies of graph.dependencies.values()) {
|
|
238
|
-
for (const [index, dependency] of dependencies.entries()) {
|
|
239
|
-
if (dependency.kind === 'target' && !graph.dependencies.has(dependency.name))
|
|
240
|
-
dependencies[index] = {
|
|
241
|
-
kind: 'product',
|
|
242
|
-
name: dependency.name,
|
|
243
|
-
package: dependency.name.toLowerCase(),
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return graph
|
|
248
|
-
}
|
|
249
|
-
|
|
250
117
|
/**
|
|
251
118
|
* the library and executable targets a sent root manifest declares, in order.
|
|
252
119
|
*
|