Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/XcodeMCPNativeRuntime/NativePreviewBuild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ final class NativePreviewBuild {
var result = records.map(\.target)
var previewRoots: [Target] = []
if let platform {
let selection = try NativePreviewTool.selectTarget(result, source: source, platform: platform)
let selection = try NativePreviewStaging.selectTarget(result, source: source, platform: platform)
if let index = result.firstIndex(where: {
$0.outputURL == selection.host.outputURL && $0.sdkRoot == selection.host.sdkRoot
&& $0.sdkVariant == selection.host.sdkVariant && $0.architecture == selection.host.architecture
Expand All @@ -681,7 +681,7 @@ final class NativePreviewBuild {
result[index].compileCommandLine = try await compileCommandLine(for: records[index], priorBuild: priorBuild,
workspace: workspace, source: source, image: image)
}
if let hostOutput = selection.host.outputURL, NativePreviewTool.productBundle(containing: hostOutput) == nil {
if let hostOutput = selection.host.outputURL, NativePreviewStaging.productBundle(containing: hostOutput) == nil {
let sourceRecord = (buildable: records[index].buildable, native: records[index].native, target: result[index])
let dependencies = try await dependencies(for: sourceRecord, records: records, buildables: buildables, image: image,
priorBuild: priorBuild, workspace: workspace, scheme: scheme, destination: destination)
Expand Down
290 changes: 290 additions & 0 deletions Sources/XcodeMCPNativeRuntime/NativePreviewDefinitions.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ struct NativePreviewProductSignature: Equatable, Sendable {
var pending = build.targets + build.previewRoots
while let target = pending.popLast() {
if let output = target.outputURL {
products.insert(NativePreviewTool.productBundle(containing: output)
?? NativePreviewTool.frameworkBundle(containing: output) ?? output)
products.insert(NativePreviewStaging.productBundle(containing: output)
?? NativePreviewStaging.frameworkBundle(containing: output) ?? output)
}
products.formUnion(target.resourceURLs)
pending += target.dependencies
Expand Down
794 changes: 794 additions & 0 deletions Sources/XcodeMCPNativeRuntime/NativePreviewStaging.swift

Large diffs are not rendered by default.

1,142 changes: 37 additions & 1,105 deletions Sources/XcodeMCPNativeRuntime/NativePreviewTool.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct NativePreviewDiscoveryTests {
@Test func recognizesRegistryNamesWithMangledWordSubstitutions() {
let symbol = "_$s15EmbeddedPreview04$s15a89Preview0024FrameworkViewswift_ynAHffMX12_0_33_11075570A56CB59BAD1AB26CEC639C6ELl0B0fMf_15B12RegistryfMu_VMn"
let name = "15EmbeddedPreview04$s15a89Preview0024FrameworkViewswift_ynAHffMX12_0_33_11075570A56CB59BAD1AB26CEC639C6ELl0B0fMf_15B12RegistryfMu_V"
#expect(NativePreviewTool.registryNames(in: symbol) == [name])
#expect(NativePreviewStaging.registryNames(in: symbol) == [name])
}

@Test func discoversProgramRootsFromCompilerMainSymbols() {
Expand All @@ -22,8 +22,8 @@ struct NativePreviewDiscoveryTests {
"_$s\(widgetRoot)VMn",
"_main",
].joined(separator: "\n")
#expect(NativePreviewTool.programRootNames(in: symbols) == [appRoot, widgetRoot])
#expect(NativePreviewTool.programRootNames(in: "_$s\(widgetRoot)VMn") == [])
#expect(NativePreviewStaging.programRootNames(in: symbols) == [appRoot, widgetRoot])
#expect(NativePreviewStaging.programRootNames(in: "_$s\(widgetRoot)VMn") == [])
}

@Test func programLibrariesMatchTheBuiltHostImage() async throws {
Expand All @@ -41,8 +41,8 @@ struct NativePreviewDiscoveryTests {
try FileManager.default.copyItem(at: output, to: stagedHost)
try FileManager.default.copyItem(at: otherOutput, to: otherLibrary)

#expect(try NativePreviewTool.programLibraries(previewLibraries: [otherLibrary, stagedHost], output: output) == [stagedHost])
#expect(try NativePreviewTool.programLibraries(previewLibraries: [otherLibrary], output: output) == [])
#expect(try NativePreviewStaging.programLibraries(previewLibraries: [otherLibrary, stagedHost], output: output) == [stagedHost])
#expect(try NativePreviewStaging.programLibraries(previewLibraries: [otherLibrary], output: output) == [])
}

@Test func includesEmbeddedFrameworkExecutablesAndDebugLibraries() async throws {
Expand Down Expand Up @@ -74,16 +74,16 @@ struct NativePreviewDiscoveryTests {
try PropertyListSerialization.data(fromPropertyList: info, format: .xml, options: 0)
.write(to: wrongFramework.appendingPathComponent("Info.plist"))

let libraries = try NativePreviewTool.registryLibraries(in: app, previewLibraries: [preview])
let libraries = try NativePreviewStaging.registryLibraries(in: app, previewLibraries: [preview])
let expected = [preview, rootDylib, executable, frameworkPreview, dylib, nestedDylib, wrongExecutable]
.map { $0.resolvingSymlinksInPath().path }
#expect(Set(libraries.map(\.path)) == Set(expected))

let frameworkPaths = try NativePreviewTool.libraryPaths(in: app, previewLibraries: [preview],
let frameworkPaths = try NativePreviewStaging.libraryPaths(in: app, previewLibraries: [preview],
registryLibraries: libraries, sourceOutput: sourceOutput)
#expect(frameworkPaths == ["FixtureApp.debug.dylib", "Frameworks/FixtureKit.framework/FixtureImplementation"])

let staticPaths = try NativePreviewTool.libraryPaths(in: app, previewLibraries: [preview],
let staticPaths = try NativePreviewStaging.libraryPaths(in: app, previewLibraries: [preview],
registryLibraries: libraries, sourceOutput: app.deletingLastPathComponent().appendingPathComponent("FixturePackage.o"))
#expect(staticPaths == ["FixtureApp.debug.dylib"])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import Testing
struct NativePreviewLocationTests {
@Test func unicodePrefixUsesMacroByteCoordinates() throws {
let source = "import SwiftUI\n/* 🌸 */ #Preview { Text(\"A\") }\n"
#expect(try NativePreviewTool.registryColumn(in: source, line: 2, utf16Column: 9) == 12)
#expect(try NativePreviewDefinitions.registryColumn(in: source, line: 2, utf16Column: 9) == 12)
}

@Test func changedSourceCannotUseStaleCoordinates() {
#expect(throws: NativeRuntimeError.self) {
try NativePreviewTool.registryColumn(in: "#Preview {}", line: 1, utf16Column: 100)
try NativePreviewDefinitions.registryColumn(in: "#Preview {}", line: 1, utf16Column: 100)
}
}
}
Loading