Skip to content

Commit 006545f

Browse files
committed
Preserve snapshot behaviour for Xcode's older entry point function
1 parent 392e42c commit 006545f

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

Sources/Testing/ABI/EntryPoints/ABIEntryPoint.swift

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,10 @@ extension ABIv0 {
4747
/// callback.
4848
public static var entryPoint: EntryPoint {
4949
return { configurationJSON, recordHandler in
50-
let args = try configurationJSON.map { configurationJSON in
51-
try JSON.decode(__CommandLineArguments_v0.self, from: configurationJSON)
52-
}
53-
54-
let eventHandler = try eventHandlerForStreamingEvents(version: args?.eventStreamVersion, forwardingTo: recordHandler)
55-
let exitCode = await Testing.entryPoint(passing: args, eventHandler: eventHandler)
56-
return exitCode == EXIT_SUCCESS
50+
try await Testing.entryPoint(
51+
configurationJSON: configurationJSON,
52+
recordHandler: recordHandler
53+
) == EXIT_SUCCESS
5754
}
5855
}
5956
}
@@ -88,7 +85,39 @@ typealias ABIEntryPoint_v0 = @Sendable (
8885
@_cdecl("swt_copyABIEntryPoint_v0")
8986
@usableFromInline func copyABIEntryPoint_v0() -> UnsafeMutableRawPointer {
9087
let result = UnsafeMutablePointer<ABIEntryPoint_v0>.allocate(capacity: 1)
91-
result.initialize { try await ABIv0.entryPoint($0, $1) ? EXIT_SUCCESS : EXIT_FAILURE }
88+
result.initialize { configurationJSON, recordHandler in
89+
try await entryPoint(
90+
configurationJSON: configurationJSON,
91+
eventStreamVersionIfNil: -1,
92+
recordHandler: recordHandler
93+
)
94+
}
9295
return .init(result)
9396
}
97+
98+
/// A common implementation for ``ABIv0/entryPoint-swift.type.property`` and
99+
/// ``copyABIEntryPoint_v0()`` that provides Xcode 16 Beta 1 compatibility.
100+
///
101+
/// This function will be removed (with its logic incorporated into
102+
/// ``ABIv0/entryPoint-swift.type.property``) in a future update.
103+
private func entryPoint(
104+
configurationJSON: UnsafeRawBufferPointer?,
105+
eventStreamVersionIfNil: Int? = nil,
106+
recordHandler: @escaping @Sendable (_ recordJSON: UnsafeRawBufferPointer) -> Void
107+
) async throws -> CInt {
108+
var args = try configurationJSON.map { configurationJSON in
109+
try JSON.decode(__CommandLineArguments_v0.self, from: configurationJSON)
110+
}
111+
112+
// If the caller needs a nil event stream version to default to a specific
113+
// JSON schema, apply it here as if they'd specified it in the configuration
114+
// JSON blob.
115+
if let eventStreamVersionIfNil, args?.eventStreamVersion == nil {
116+
args?.eventStreamVersion = eventStreamVersionIfNil
117+
}
118+
119+
let eventHandler = try eventHandlerForStreamingEvents(version: args?.eventStreamVersion, forwardingTo: recordHandler)
120+
let exitCode = await entryPoint(passing: args, eventHandler: eventHandler)
121+
return exitCode
122+
}
94123
#endif

0 commit comments

Comments
 (0)