@@ -226,7 +226,7 @@ public struct SwiftFrontendTool: ToolProtocol {
226
226
227
227
/// Swift compiler llbuild tool.
228
228
public struct SwiftCompilerTool : ToolProtocol {
229
- public static let name : String = " swift-compiler "
229
+ public static let name : String = " shell "
230
230
231
231
public static let numThreads : Int = ProcessInfo . processInfo. activeProcessorCount
232
232
@@ -244,6 +244,7 @@ public struct SwiftCompilerTool: ToolProtocol {
244
244
public var sources : [ AbsolutePath ]
245
245
public var isLibrary : Bool
246
246
public var wholeModuleOptimization : Bool
247
+ public var outputFileMapPath : AbsolutePath
247
248
248
249
init (
249
250
inputs: [ Node ] ,
@@ -258,7 +259,8 @@ public struct SwiftCompilerTool: ToolProtocol {
258
259
otherArguments: [ String ] ,
259
260
sources: [ AbsolutePath ] ,
260
261
isLibrary: Bool ,
261
- wholeModuleOptimization: Bool
262
+ wholeModuleOptimization: Bool ,
263
+ outputFileMapPath: AbsolutePath
262
264
) {
263
265
self . inputs = inputs
264
266
self . outputs = outputs
@@ -273,24 +275,43 @@ public struct SwiftCompilerTool: ToolProtocol {
273
275
self . sources = sources
274
276
self . isLibrary = isLibrary
275
277
self . wholeModuleOptimization = wholeModuleOptimization
278
+ self . outputFileMapPath = outputFileMapPath
276
279
}
277
280
278
- public func write( to stream: ManifestToolStream ) {
279
- stream [ " executable " ] = executable
280
- stream [ " module-name " ] = moduleName
281
- if let moduleAliases {
282
- // Format the key and value to pass to -module-alias flag
283
- let formatted = moduleAliases. map { $0. key + " = " + $0. value}
284
- stream [ " module-aliases " ] = formatted
281
+ var description : String {
282
+ return " Compiling Swift Module ' \( moduleName) ' ( \( sources. count) sources) "
283
+ }
284
+
285
+ var arguments : [ String ] {
286
+ var arguments = [
287
+ executable. pathString,
288
+ " -module-name " , moduleName,
289
+ ]
290
+ if let moduleAliases = moduleAliases {
291
+ for (original, alias) in moduleAliases {
292
+ arguments += [ " -module-alias \( original) = \( alias) " ]
293
+ }
294
+ }
295
+ arguments += [
296
+ " -incremental " ,
297
+ " -emit-dependencies " ,
298
+ " -emit-module " ,
299
+ " -emit-module-path " , moduleOutputPath. pathString,
300
+ " -output-file-map " , outputFileMapPath. pathString,
301
+ ]
302
+ if isLibrary {
303
+ arguments += [ " -parse-as-library " ]
285
304
}
286
- stream [ " module-output-path " ] = moduleOutputPath
287
- stream [ " import-paths " ] = [ importPath]
288
- stream [ " temps-path " ] = tempsPath
289
- stream [ " objects " ] = objects
290
- stream [ " other-args " ] = otherArguments
291
- stream [ " sources " ] = sources
292
- stream [ " is-library " ] = isLibrary
293
- stream [ " enable-whole-module-optimization " ] = wholeModuleOptimization
294
- stream [ " num-threads " ] = Self . numThreads
295
- }
305
+ if wholeModuleOptimization {
306
+ arguments += [ " -whole-module-optimization " , " -num-threads " , " \( Self . numThreads) " ]
307
+ }
308
+ arguments += [ " -c " ] + sources. map { $0. pathString }
309
+ arguments += [ " -I " , importPath. pathString]
310
+ arguments += otherArguments
311
+ return arguments
312
+ }
313
+
314
+ public func write( to stream: ManifestToolStream ) {
315
+ ShellTool ( description: description, inputs: inputs, outputs: outputs, arguments: arguments) . write ( to: stream)
316
+ }
296
317
}
0 commit comments