peachsim 0.1.758 → 0.1.760
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 +1316 -863
- 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 +2 -4
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +509 -336
- 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 +480 -307
- 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 +1637 -1173
- package/dist-lib/swift-compile.cjs +1 -1
- package/dist-lib/swift-compile.mjs +1 -1
- 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 +1013 -558
- package/dist-lib/vite.cjs +2 -4
- package/package.json +1 -1
- package/src/host/replacement-module-handler.ts +2 -1
- package/src/native-seam-manifest.ts +8 -0
- package/src/swift-host.ts +68 -66
- 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-json-project.ts +450 -0
- package/src/xcode-project.ts +112 -92
- package/src/swift-remote-packages.ts +0 -255
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
|
*
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
// the swift packages an app links, local and remote, compiled from source.
|
|
2
|
+
// each linked product resolves through swiftpm's own reading of its package
|
|
3
|
+
// (swift-package-manifest.ts) to the source targets that build it; remote
|
|
4
|
+
// packages are fetched at the revision the app's Package.resolved pins, into
|
|
5
|
+
// .build/peach/checkouts under the app's root. peach compiles swift source
|
|
6
|
+
// only, so a product reaching a binary or c-family target stays missing,
|
|
7
|
+
// with the reason, and so does every module such a package declares.
|
|
8
|
+
|
|
9
|
+
import { execFileSync } from 'node:child_process'
|
|
10
|
+
import fs from 'node:fs'
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
import {
|
|
13
|
+
swiftImplicitResourcePaths,
|
|
14
|
+
swiftPackageIdentity,
|
|
15
|
+
type SwiftPackageTarget,
|
|
16
|
+
} from './swift-package'
|
|
17
|
+
import {
|
|
18
|
+
swiftPackageManifest,
|
|
19
|
+
swiftTargetFiles,
|
|
20
|
+
type SwiftPackageManifest,
|
|
21
|
+
} from './swift-package-manifest'
|
|
22
|
+
|
|
23
|
+
/** where a linked product comes from, as the project names it. */
|
|
24
|
+
export type SwiftPackageSource =
|
|
25
|
+
| { kind: 'local'; dir: string }
|
|
26
|
+
| { kind: 'remote'; url: string }
|
|
27
|
+
/** a product xcode finds by name among the local packages the workspace references. */
|
|
28
|
+
| { kind: 'unnamed' }
|
|
29
|
+
|
|
30
|
+
export interface SwiftLinkedProduct {
|
|
31
|
+
product: string
|
|
32
|
+
source: SwiftPackageSource
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** a source target that compiles, its directory and files absolute. */
|
|
36
|
+
export interface SwiftPackageSourceTarget extends SwiftPackageTarget {
|
|
37
|
+
dir: string
|
|
38
|
+
files: string[]
|
|
39
|
+
/** the package directory, so a manifest edit reaches the compile. */
|
|
40
|
+
packageDir: string
|
|
41
|
+
remote: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** why a product or module does not compile, and where it comes from. */
|
|
45
|
+
export interface SwiftPackageGap {
|
|
46
|
+
source: string
|
|
47
|
+
reason: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SwiftPackages {
|
|
51
|
+
targets: SwiftPackageSourceTarget[]
|
|
52
|
+
/** linked products peach cannot compile. */
|
|
53
|
+
unavailable: Map<string, SwiftPackageGap>
|
|
54
|
+
/** every module a reached package declares that does not compile. */
|
|
55
|
+
modules: Map<string, SwiftPackageGap>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** where checkouts live, relative to the app's root. */
|
|
59
|
+
export const REMOTE_CHECKOUTS = path.join('.build', 'peach', 'checkouts')
|
|
60
|
+
|
|
61
|
+
// sources the swift compile cannot build: c, c++, objective-c and assembly.
|
|
62
|
+
const C_FAMILY = /\.(c|cc|cpp|cxx|m|mm|s|S)$/
|
|
63
|
+
|
|
64
|
+
interface Pin {
|
|
65
|
+
location: string
|
|
66
|
+
revision: string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function readPins(resolved: string): Map<string, Pin> {
|
|
70
|
+
const data: unknown = JSON.parse(fs.readFileSync(resolved, 'utf8'))
|
|
71
|
+
const pins =
|
|
72
|
+
data && typeof data === 'object' && 'pins' in data && Array.isArray(data.pins)
|
|
73
|
+
? data.pins
|
|
74
|
+
: null
|
|
75
|
+
if (!pins)
|
|
76
|
+
throw new Error(`${resolved} has no pins; resolve packages in a current Xcode`)
|
|
77
|
+
const out = new Map<string, Pin>()
|
|
78
|
+
for (const pin of pins) {
|
|
79
|
+
const identity = pin?.identity
|
|
80
|
+
const location = pin?.location
|
|
81
|
+
const revision = pin?.state?.revision
|
|
82
|
+
if (
|
|
83
|
+
typeof identity === 'string' &&
|
|
84
|
+
typeof location === 'string' &&
|
|
85
|
+
typeof revision === 'string'
|
|
86
|
+
)
|
|
87
|
+
out.set(identity, { location, revision })
|
|
88
|
+
}
|
|
89
|
+
return out
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const verified = new Set<string>()
|
|
93
|
+
|
|
94
|
+
// a shallow checkout of exactly the pinned revision, reused while HEAD is it.
|
|
95
|
+
function checkout(checkouts: string, identity: string, pin: Pin): string {
|
|
96
|
+
const dir = path.join(checkouts, identity)
|
|
97
|
+
const key = `${dir}\0${pin.revision}`
|
|
98
|
+
if (verified.has(key)) return dir
|
|
99
|
+
const git = (...args: string[]) =>
|
|
100
|
+
execFileSync('git', ['-C', dir, ...args], {
|
|
101
|
+
encoding: 'utf8',
|
|
102
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
103
|
+
}).trim()
|
|
104
|
+
const current = fs.existsSync(path.join(dir, '.git')) ? git('rev-parse', 'HEAD') : ''
|
|
105
|
+
if (current !== pin.revision) {
|
|
106
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
107
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
108
|
+
try {
|
|
109
|
+
git('init', '-q')
|
|
110
|
+
git('fetch', '-q', '--depth', '1', pin.location, pin.revision)
|
|
111
|
+
git('checkout', '-q', 'FETCH_HEAD')
|
|
112
|
+
} catch (error) {
|
|
113
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
114
|
+
const stderr =
|
|
115
|
+
error instanceof Error && 'stderr' in error ? String(error.stderr).trim() : ''
|
|
116
|
+
throw new Error(
|
|
117
|
+
`could not fetch ${pin.location} at ${pin.revision}${stderr ? `: ${stderr}` : ''}`,
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
verified.add(key)
|
|
122
|
+
return dir
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface LoadedPackage {
|
|
126
|
+
/** the url, or the local directory. */
|
|
127
|
+
source: string
|
|
128
|
+
remote: boolean
|
|
129
|
+
manifest: SwiftPackageManifest
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* resolves `products` to the source targets that build them. products named
|
|
134
|
+
* in `provided` are peach modules and link as those instead. without
|
|
135
|
+
* `provided` (a hosted compile has no local module list) remote products
|
|
136
|
+
* stay unresolved and only local packages compile.
|
|
137
|
+
*/
|
|
138
|
+
export function resolveSwiftPackages(options: {
|
|
139
|
+
rootDir: string
|
|
140
|
+
/** the Package.resolved pinning remote revisions, when the app has one. */
|
|
141
|
+
resolved: string | null
|
|
142
|
+
products: readonly SwiftLinkedProduct[]
|
|
143
|
+
/** local package directories the workspace or a project references. */
|
|
144
|
+
localDirs: readonly string[]
|
|
145
|
+
provided: ReadonlySet<string> | null
|
|
146
|
+
}): SwiftPackages {
|
|
147
|
+
const { rootDir, resolved, products, localDirs } = options
|
|
148
|
+
const provided = options.provided ?? new Set<string>()
|
|
149
|
+
const result: SwiftPackages = {
|
|
150
|
+
targets: [],
|
|
151
|
+
unavailable: new Map(),
|
|
152
|
+
modules: new Map(),
|
|
153
|
+
}
|
|
154
|
+
const pins = resolved ? readPins(resolved) : null
|
|
155
|
+
const checkouts = path.join(rootDir, REMOTE_CHECKOUTS)
|
|
156
|
+
|
|
157
|
+
const packages = new Map<string, LoadedPackage | string>()
|
|
158
|
+
// a package by local directory or remote url, or why it cannot load
|
|
159
|
+
const load = (source: SwiftPackageSource & { kind: 'local' | 'remote' }) => {
|
|
160
|
+
const key = source.kind === 'local' ? path.resolve(source.dir) : source.url
|
|
161
|
+
const cached = packages.get(key)
|
|
162
|
+
if (cached !== undefined) return cached
|
|
163
|
+
let loaded: LoadedPackage | string
|
|
164
|
+
if (source.kind === 'local') {
|
|
165
|
+
loaded = { source: key, remote: false, manifest: swiftPackageManifest(key) }
|
|
166
|
+
} else {
|
|
167
|
+
const identity = swiftPackageIdentity(source.url)
|
|
168
|
+
const pin = pins?.get(identity)
|
|
169
|
+
if (!pin) {
|
|
170
|
+
loaded = pins
|
|
171
|
+
? `package ${identity} is not pinned in Package.resolved`
|
|
172
|
+
: 'no Package.resolved pins it; resolve packages in Xcode once'
|
|
173
|
+
} else {
|
|
174
|
+
fs.mkdirSync(checkouts, { recursive: true })
|
|
175
|
+
// fetched sources never show up as changes in the app's repository
|
|
176
|
+
fs.writeFileSync(path.join(path.dirname(checkouts), '.gitignore'), '*\n')
|
|
177
|
+
loaded = {
|
|
178
|
+
source: source.url,
|
|
179
|
+
remote: true,
|
|
180
|
+
manifest: swiftPackageManifest(checkout(checkouts, identity, pin)),
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
packages.set(key, loaded)
|
|
185
|
+
return loaded
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const targets = new Map<string, SwiftPackageSourceTarget>()
|
|
189
|
+
// why each target of each package cannot compile, or null once it can
|
|
190
|
+
const targetOutcomes = new Map<string, string | null>()
|
|
191
|
+
const resolveTarget = (pkg: LoadedPackage, name: string): string | null => {
|
|
192
|
+
const key = `${pkg.manifest.dir}\0${name}`
|
|
193
|
+
if (targetOutcomes.has(key)) return targetOutcomes.get(key)!
|
|
194
|
+
// a dependency cycle resolves as compiling; swiftpm rejects real cycles
|
|
195
|
+
targetOutcomes.set(key, null)
|
|
196
|
+
const outcome = ((): string | null => {
|
|
197
|
+
if (provided.has(name)) return null
|
|
198
|
+
const target = pkg.manifest.targets.get(name)
|
|
199
|
+
if (!target) return `${path.basename(pkg.manifest.dir)} declares no target ${name}`
|
|
200
|
+
if (target.type === 'binary') return `${name} is a binary framework`
|
|
201
|
+
if (target.type === 'system') return `${name} is a system C library`
|
|
202
|
+
if (target.type !== 'regular') return `${name} is a ${target.type} target`
|
|
203
|
+
const files = swiftTargetFiles(pkg.manifest, target)
|
|
204
|
+
if (files.some((file) => C_FAMILY.test(file)))
|
|
205
|
+
return `${name} is a C or Objective-C target`
|
|
206
|
+
for (const dependency of target.dependencies) {
|
|
207
|
+
if (dependency.kind === 'target') {
|
|
208
|
+
const nested = resolveTarget(pkg, dependency.name)
|
|
209
|
+
if (nested) return nested
|
|
210
|
+
continue
|
|
211
|
+
}
|
|
212
|
+
const nested = resolveDependencyProduct(pkg, dependency.package, dependency.name)
|
|
213
|
+
if (nested) return `${dependency.name}: ${nested}`
|
|
214
|
+
}
|
|
215
|
+
const relative = files.map((file) => path.relative(target.dir, file))
|
|
216
|
+
targets.set(`${pkg.manifest.dir}\0${name}`, {
|
|
217
|
+
name,
|
|
218
|
+
path: '',
|
|
219
|
+
dir: target.dir,
|
|
220
|
+
files,
|
|
221
|
+
packageDir: pkg.manifest.dir,
|
|
222
|
+
remote: pkg.remote,
|
|
223
|
+
executable: false,
|
|
224
|
+
languageMode: target.languageMode,
|
|
225
|
+
mainActorIsolation: target.mainActorIsolation,
|
|
226
|
+
resources:
|
|
227
|
+
target.declaresResources || swiftImplicitResourcePaths(relative).length > 0,
|
|
228
|
+
})
|
|
229
|
+
return null
|
|
230
|
+
})()
|
|
231
|
+
targetOutcomes.set(key, outcome)
|
|
232
|
+
return outcome
|
|
233
|
+
}
|
|
234
|
+
const resolveProduct = (pkg: LoadedPackage, product: string): string | null => {
|
|
235
|
+
if (provided.has(product)) return null
|
|
236
|
+
const roots = pkg.manifest.products.get(product)
|
|
237
|
+
if (!roots) return `${path.basename(pkg.manifest.dir)} has no library ${product}`
|
|
238
|
+
for (const name of roots) {
|
|
239
|
+
const reason = resolveTarget(pkg, name)
|
|
240
|
+
if (reason) return reason
|
|
241
|
+
}
|
|
242
|
+
return null
|
|
243
|
+
}
|
|
244
|
+
// a `.product(package:)` names a dependency by identity or by its `name:`
|
|
245
|
+
const resolveDependencyProduct = (
|
|
246
|
+
pkg: LoadedPackage,
|
|
247
|
+
packageName: string,
|
|
248
|
+
product: string,
|
|
249
|
+
): string | null => {
|
|
250
|
+
if (provided.has(product)) return null
|
|
251
|
+
const dependency = pkg.manifest.packages.get(packageName)
|
|
252
|
+
if (!dependency)
|
|
253
|
+
return `${path.basename(pkg.manifest.dir)} names no package ${packageName}`
|
|
254
|
+
if ('dir' in dependency) {
|
|
255
|
+
const loaded = load({ kind: 'local', dir: dependency.dir })
|
|
256
|
+
return typeof loaded === 'string' ? loaded : resolveProduct(loaded, product)
|
|
257
|
+
}
|
|
258
|
+
if (!options.provided) return null
|
|
259
|
+
const loaded = load({ kind: 'remote', url: dependency.url })
|
|
260
|
+
return typeof loaded === 'string' ? loaded : resolveProduct(loaded, product)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const unnamed = () =>
|
|
264
|
+
localDirs
|
|
265
|
+
.map((dir) => load({ kind: 'local', dir }))
|
|
266
|
+
.filter((pkg) => typeof pkg !== 'string')
|
|
267
|
+
for (const { product, source } of products) {
|
|
268
|
+
if (provided.has(product)) continue
|
|
269
|
+
if (source.kind === 'remote' && !options.provided) continue
|
|
270
|
+
const pkg =
|
|
271
|
+
source.kind === 'unnamed'
|
|
272
|
+
? unnamed().find((candidate) => candidate.manifest.products.has(product))
|
|
273
|
+
: load(source)
|
|
274
|
+
const reason =
|
|
275
|
+
pkg === undefined
|
|
276
|
+
? 'no package the workspace references vends it'
|
|
277
|
+
: typeof pkg === 'string'
|
|
278
|
+
? pkg
|
|
279
|
+
: resolveProduct(pkg, product)
|
|
280
|
+
if (reason)
|
|
281
|
+
result.unavailable.set(product, {
|
|
282
|
+
source:
|
|
283
|
+
source.kind === 'remote'
|
|
284
|
+
? source.url
|
|
285
|
+
: typeof pkg === 'object'
|
|
286
|
+
? pkg.source
|
|
287
|
+
: source.kind === 'local'
|
|
288
|
+
? source.dir
|
|
289
|
+
: 'the workspace',
|
|
290
|
+
reason,
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// every module a reached package declares, so an import of one that does
|
|
295
|
+
// not compile says why even when the app links it through another product
|
|
296
|
+
for (const pkg of packages.values()) {
|
|
297
|
+
if (typeof pkg === 'string') continue
|
|
298
|
+
for (const [name, target] of pkg.manifest.targets) {
|
|
299
|
+
if (target.type === 'test' || target.type === 'plugin' || target.type === 'macro')
|
|
300
|
+
continue
|
|
301
|
+
if (target.type === 'executable') continue
|
|
302
|
+
const reason = resolveTarget(pkg, name)
|
|
303
|
+
if (reason && !result.modules.has(name))
|
|
304
|
+
result.modules.set(name, { source: pkg.source, reason })
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
// only targets a linked product reaches compile; the module sweep above
|
|
308
|
+
// resolved the rest to learn their reasons
|
|
309
|
+
const reached = new Set<string>()
|
|
310
|
+
const reach = (pkg: LoadedPackage, name: string) => {
|
|
311
|
+
const key = `${pkg.manifest.dir}\0${name}`
|
|
312
|
+
if (reached.has(key) || !targets.has(key)) return
|
|
313
|
+
reached.add(key)
|
|
314
|
+
for (const dependency of pkg.manifest.targets.get(name)?.dependencies ?? []) {
|
|
315
|
+
if (dependency.kind === 'target') reach(pkg, dependency.name)
|
|
316
|
+
else {
|
|
317
|
+
const source = pkg.manifest.packages.get(dependency.package)
|
|
318
|
+
const nested =
|
|
319
|
+
source &&
|
|
320
|
+
('dir' in source
|
|
321
|
+
? packages.get(path.resolve(source.dir))
|
|
322
|
+
: packages.get(source.url))
|
|
323
|
+
if (nested && typeof nested !== 'string')
|
|
324
|
+
for (const root of nested.manifest.products.get(dependency.name) ?? [])
|
|
325
|
+
reach(nested, root)
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
for (const { product, source } of products) {
|
|
330
|
+
const pkg =
|
|
331
|
+
source.kind === 'unnamed'
|
|
332
|
+
? unnamed().find((candidate) => candidate.manifest.products.has(product))
|
|
333
|
+
: packages.get(source.kind === 'local' ? path.resolve(source.dir) : source.url)
|
|
334
|
+
if (!pkg || typeof pkg === 'string' || result.unavailable.has(product)) continue
|
|
335
|
+
for (const root of pkg.manifest.products.get(product) ?? []) reach(pkg, root)
|
|
336
|
+
}
|
|
337
|
+
result.targets = [...targets.entries()]
|
|
338
|
+
.filter(([key]) => reached.has(key))
|
|
339
|
+
.map(([, target]) => target)
|
|
340
|
+
return result
|
|
341
|
+
}
|