@@ -66,18 +66,19 @@ public struct ExitTest: Sendable {
66
66
#endif
67
67
}
68
68
69
- /// Find a back channel file handle set up by the parent process.
69
+ /// The back channel file handle set up by the parent process.
70
70
///
71
- /// - Returns: A file handle open for writing to which events should be
72
- /// written, or `nil` if the file handle could not be resolved.
73
- private static func _findBackChannel( ) -> FileHandle ? {
71
+ /// The value of this property is a file handle open for writing to which
72
+ /// events should be written, or `nil` if the file handle could not be
73
+ /// resolved.
74
+ private static let _backChannel : FileHandle ? = {
74
75
guard let backChannelEnvironmentVariable = Environment . variable ( named: " SWT_EXPERIMENTAL_BACKCHANNEL " ) else {
75
76
return nil
76
77
}
77
78
78
79
var fd : CInt ?
79
80
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD)
80
- fd = CInt ( backChannelEnvironmentVariable) . map ( dup )
81
+ fd = CInt ( backChannelEnvironmentVariable)
81
82
#elseif os(Windows)
82
83
if let handle = UInt ( backChannelEnvironmentVariable) . flatMap ( HANDLE . init ( bitPattern: ) ) {
83
84
fd = _open_osfhandle ( Int ( bitPattern: handle) , _O_WRONLY | _O_BINARY)
@@ -90,7 +91,7 @@ public struct ExitTest: Sendable {
90
91
}
91
92
92
93
return try ? FileHandle ( unsafePOSIXFileDescriptor: fd, mode: " wb " )
93
- }
94
+ } ( )
94
95
95
96
/// Call the exit test in the current process.
96
97
///
@@ -104,23 +105,22 @@ public struct ExitTest: Sendable {
104
105
105
106
// Set up the configuration for this process.
106
107
var configuration = Configuration ( )
107
- if let backChannel = Self . _findBackChannel ( ) {
108
- // Encode events as JSON and write them to the back channel file handle.
109
- var eventHandler = ABIv0 . Record. eventHandler ( encodeAsJSONLines: true ) { json in
110
- try ? backChannel. write ( json)
111
- }
112
108
113
- // Only forward issue-recorded events. (If we start handling other kinds
114
- // of event in the future, we can forward them too.)
115
- eventHandler = { [ eventHandler] event, eventContext in
116
- if case . issueRecorded = event. kind {
117
- eventHandler ( event, eventContext)
118
- }
119
- }
109
+ // Encode events as JSON and write them to the back channel file handle.
110
+ var eventHandler = ABIv0 . Record. eventHandler ( encodeAsJSONLines: true ) { json in
111
+ try ? Self . _backChannel? . write ( json)
112
+ }
120
113
121
- configuration. eventHandler = eventHandler
114
+ // Only forward issue-recorded events. (If we start handling other kinds
115
+ // of event in the future, we can forward them too.)
116
+ eventHandler = { [ eventHandler] event, eventContext in
117
+ if case . issueRecorded = event. kind {
118
+ eventHandler ( event, eventContext)
119
+ }
122
120
}
123
121
122
+ configuration. eventHandler = eventHandler
123
+
124
124
do {
125
125
try await Configuration . withCurrent ( configuration, perform: body)
126
126
} catch {
0 commit comments