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/xcode-project.ts
CHANGED
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
// swift sources and resources that are members of the target, the local
|
|
3
3
|
// swift packages its products come from, the remote package products it links,
|
|
4
4
|
// and the build settings that change how its swift compiles. never runs xcode
|
|
5
|
-
// or evaluates a build phase; project
|
|
5
|
+
// or evaluates a build phase; the project file is data: project.pbxproj, or
|
|
6
|
+
// xcode 27.2's json project.xcproj, which xcode-json-project.ts reads into
|
|
7
|
+
// the same object table.
|
|
6
8
|
|
|
7
9
|
import fs from 'node:fs'
|
|
8
10
|
import path from 'node:path'
|
|
9
11
|
import plist from 'plist'
|
|
10
|
-
import {
|
|
12
|
+
import { readXcodeJsonProject } from './xcode-json-project'
|
|
13
|
+
import type { SwiftLinkedProduct } from './swift-packages'
|
|
11
14
|
|
|
12
|
-
type PlistValue = string | PlistValue[] | { [key: string]: PlistValue }
|
|
13
|
-
type PlistDict = { [key: string]: PlistValue }
|
|
15
|
+
export type PlistValue = string | PlistValue[] | { [key: string]: PlistValue }
|
|
16
|
+
export type PlistDict = { [key: string]: PlistValue }
|
|
14
17
|
|
|
15
18
|
// project.pbxproj is an old-style (openstep) property list: dictionaries,
|
|
16
19
|
// arrays and strings, with c comments. node's plist package reads only xml.
|
|
@@ -113,12 +116,6 @@ const list = (value: PlistValue | undefined): string[] =>
|
|
|
113
116
|
? value.filter((item): item is string => typeof item === 'string')
|
|
114
117
|
: []
|
|
115
118
|
|
|
116
|
-
/** a remote package product the target links, as the project names it. */
|
|
117
|
-
export interface XcodeRemoteProduct {
|
|
118
|
-
product: string
|
|
119
|
-
repositoryURL: string
|
|
120
|
-
}
|
|
121
|
-
|
|
122
119
|
/** a target whose swift compiles as one module: the app, or a framework it builds. */
|
|
123
120
|
export interface XcodeModuleTarget {
|
|
124
121
|
name: string
|
|
@@ -139,8 +136,8 @@ export interface XcodeAppTarget extends XcodeModuleTarget {
|
|
|
139
136
|
* local package the app builds from: every compile path is relative to it.
|
|
140
137
|
*/
|
|
141
138
|
rootDir: string
|
|
142
|
-
/** every project.pbxproj the app's build reads. */
|
|
143
|
-
|
|
139
|
+
/** every project file (project.pbxproj or project.xcproj) the app's build reads. */
|
|
140
|
+
projectFiles: string[]
|
|
144
141
|
/** the target's processed launch plist, including generated build settings. */
|
|
145
142
|
infoPlist: string
|
|
146
143
|
infoPlistFile: string | null
|
|
@@ -152,13 +149,14 @@ export interface XcodeAppTarget extends XcodeModuleTarget {
|
|
|
152
149
|
* products directory, so every one is importable from every other.
|
|
153
150
|
*/
|
|
154
151
|
frameworks: XcodeModuleTarget[]
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
/** package products the app and its frameworks link, with the package each names. */
|
|
153
|
+
linkedProducts: SwiftLinkedProduct[]
|
|
154
|
+
/** local package directories the workspace or a project references. */
|
|
155
|
+
localPackageDirs: string[]
|
|
156
|
+
/** prebuilt frameworks and xcframeworks the projects vendor and link, by name. */
|
|
157
|
+
binaryFrameworks: string[]
|
|
158
158
|
/** the Package.resolved pinning the remote packages' revisions, when resolved. */
|
|
159
159
|
packageResolved: string | null
|
|
160
|
-
/** linked product names no local or remote package reference supplies. */
|
|
161
|
-
unresolvedProducts: string[]
|
|
162
160
|
/** every application target in the workspace, for a chooser. */
|
|
163
161
|
appTargets: string[]
|
|
164
162
|
}
|
|
@@ -342,7 +340,8 @@ export function findXcodeProject(input: string): string | null {
|
|
|
342
340
|
|
|
343
341
|
interface LoadedProject {
|
|
344
342
|
xcodeproj: string
|
|
345
|
-
pbxproj
|
|
343
|
+
/** project.pbxproj, or the json project.xcproj. */
|
|
344
|
+
projectFile: string
|
|
346
345
|
objects: PlistDict
|
|
347
346
|
project: PlistDict
|
|
348
347
|
/** the directory holding the .xcodeproj: every relative path starts here. */
|
|
@@ -353,15 +352,28 @@ interface LoadedProject {
|
|
|
353
352
|
|
|
354
353
|
const loaded = new Map<string, { mtimeMs: number; project: LoadedProject }>()
|
|
355
354
|
|
|
355
|
+
// a project bundle holds one project file, in either format.
|
|
356
|
+
function xcodeProjectFile(xcodeproj: string): string | null {
|
|
357
|
+
for (const name of ['project.pbxproj', 'project.xcproj']) {
|
|
358
|
+
const file = path.join(xcodeproj, name)
|
|
359
|
+
if (fs.existsSync(file)) return file
|
|
360
|
+
}
|
|
361
|
+
return null
|
|
362
|
+
}
|
|
363
|
+
|
|
356
364
|
function loadProject(xcodeproj: string): LoadedProject {
|
|
357
|
-
const
|
|
358
|
-
if (!
|
|
359
|
-
|
|
360
|
-
const
|
|
365
|
+
const projectFile = xcodeProjectFile(xcodeproj)
|
|
366
|
+
if (!projectFile)
|
|
367
|
+
throw new Error(`${xcodeproj} has no project.pbxproj or project.xcproj`)
|
|
368
|
+
const mtimeMs = fs.statSync(projectFile).mtimeMs
|
|
369
|
+
const cached = loaded.get(projectFile)
|
|
361
370
|
if (cached?.mtimeMs === mtimeMs) return cached.project
|
|
362
|
-
const
|
|
371
|
+
const source = fs.readFileSync(projectFile, 'utf8')
|
|
372
|
+
const root = projectFile.endsWith('.xcproj')
|
|
373
|
+
? readXcodeJsonProject(xcodeproj, source)
|
|
374
|
+
: parseOpenStepPlist(source)
|
|
363
375
|
if (!isDict(root) || !isDict(root.objects)) {
|
|
364
|
-
throw new Error(`${
|
|
376
|
+
throw new Error(`${projectFile} has no objects table`)
|
|
365
377
|
}
|
|
366
378
|
const objects = root.objects
|
|
367
379
|
const object = (id: string | undefined): PlistDict | undefined => {
|
|
@@ -370,7 +382,7 @@ function loadProject(xcodeproj: string): LoadedProject {
|
|
|
370
382
|
}
|
|
371
383
|
const project = object(str(root.rootObject))
|
|
372
384
|
if (!project || project.isa !== 'PBXProject') {
|
|
373
|
-
throw new Error(`${
|
|
385
|
+
throw new Error(`${projectFile} has no PBXProject root`)
|
|
374
386
|
}
|
|
375
387
|
// canonical, so every member path agrees with the host's realpath checks
|
|
376
388
|
const projectDir = fs.realpathSync(
|
|
@@ -403,8 +415,16 @@ function loadProject(xcodeproj: string): LoadedProject {
|
|
|
403
415
|
resolvedPaths.set(id, result)
|
|
404
416
|
return result
|
|
405
417
|
}
|
|
406
|
-
const result = {
|
|
407
|
-
|
|
418
|
+
const result = {
|
|
419
|
+
xcodeproj,
|
|
420
|
+
projectFile,
|
|
421
|
+
objects,
|
|
422
|
+
project,
|
|
423
|
+
projectDir,
|
|
424
|
+
object,
|
|
425
|
+
resolvePath,
|
|
426
|
+
}
|
|
427
|
+
loaded.set(projectFile, { mtimeMs, project: result })
|
|
408
428
|
return result
|
|
409
429
|
}
|
|
410
430
|
|
|
@@ -630,7 +650,7 @@ function workspaceProjects(xcodeprojOrWorkspace: string): {
|
|
|
630
650
|
const addProject = (xcodeproj: string) => {
|
|
631
651
|
const key = path.resolve(xcodeproj)
|
|
632
652
|
if (projectAt.has(key) || key.split(path.sep).includes('Pods')) return
|
|
633
|
-
if (!
|
|
653
|
+
if (!xcodeProjectFile(key)) return
|
|
634
654
|
const project = loadProject(key)
|
|
635
655
|
projectAt.set(key, project)
|
|
636
656
|
projects.push(project)
|
|
@@ -651,11 +671,19 @@ function workspaceProjects(xcodeprojOrWorkspace: string): {
|
|
|
651
671
|
return { listed, projects, projectAt }
|
|
652
672
|
}
|
|
653
673
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
674
|
+
// one ref per target, so a target reached by a dependency and a link is visited once
|
|
675
|
+
const targetRefs = new WeakMap<LoadedProject, TargetRef[]>()
|
|
676
|
+
function nativeTargets(project: LoadedProject): TargetRef[] {
|
|
677
|
+
let refs = targetRefs.get(project)
|
|
678
|
+
if (!refs) {
|
|
679
|
+
refs = list(project.project.targets).flatMap((id) => {
|
|
680
|
+
const target = project.object(id)
|
|
681
|
+
return target?.isa === 'PBXNativeTarget' ? [{ project, id, target }] : []
|
|
682
|
+
})
|
|
683
|
+
targetRefs.set(project, refs)
|
|
684
|
+
}
|
|
685
|
+
return refs
|
|
686
|
+
}
|
|
659
687
|
|
|
660
688
|
/** the names of every application target a workspace or project builds. */
|
|
661
689
|
export function listXcodeAppTargets(xcodeprojOrWorkspace: string): string[] {
|
|
@@ -855,25 +883,8 @@ export function readXcodeAppTarget(
|
|
|
855
883
|
}),
|
|
856
884
|
),
|
|
857
885
|
]
|
|
858
|
-
const
|
|
859
|
-
const
|
|
860
|
-
const cached = graphs.get(dir)
|
|
861
|
-
if (cached) return cached
|
|
862
|
-
const graph = swiftManifestGraph(
|
|
863
|
-
fs.readFileSync(path.join(dir, 'Package.swift'), 'utf8'),
|
|
864
|
-
)
|
|
865
|
-
graphs.set(dir, graph)
|
|
866
|
-
return graph
|
|
867
|
-
}
|
|
868
|
-
const localProducts = new Map<string, string>()
|
|
869
|
-
for (const dir of localPackageDirs) {
|
|
870
|
-
for (const product of graphOf(dir).products.keys()) {
|
|
871
|
-
if (!localProducts.has(product)) localProducts.set(product, dir)
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
const localPackages = new Set<string>()
|
|
875
|
-
const remoteProducts: XcodeRemoteProduct[] = []
|
|
876
|
-
const unresolvedProducts: string[] = []
|
|
886
|
+
const linkedProducts: SwiftLinkedProduct[] = []
|
|
887
|
+
const binaryFrameworks = new Set<string>()
|
|
877
888
|
for (const { project, target } of order) {
|
|
878
889
|
const productDependencies = [
|
|
879
890
|
...list(target.packageProductDependencies),
|
|
@@ -885,43 +896,47 @@ export function readXcodeAppTarget(
|
|
|
885
896
|
for (const dependencyId of productDependencies) {
|
|
886
897
|
const dependency = project.object(dependencyId)
|
|
887
898
|
const product = str(dependency?.productName)?.replace(/^plugin:/, '')
|
|
888
|
-
if (
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
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
|
-
}
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
// local packages depend on further local packages by path, and on remote
|
|
907
|
-
// products by the package's url.
|
|
908
|
-
const pending = [...localPackages]
|
|
909
|
-
while (pending.length > 0) {
|
|
910
|
-
const dir = pending.pop()!
|
|
911
|
-
const graph = graphOf(dir)
|
|
912
|
-
for (const relative of graph.packagePaths) {
|
|
913
|
-
const next = path.resolve(dir, relative)
|
|
914
|
-
if (localPackages.has(next) || !fs.existsSync(path.join(next, 'Package.swift')))
|
|
899
|
+
if (
|
|
900
|
+
!dependency ||
|
|
901
|
+
!product ||
|
|
902
|
+
linkedProducts.some((entry) => entry.product === product)
|
|
903
|
+
)
|
|
915
904
|
continue
|
|
916
|
-
|
|
917
|
-
|
|
905
|
+
const reference = project.object(str(dependency.package))
|
|
906
|
+
linkedProducts.push({
|
|
907
|
+
product,
|
|
908
|
+
source:
|
|
909
|
+
reference?.isa === 'XCRemoteSwiftPackageReference'
|
|
910
|
+
? { kind: 'remote', url: str(reference.repositoryURL) ?? '' }
|
|
911
|
+
: reference?.isa === 'XCLocalSwiftPackageReference'
|
|
912
|
+
? {
|
|
913
|
+
kind: 'local',
|
|
914
|
+
dir: path.resolve(
|
|
915
|
+
project.projectDir,
|
|
916
|
+
str(reference.relativePath) ?? '',
|
|
917
|
+
),
|
|
918
|
+
}
|
|
919
|
+
: { kind: 'unnamed' },
|
|
920
|
+
})
|
|
918
921
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
922
|
+
// prebuilt frameworks the project vendors, as opposed to built products
|
|
923
|
+
// and the sdk's own
|
|
924
|
+
for (const phaseId of list(target.buildPhases)) {
|
|
925
|
+
const phase = project.object(phaseId)
|
|
926
|
+
if (phase?.isa !== 'PBXFrameworksBuildPhase') continue
|
|
927
|
+
for (const buildFileId of list(phase.files)) {
|
|
928
|
+
const fileId = str(project.object(buildFileId)?.fileRef)
|
|
929
|
+
const file = project.object(fileId)
|
|
930
|
+
const tree = str(file?.sourceTree)
|
|
931
|
+
const name = /([^/]+)\.(xc)?framework$/.exec(str(file?.path) ?? '')?.[1]
|
|
932
|
+
if (file?.isa !== 'PBXFileReference' || !name) continue
|
|
933
|
+
if (
|
|
934
|
+
tree === 'BUILT_PRODUCTS_DIR' ||
|
|
935
|
+
tree === 'SDKROOT' ||
|
|
936
|
+
tree === 'DEVELOPER_DIR'
|
|
937
|
+
)
|
|
938
|
+
continue
|
|
939
|
+
binaryFrameworks.add(name)
|
|
925
940
|
}
|
|
926
941
|
}
|
|
927
942
|
}
|
|
@@ -941,17 +956,22 @@ export function readXcodeAppTarget(
|
|
|
941
956
|
[
|
|
942
957
|
workspace ? path.dirname(workspace) : app.project.projectDir,
|
|
943
958
|
...used.map((project) => project.projectDir),
|
|
944
|
-
...
|
|
959
|
+
...localPackageDirs,
|
|
960
|
+
...linkedProducts.flatMap(({ source }) =>
|
|
961
|
+
source.kind === 'local' && fs.existsSync(source.dir) ? [source.dir] : [],
|
|
962
|
+
),
|
|
945
963
|
].map((dir) => fs.realpathSync(dir)),
|
|
946
964
|
),
|
|
947
|
-
|
|
965
|
+
projectFiles: [...new Set(used.map((project) => project.projectFile))].sort(),
|
|
948
966
|
infoPlist: plist.build(info),
|
|
949
967
|
infoPlistFile,
|
|
950
968
|
frameworks,
|
|
951
|
-
|
|
952
|
-
|
|
969
|
+
linkedProducts,
|
|
970
|
+
localPackageDirs: [
|
|
971
|
+
...new Set(localPackageDirs.map((dir) => fs.realpathSync(dir))),
|
|
972
|
+
].sort(),
|
|
973
|
+
binaryFrameworks: [...binaryFrameworks].sort(),
|
|
953
974
|
packageResolved: fs.existsSync(resolvedFile) ? resolvedFile : null,
|
|
954
|
-
unresolvedProducts,
|
|
955
975
|
appTargets: appTargetNames,
|
|
956
976
|
}
|
|
957
977
|
}
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
// the remote swift packages an app links, compiled from source: each package
|
|
2
|
-
// is fetched at the revision the project's Package.resolved pins, into the
|
|
3
|
-
// project's .build/peach/checkouts, and each linked product resolves to the
|
|
4
|
-
// source targets that build it. peach compiles swift source only, so a
|
|
5
|
-
// product reaching a binary or c-family target stays missing, with the reason.
|
|
6
|
-
|
|
7
|
-
import { execFileSync } from 'node:child_process'
|
|
8
|
-
import fs from 'node:fs'
|
|
9
|
-
import path from 'node:path'
|
|
10
|
-
import {
|
|
11
|
-
swiftManifestGraph,
|
|
12
|
-
swiftManifestTargets,
|
|
13
|
-
swiftPackageIdentity,
|
|
14
|
-
type SwiftManifestGraph,
|
|
15
|
-
type SwiftPackageTarget,
|
|
16
|
-
} from './swift-package'
|
|
17
|
-
|
|
18
|
-
export interface RemoteProduct {
|
|
19
|
-
product: string
|
|
20
|
-
repositoryURL: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** a source target from a remote checkout, its path absolute. */
|
|
24
|
-
export interface RemotePackageTarget extends SwiftPackageTarget {
|
|
25
|
-
dir: string
|
|
26
|
-
/** every file under the target directory. */
|
|
27
|
-
files: string[]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface RemotePackages {
|
|
31
|
-
targets: RemotePackageTarget[]
|
|
32
|
-
/** linked products peach cannot compile, with why. */
|
|
33
|
-
unavailable: Map<string, { repositoryURL: string; reason: string }>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** where checkouts live, relative to the project directory. */
|
|
37
|
-
export const REMOTE_CHECKOUTS = path.join('.build', 'peach', 'checkouts')
|
|
38
|
-
|
|
39
|
-
interface Pin {
|
|
40
|
-
location: string
|
|
41
|
-
revision: string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// sources the swift compile cannot build: c, c++, objective-c and assembly.
|
|
45
|
-
const C_FAMILY = /\.(c|cc|cpp|cxx|m|mm|s|S)$/
|
|
46
|
-
|
|
47
|
-
function readPins(resolved: string): Map<string, Pin> {
|
|
48
|
-
const data: unknown = JSON.parse(fs.readFileSync(resolved, 'utf8'))
|
|
49
|
-
const pins =
|
|
50
|
-
data && typeof data === 'object' && 'pins' in data && Array.isArray(data.pins)
|
|
51
|
-
? data.pins
|
|
52
|
-
: null
|
|
53
|
-
if (!pins)
|
|
54
|
-
throw new Error(`${resolved} has no pins; resolve packages in a current Xcode`)
|
|
55
|
-
const out = new Map<string, Pin>()
|
|
56
|
-
for (const pin of pins) {
|
|
57
|
-
const identity = pin?.identity
|
|
58
|
-
const location = pin?.location
|
|
59
|
-
const revision = pin?.state?.revision
|
|
60
|
-
if (
|
|
61
|
-
typeof identity === 'string' &&
|
|
62
|
-
typeof location === 'string' &&
|
|
63
|
-
typeof revision === 'string'
|
|
64
|
-
)
|
|
65
|
-
out.set(identity, { location, revision })
|
|
66
|
-
}
|
|
67
|
-
return out
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function walk(dir: string): string[] {
|
|
71
|
-
if (!fs.existsSync(dir)) return []
|
|
72
|
-
const out: string[] = []
|
|
73
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
74
|
-
if (entry.name.startsWith('.')) continue
|
|
75
|
-
const full = path.join(dir, entry.name)
|
|
76
|
-
if (entry.isDirectory()) out.push(...walk(full))
|
|
77
|
-
else if (entry.isFile()) out.push(full)
|
|
78
|
-
}
|
|
79
|
-
return out.sort()
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const verified = new Set<string>()
|
|
83
|
-
|
|
84
|
-
// a shallow checkout of exactly the pinned revision, reused while HEAD is it.
|
|
85
|
-
function checkout(checkouts: string, identity: string, pin: Pin): string {
|
|
86
|
-
const dir = path.join(checkouts, identity)
|
|
87
|
-
const key = `${dir}\0${pin.revision}`
|
|
88
|
-
if (verified.has(key)) return dir
|
|
89
|
-
const git = (...args: string[]) =>
|
|
90
|
-
execFileSync('git', ['-C', dir, ...args], {
|
|
91
|
-
encoding: 'utf8',
|
|
92
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
93
|
-
}).trim()
|
|
94
|
-
const current = fs.existsSync(path.join(dir, '.git')) ? git('rev-parse', 'HEAD') : ''
|
|
95
|
-
if (current !== pin.revision) {
|
|
96
|
-
fs.rmSync(dir, { recursive: true, force: true })
|
|
97
|
-
fs.mkdirSync(dir, { recursive: true })
|
|
98
|
-
try {
|
|
99
|
-
git('init', '-q')
|
|
100
|
-
git('fetch', '-q', '--depth', '1', pin.location, pin.revision)
|
|
101
|
-
git('checkout', '-q', 'FETCH_HEAD')
|
|
102
|
-
} catch (error) {
|
|
103
|
-
fs.rmSync(dir, { recursive: true, force: true })
|
|
104
|
-
const stderr =
|
|
105
|
-
error instanceof Error && 'stderr' in error ? String(error.stderr).trim() : ''
|
|
106
|
-
throw new Error(
|
|
107
|
-
`could not fetch ${pin.location} at ${pin.revision}${stderr ? `: ${stderr}` : ''}`,
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
verified.add(key)
|
|
112
|
-
return dir
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* fetches and resolves `products` against the pins in `resolved`. products
|
|
117
|
-
* named in `provided` are peach modules and link as those instead.
|
|
118
|
-
*/
|
|
119
|
-
export function resolveRemotePackages(
|
|
120
|
-
projectDir: string,
|
|
121
|
-
resolved: string | null,
|
|
122
|
-
products: readonly RemoteProduct[],
|
|
123
|
-
provided: ReadonlySet<string>,
|
|
124
|
-
): RemotePackages {
|
|
125
|
-
const result: RemotePackages = { targets: [], unavailable: new Map() }
|
|
126
|
-
const wanted = products.filter((entry) => !provided.has(entry.product))
|
|
127
|
-
if (wanted.length === 0) return result
|
|
128
|
-
if (!resolved) {
|
|
129
|
-
for (const entry of wanted)
|
|
130
|
-
result.unavailable.set(entry.product, {
|
|
131
|
-
repositoryURL: entry.repositoryURL,
|
|
132
|
-
reason: 'no Package.resolved pins it; resolve packages in Xcode once',
|
|
133
|
-
})
|
|
134
|
-
return result
|
|
135
|
-
}
|
|
136
|
-
const pins = readPins(resolved)
|
|
137
|
-
const checkouts = path.join(projectDir, REMOTE_CHECKOUTS)
|
|
138
|
-
fs.mkdirSync(checkouts, { recursive: true })
|
|
139
|
-
// fetched sources never show up as changes in the app's repository
|
|
140
|
-
fs.writeFileSync(path.join(path.dirname(checkouts), '.gitignore'), '*\n')
|
|
141
|
-
|
|
142
|
-
const packages = new Map<
|
|
143
|
-
string,
|
|
144
|
-
{ dir: string; manifest: string; graph: SwiftManifestGraph }
|
|
145
|
-
>()
|
|
146
|
-
const load = (identity: string) => {
|
|
147
|
-
const cached = packages.get(identity)
|
|
148
|
-
if (cached) return cached
|
|
149
|
-
const pin = pins.get(identity)
|
|
150
|
-
if (!pin) return null
|
|
151
|
-
const dir = checkout(checkouts, identity, pin)
|
|
152
|
-
const manifest = fs.readFileSync(path.join(dir, 'Package.swift'), 'utf8')
|
|
153
|
-
const loaded = { dir, manifest, graph: swiftManifestGraph(manifest) }
|
|
154
|
-
packages.set(identity, loaded)
|
|
155
|
-
return loaded
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const targets = new Map<string, RemotePackageTarget>()
|
|
159
|
-
// product key to the reason it cannot compile, or null once it can
|
|
160
|
-
const outcomes = new Map<string, string | null>()
|
|
161
|
-
const resolveProduct = (identity: string, product: string): string | null => {
|
|
162
|
-
const key = `${identity}\0${product}`
|
|
163
|
-
if (outcomes.has(key)) return outcomes.get(key)!
|
|
164
|
-
outcomes.set(key, null)
|
|
165
|
-
const pkg = load(identity)
|
|
166
|
-
if (!pkg) {
|
|
167
|
-
outcomes.set(key, `package ${identity} is not pinned in Package.resolved`)
|
|
168
|
-
return outcomes.get(key)!
|
|
169
|
-
}
|
|
170
|
-
const roots = pkg.graph.products.get(product)
|
|
171
|
-
if (!roots) {
|
|
172
|
-
outcomes.set(key, `package ${identity} has no library ${product}`)
|
|
173
|
-
return outcomes.get(key)!
|
|
174
|
-
}
|
|
175
|
-
const declared = new Map(
|
|
176
|
-
swiftManifestTargets(pkg.manifest).map((target) => [target.name, target]),
|
|
177
|
-
)
|
|
178
|
-
const reached: SwiftPackageTarget[] = []
|
|
179
|
-
const seen = new Set<string>()
|
|
180
|
-
const pending = [...roots]
|
|
181
|
-
let reason: string | null = null
|
|
182
|
-
while (pending.length > 0 && !reason) {
|
|
183
|
-
const name = pending.pop()!
|
|
184
|
-
if (seen.has(name) || provided.has(name)) continue
|
|
185
|
-
seen.add(name)
|
|
186
|
-
if (pkg.graph.binaryTargets.has(name)) {
|
|
187
|
-
reason = `${name} is a binary framework`
|
|
188
|
-
break
|
|
189
|
-
}
|
|
190
|
-
if (pkg.graph.systemLibraries.has(name)) {
|
|
191
|
-
reason = `${name} is a system C library`
|
|
192
|
-
break
|
|
193
|
-
}
|
|
194
|
-
const target = declared.get(name)
|
|
195
|
-
if (!target) {
|
|
196
|
-
reason = `${identity} declares no target ${name}`
|
|
197
|
-
break
|
|
198
|
-
}
|
|
199
|
-
const files = walk(path.join(pkg.dir, target.path))
|
|
200
|
-
if (files.some((file) => C_FAMILY.test(file))) {
|
|
201
|
-
reason = `${name} is a C or Objective-C target`
|
|
202
|
-
break
|
|
203
|
-
}
|
|
204
|
-
reached.push(target)
|
|
205
|
-
for (const dependency of pkg.graph.dependencies.get(name) ?? []) {
|
|
206
|
-
if (dependency.kind === 'target') pending.push(dependency.name)
|
|
207
|
-
else if (!provided.has(dependency.name)) {
|
|
208
|
-
const url = pkg.graph.packageURLs.get(dependency.package)
|
|
209
|
-
const nested = resolveProduct(
|
|
210
|
-
url ? swiftPackageIdentity(url) : dependency.package,
|
|
211
|
-
dependency.name,
|
|
212
|
-
)
|
|
213
|
-
if (nested) reason = `${dependency.name}: ${nested}`
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (reason) {
|
|
218
|
-
outcomes.set(key, reason)
|
|
219
|
-
return reason
|
|
220
|
-
}
|
|
221
|
-
// resources need the files each target holds, relative to its package
|
|
222
|
-
const relative = reached.flatMap((target) =>
|
|
223
|
-
walk(path.join(pkg.dir, target.path)).map((file) =>
|
|
224
|
-
path.relative(pkg.dir, file).split(path.sep).join(path.posix.sep),
|
|
225
|
-
),
|
|
226
|
-
)
|
|
227
|
-
const withResources = new Map(
|
|
228
|
-
swiftManifestTargets(pkg.manifest, relative).map((target) => [target.name, target]),
|
|
229
|
-
)
|
|
230
|
-
for (const target of reached) {
|
|
231
|
-
const dir = path.join(pkg.dir, target.path)
|
|
232
|
-
targets.set(target.name, {
|
|
233
|
-
...(withResources.get(target.name) ?? target),
|
|
234
|
-
executable: false,
|
|
235
|
-
dir,
|
|
236
|
-
files: walk(dir),
|
|
237
|
-
})
|
|
238
|
-
}
|
|
239
|
-
return null
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
for (const entry of wanted) {
|
|
243
|
-
const reason = resolveProduct(
|
|
244
|
-
swiftPackageIdentity(entry.repositoryURL),
|
|
245
|
-
entry.product,
|
|
246
|
-
)
|
|
247
|
-
if (reason)
|
|
248
|
-
result.unavailable.set(entry.product, {
|
|
249
|
-
repositoryURL: entry.repositoryURL,
|
|
250
|
-
reason,
|
|
251
|
-
})
|
|
252
|
-
}
|
|
253
|
-
result.targets = [...targets.values()]
|
|
254
|
-
return result
|
|
255
|
-
}
|