@@ -37,11 +37,11 @@ struct CMakeSmokeTest: CommandPlugin {
37
37
let extraCMakeArgs = args. extractOption ( named: " extra-cmake-arg " )
38
38
Diagnostics . progress ( " Extra cmake args: \( extraCMakeArgs. joined ( separator: " " ) ) " )
39
39
40
- let moduleCachePath = context. pluginWorkDirectoryURL. appending ( component: " module-cache " ) . path ( )
40
+ let moduleCachePath = try context. pluginWorkDirectoryURL. appending ( component: " module-cache " ) . filePath
41
41
42
42
let swiftBuildURL = context. package . directoryURL
43
43
let swiftBuildBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-build " )
44
- Diagnostics . progress ( " swift-build: \( swiftBuildURL. path ( ) ) " )
44
+ try Diagnostics . progress ( " swift-build: \( swiftBuildURL. filePath ) " )
45
45
46
46
let swiftToolsSupportCoreURL = try findDependency ( " swift-tools-support-core " , pluginContext: context)
47
47
let swiftToolsSupportCoreBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-tools-support-core " )
@@ -70,12 +70,12 @@ struct CMakeSmokeTest: CommandPlugin {
70
70
sharedSwiftFlags += [ " -sdk " , sysrootPath]
71
71
}
72
72
73
- let cMakeProjectArgs = [
74
- " -DArgumentParser_DIR= \( swiftArgumentParserBuildURL. appending ( components: " cmake " , " modules " ) . path ( ) ) " ,
75
- " -DLLBuild_DIR= \( llbuildBuildURL. appending ( components: " cmake " , " modules " ) . path ( ) ) " ,
76
- " -DTSC_DIR= \( swiftToolsSupportCoreBuildURL. appending ( components: " cmake " , " modules " ) . path ( ) ) " ,
77
- " -DSwiftDriver_DIR= \( swiftDriverBuildURL. appending ( components: " cmake " , " modules " ) . path ( ) ) " ,
78
- " -DSwiftSystem_DIR= \( swiftSystemBuildURL. appending ( components: " cmake " , " modules " ) . path ( ) ) "
73
+ let cMakeProjectArgs = try [
74
+ " -DArgumentParser_DIR= \( swiftArgumentParserBuildURL. appending ( components: " cmake " , " modules " ) . filePath ) " ,
75
+ " -DLLBuild_DIR= \( llbuildBuildURL. appending ( components: " cmake " , " modules " ) . filePath ) " ,
76
+ " -DTSC_DIR= \( swiftToolsSupportCoreBuildURL. appending ( components: " cmake " , " modules " ) . filePath ) " ,
77
+ " -DSwiftDriver_DIR= \( swiftDriverBuildURL. appending ( components: " cmake " , " modules " ) . filePath ) " ,
78
+ " -DSwiftSystem_DIR= \( swiftSystemBuildURL. appending ( components: " cmake " , " modules " ) . filePath ) "
79
79
]
80
80
81
81
let sharedCMakeArgs = [
@@ -86,34 +86,34 @@ struct CMakeSmokeTest: CommandPlugin {
86
86
] + cMakeProjectArgs + extraCMakeArgs
87
87
88
88
Diagnostics . progress ( " Building swift-tools-support-core " )
89
- try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftToolsSupportCoreURL. path ( ) ] , workingDirectory: swiftToolsSupportCoreBuildURL)
89
+ try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftToolsSupportCoreURL. filePath ] , workingDirectory: swiftToolsSupportCoreBuildURL)
90
90
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftToolsSupportCoreBuildURL)
91
91
Diagnostics . progress ( " Built swift-tools-support-core " )
92
92
93
93
if hostOS != . macOS {
94
94
Diagnostics . progress ( " Building swift-system " )
95
- try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftSystemURL. path ( ) ] , workingDirectory: swiftSystemBuildURL)
95
+ try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftSystemURL. filePath ] , workingDirectory: swiftSystemBuildURL)
96
96
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftSystemBuildURL)
97
97
Diagnostics . progress ( " Built swift-system " )
98
98
}
99
99
100
100
Diagnostics . progress ( " Building llbuild " )
101
- try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ " -DLLBUILD_SUPPORT_BINDINGS:=Swift " , llbuildURL. path ( ) ] , workingDirectory: llbuildBuildURL)
101
+ try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ " -DLLBUILD_SUPPORT_BINDINGS:=Swift " , llbuildURL. filePath ] , workingDirectory: llbuildBuildURL)
102
102
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: llbuildBuildURL)
103
103
Diagnostics . progress ( " Built llbuild " )
104
104
105
105
Diagnostics . progress ( " Building swift-argument-parser " )
106
- try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ " -DBUILD_TESTING=NO " , " -DBUILD_EXAMPLES=NO " , swiftArgumentParserURL. path ( ) ] , workingDirectory: swiftArgumentParserBuildURL)
106
+ try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ " -DBUILD_TESTING=NO " , " -DBUILD_EXAMPLES=NO " , swiftArgumentParserURL. filePath ] , workingDirectory: swiftArgumentParserBuildURL)
107
107
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftArgumentParserBuildURL)
108
108
Diagnostics . progress ( " Built swift-argument-parser " )
109
109
110
110
Diagnostics . progress ( " Building swift-driver " )
111
- try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftDriverURL. path ( ) ] , workingDirectory: swiftDriverBuildURL)
111
+ try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftDriverURL. filePath ] , workingDirectory: swiftDriverBuildURL)
112
112
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftDriverBuildURL)
113
113
Diagnostics . progress ( " Built swift-driver " )
114
114
115
115
Diagnostics . progress ( " Building swift-build in \( swiftBuildBuildURL) " )
116
- try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftBuildURL. path ( ) ] , workingDirectory: swiftBuildBuildURL)
116
+ try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftBuildURL. filePath ] , workingDirectory: swiftBuildBuildURL)
117
117
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftBuildBuildURL)
118
118
Diagnostics . progress ( " Built swift-build " )
119
119
}
@@ -135,9 +135,10 @@ struct CMakeSmokeTest: CommandPlugin {
135
135
throw Errors . missingRepository ( name)
136
136
}
137
137
let dependencyURL = dependency. directoryURL
138
- Diagnostics . progress ( " \( name) : \( dependencyURL. path ( ) ) " )
139
- guard FileManager . default. fileExists ( atPath: dependencyURL. path ( ) ) else {
140
- throw Errors . missingRepository ( dependencyURL. path ( ) )
138
+ let dependencyFilePath = try dependencyURL. filePath
139
+ Diagnostics . progress ( " \( name) : \( dependencyFilePath) " )
140
+ guard FileManager . default. fileExists ( atPath: dependencyFilePath) else {
141
+ throw Errors . missingRepository ( dependencyFilePath)
141
142
}
142
143
return dependencyURL
143
144
}
@@ -169,6 +170,19 @@ enum OS {
169
170
}
170
171
}
171
172
173
+ extension URL {
174
+ var filePath : String {
175
+ get throws {
176
+ try withUnsafeFileSystemRepresentation { path in
177
+ guard let path else {
178
+ throw Errors . miscError ( " cannot get file path for URL: \( self ) " )
179
+ }
180
+ return String ( cString: path)
181
+ }
182
+ }
183
+ }
184
+ }
185
+
172
186
extension Process {
173
187
func run( ) async throws {
174
188
try await withCheckedThrowingContinuation { continuation in
@@ -186,8 +200,8 @@ extension Process {
186
200
}
187
201
188
202
static func checkNonZeroExit( url: URL , arguments: [ String ] , workingDirectory: URL , environment: [ String : String ] ? = nil ) async throws {
189
- Diagnostics . progress ( " \( url. path ( ) ) \( arguments. joined ( separator: " " ) ) " )
190
- #if USE_PROCESS_SPAWNING_WORKAROUND
203
+ try Diagnostics . progress ( " \( url. filePath ) \( arguments. joined ( separator: " " ) ) " )
204
+ #if USE_PROCESS_SPAWNING_WORKAROUND && !os(Windows)
191
205
Diagnostics . progress ( " Using process spawning workaround " )
192
206
// Linux workaround for https://github.com/swiftlang/swift-corelibs-foundation/issues/4772
193
207
// Foundation.Process on Linux seems to inherit the Process.run()-calling thread's signal mask, creating processes that even have SIGTERM blocked
@@ -197,7 +211,7 @@ extension Process {
197
211
var attrs : posix_spawnattr_t = posix_spawnattr_t ( )
198
212
defer { posix_spawnattr_destroy ( & attrs) }
199
213
posix_spawn_file_actions_init ( & fileActions)
200
- posix_spawn_file_actions_addchdir_np ( & fileActions, workingDirectory. path ( ) )
214
+ try posix_spawn_file_actions_addchdir_np ( & fileActions, workingDirectory. filePath )
201
215
202
216
posix_spawnattr_init ( & attrs)
203
217
posix_spawnattr_setpgroup ( & attrs, 0 )
@@ -216,9 +230,9 @@ extension Process {
216
230
posix_spawnattr_setsigdefault ( & attrs, & mostSignals)
217
231
posix_spawnattr_setflags ( & attrs, numericCast ( POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK) )
218
232
var pid : pid_t = - 1
219
- try withArrayOfCStrings ( [ url. path ( ) ] + arguments) { arguments in
233
+ try withArrayOfCStrings ( [ url. filePath ] + arguments) { arguments in
220
234
try withArrayOfCStrings ( ( environment ?? [ : ] ) . map { key, value in " \( key) = \( value) " } ) { environment in
221
- let spawnResult = posix_spawn ( & pid, url. path ( ) , /*file_actions=*/& fileActions, /*attrp=*/& attrs, arguments, nil ) ;
235
+ let spawnResult = try posix_spawn ( & pid, url. filePath , /*file_actions=*/& fileActions, /*attrp=*/& attrs, arguments, nil ) ;
222
236
var exitCode : Int32 = - 1
223
237
var result = wait4 ( pid, & exitCode, 0 , nil ) ;
224
238
while ( result == - 1 && errno == EINTR) {
@@ -246,6 +260,7 @@ extension Process {
246
260
}
247
261
}
248
262
263
+ #if USE_PROCESS_SPAWNING_WORKAROUND && !os(Windows)
249
264
func scan< S: Sequence , U> ( _ seq: S , _ initial: U , _ combine: ( U , S . Element ) -> U ) -> [ U ] {
250
265
var result : [ U ] = [ ]
251
266
result. reserveCapacity ( seq. underestimatedCount)
@@ -283,3 +298,4 @@ func withArrayOfCStrings<T>(
283
298
}
284
299
}
285
300
}
301
+ #endif
0 commit comments