10
10
11
11
import LLBuildManifest
12
12
13
+ import Basics
13
14
import TSCBasic
14
15
import TSCUtility
15
16
@@ -67,9 +68,9 @@ public class LLBuildManifestBuilder {
67
68
for (_, description) in plan. targetMap {
68
69
switch description {
69
70
case . swift( let desc) :
70
- try createSwiftCompileCommand ( desc)
71
+ try self . createSwiftCompileCommand ( desc)
71
72
case . clang( let desc) :
72
- createClangCompileCommand ( desc)
73
+ try self . createClangCompileCommand ( desc)
73
74
}
74
75
}
75
76
}
@@ -78,7 +79,7 @@ public class LLBuildManifestBuilder {
78
79
79
80
// Create command for all products in the plan.
80
81
for (_, description) in plan. productMap {
81
- createProductCommand ( description)
82
+ try self . createProductCommand ( description)
82
83
}
83
84
84
85
// Output a dot graph
@@ -188,23 +189,23 @@ extension LLBuildManifestBuilder {
188
189
_ target: SwiftTargetBuildDescription
189
190
) throws {
190
191
// Inputs.
191
- let inputs = computeSwiftCompileCmdInputs ( target)
192
+ let inputs = try self . computeSwiftCompileCmdInputs ( target)
192
193
193
194
// Outputs.
194
195
let objectNodes = target. objects. map ( Node . file)
195
196
let moduleNode = Node . file ( target. moduleOutputPath)
196
197
let cmdOutputs = objectNodes + [ moduleNode]
197
198
198
199
if buildParameters. useIntegratedSwiftDriver {
199
- try addSwiftCmdsViaIntegratedDriver ( target, inputs: inputs, objectNodes: objectNodes, moduleNode: moduleNode)
200
+ try self . addSwiftCmdsViaIntegratedDriver ( target, inputs: inputs, objectNodes: objectNodes, moduleNode: moduleNode)
200
201
} else if buildParameters. emitSwiftModuleSeparately {
201
- addSwiftCmdsEmitSwiftModuleSeparately ( target, inputs: inputs, objectNodes: objectNodes, moduleNode: moduleNode)
202
+ try self . addSwiftCmdsEmitSwiftModuleSeparately ( target, inputs: inputs, objectNodes: objectNodes, moduleNode: moduleNode)
202
203
} else {
203
- addCmdWithBuiltinSwiftTool ( target, inputs: inputs, cmdOutputs: cmdOutputs)
204
+ self . addCmdWithBuiltinSwiftTool ( target, inputs: inputs, cmdOutputs: cmdOutputs)
204
205
}
205
206
206
- addTargetCmd ( target, cmdOutputs: cmdOutputs)
207
- addModuleWrapCmd ( target)
207
+ self . addTargetCmd ( target, cmdOutputs: cmdOutputs)
208
+ self . addModuleWrapCmd ( target)
208
209
}
209
210
210
211
private func addSwiftCmdsViaIntegratedDriver(
@@ -215,7 +216,7 @@ extension LLBuildManifestBuilder {
215
216
) throws {
216
217
// Use the integrated Swift driver to compute the set of frontend
217
218
// jobs needed to build this Swift target.
218
- var commandLine = target. emitCommandLine ( ) ;
219
+ var commandLine = try target. emitCommandLine ( ) ;
219
220
commandLine. append ( " -driver-use-frontend-path " )
220
221
commandLine. append ( buildParameters. toolchain. swiftCompiler. pathString)
221
222
// FIXME: At some point SwiftPM should provide its own executor for
@@ -243,8 +244,8 @@ extension LLBuildManifestBuilder {
243
244
let commandLine = try job. commandLine. map { try resolver. resolve ( $0) }
244
245
let arguments = [ tool] + commandLine
245
246
246
- let jobInputs = job. inputs. map { $0. resolveToNode ( ) }
247
- let jobOutputs = job. outputs. map { $0. resolveToNode ( ) }
247
+ let jobInputs = try job. inputs. map { try $0. resolveToNode ( ) }
248
+ let jobOutputs = try job. outputs. map { try $0. resolveToNode ( ) }
248
249
249
250
// Add target dependencies as inputs to the main module build command.
250
251
//
@@ -310,7 +311,7 @@ extension LLBuildManifestBuilder {
310
311
let nodes : [ ResolvedTarget . Dependency ] = plan. targetMap. keys. map {
311
312
ResolvedTarget . Dependency. target ( $0, conditions: [ ] )
312
313
}
313
- let allPackageDependencies = try ! topologicalSort ( nodes, successors: { $0. dependencies } )
314
+ let allPackageDependencies = try topologicalSort ( nodes, successors: { $0. dependencies } )
314
315
315
316
// All modules discovered so far as a part of this package manifest.
316
317
// This includes modules that correspond to the package's own targets, package dependency
@@ -339,14 +340,14 @@ extension LLBuildManifestBuilder {
339
340
continue
340
341
}
341
342
guard let description = plan. targetMap [ target] else {
342
- fatalError ( " Expected description for target \( target) " )
343
+ throw InternalError ( " Expected description for target \( target) " )
343
344
}
344
345
switch description {
345
346
case . swift( let desc) :
346
- try createExplicitSwiftTargetCompileCommand ( description: desc,
347
- discoveredModulesMap: & discoveredModulesMap)
347
+ try self . createExplicitSwiftTargetCompileCommand ( description: desc,
348
+ discoveredModulesMap: & discoveredModulesMap)
348
349
case . clang( let desc) :
349
- createClangCompileCommand ( desc)
350
+ try self . createClangCompileCommand ( desc)
350
351
}
351
352
}
352
353
}
@@ -356,7 +357,7 @@ extension LLBuildManifestBuilder {
356
357
discoveredModulesMap: inout SwiftDriver . ModuleInfoMap
357
358
) throws {
358
359
// Inputs.
359
- let inputs = computeSwiftCompileCmdInputs ( description)
360
+ let inputs = try self . computeSwiftCompileCmdInputs ( description)
360
361
361
362
// Outputs.
362
363
let objectNodes = description. objects. map ( Node . file)
@@ -367,8 +368,8 @@ extension LLBuildManifestBuilder {
367
368
try addExplicitBuildSwiftCmds ( description, inputs: inputs,
368
369
discoveredModulesMap: & discoveredModulesMap)
369
370
370
- addTargetCmd ( description, cmdOutputs: cmdOutputs)
371
- addModuleWrapCmd ( description)
371
+ self . addTargetCmd ( description, cmdOutputs: cmdOutputs)
372
+ self . addModuleWrapCmd ( description)
372
373
}
373
374
374
375
private func addExplicitBuildSwiftCmds(
@@ -379,12 +380,12 @@ extension LLBuildManifestBuilder {
379
380
// Pass the driver its external dependencies (target dependencies)
380
381
var dependencyModulePathMap : SwiftDriver . ExternalTargetModulePathMap = [ : ]
381
382
// Collect paths for target dependencies of this target (direct and transitive)
382
- collectTargetDependencyModulePaths ( for: targetDescription. target,
383
- dependencyModulePathMap: & dependencyModulePathMap)
383
+ self . collectTargetDependencyModulePaths ( for: targetDescription. target,
384
+ dependencyModulePathMap: & dependencyModulePathMap)
384
385
385
386
// Compute the set of frontend
386
387
// jobs needed to build this Swift target.
387
- var commandLine = targetDescription. emitCommandLine ( ) ;
388
+ var commandLine = try targetDescription. emitCommandLine ( ) ;
388
389
commandLine. append ( " -driver-use-frontend-path " )
389
390
commandLine. append ( buildParameters. toolchain. swiftCompiler. pathString)
390
391
commandLine. append ( " -experimental-explicit-module-build " )
@@ -401,7 +402,7 @@ extension LLBuildManifestBuilder {
401
402
// Save the path to the target's module to be used by its dependents
402
403
// Save the dependency graph of this target to be used by its dependents
403
404
guard let dependencyGraph = driver. interModuleDependencyGraph else {
404
- fatalError ( " Expected module dependency graph for target: \( targetDescription) " )
405
+ throw InternalError ( " Expected module dependency graph for target: \( targetDescription) " )
405
406
}
406
407
try InterModuleDependencyGraph . mergeModules ( from: dependencyGraph,
407
408
into: & discoveredModulesMap)
@@ -450,7 +451,7 @@ extension LLBuildManifestBuilder {
450
451
inputs: [ Node ] ,
451
452
objectNodes: [ Node ] ,
452
453
moduleNode: Node
453
- ) {
454
+ ) throws {
454
455
// FIXME: We need to ingest the emitted dependencies.
455
456
456
457
manifest. addShellCmd (
@@ -467,7 +468,7 @@ extension LLBuildManifestBuilder {
467
468
description: " Compiling module \( target. target. name) " ,
468
469
inputs: inputs,
469
470
outputs: objectNodes,
470
- args: target. emitObjectsCommandLine ( )
471
+ args: try target. emitObjectsCommandLine ( )
471
472
)
472
473
}
473
474
@@ -498,7 +499,7 @@ extension LLBuildManifestBuilder {
498
499
499
500
private func computeSwiftCompileCmdInputs(
500
501
_ target: SwiftTargetBuildDescription
501
- ) -> [ Node ] {
502
+ ) throws -> [ Node ] {
502
503
var inputs = target. sources. map ( Node . file)
503
504
504
505
// Add resources node as the input to the target. This isn't great because we
@@ -509,7 +510,7 @@ extension LLBuildManifestBuilder {
509
510
inputs. append ( resourcesNode)
510
511
}
511
512
512
- func addStaticTargetInputs( _ target: ResolvedTarget ) {
513
+ func addStaticTargetInputs( _ target: ResolvedTarget ) throws {
513
514
// Ignore C Modules.
514
515
if target. underlyingTarget is SystemLibraryTarget { return }
515
516
// Ignore Binary Modules.
@@ -535,14 +536,14 @@ extension LLBuildManifestBuilder {
535
536
inputs. append ( file: object)
536
537
}
537
538
case nil :
538
- fatalError ( " unexpected: target \( target) not in target map \( plan. targetMap) " )
539
+ throw InternalError ( " unexpected: target \( target) not in target map \( plan. targetMap) " )
539
540
}
540
541
}
541
542
542
543
for dependency in target. target. dependencies ( satisfying: buildEnvironment) {
543
544
switch dependency {
544
545
case . target( let target, _) :
545
- addStaticTargetInputs ( target)
546
+ try addStaticTargetInputs ( target)
546
547
547
548
case . product( let product, _) :
548
549
switch product. type {
@@ -553,7 +554,7 @@ extension LLBuildManifestBuilder {
553
554
// For automatic and static libraries, add their targets as static input.
554
555
case . library( . automatic) , . library( . static) :
555
556
for target in product. targets {
556
- addStaticTargetInputs ( target)
557
+ try addStaticTargetInputs ( target)
557
558
}
558
559
559
560
case . test:
@@ -618,7 +619,7 @@ extension LLBuildManifestBuilder {
618
619
/// Create a llbuild target for a Clang target description.
619
620
private func createClangCompileCommand(
620
621
_ target: ClangTargetBuildDescription
621
- ) {
622
+ ) throws {
622
623
let standards = [
623
624
( target. clangTarget. cxxLanguageStandard, SupportedLanguageExtension . cppExtensions) ,
624
625
( target. clangTarget. cLanguageStandard, SupportedLanguageExtension . cExtensions) ,
@@ -688,7 +689,7 @@ extension LLBuildManifestBuilder {
688
689
689
690
args += [ " -c " , path. source. pathString, " -o " , path. object. pathString]
690
691
691
- let clangCompiler = try ! buildParameters. toolchain. getClangCompiler ( ) . pathString
692
+ let clangCompiler = try buildParameters. toolchain. getClangCompiler ( ) . pathString
692
693
args. insert ( clangCompiler, at: 0 )
693
694
694
695
let objectFileNode : Node = . file( path. object)
@@ -753,7 +754,7 @@ extension LLBuildManifestBuilder {
753
754
// MARK:- Product Command
754
755
755
756
extension LLBuildManifestBuilder {
756
- private func createProductCommand( _ buildProduct: ProductBuildDescription ) {
757
+ private func createProductCommand( _ buildProduct: ProductBuildDescription ) throws {
757
758
let cmdName = buildProduct. product. getCommandName ( config: buildConfig)
758
759
759
760
// Create archive tool for static library and shell tool for rest of the products.
@@ -771,7 +772,7 @@ extension LLBuildManifestBuilder {
771
772
description: " Linking \( buildProduct. binary. prettyPath ( ) ) " ,
772
773
inputs: inputs. map ( Node . file) ,
773
774
outputs: [ . file( buildProduct. binary) ] ,
774
- args: buildProduct. linkArguments ( )
775
+ args: try buildProduct. linkArguments ( )
775
776
)
776
777
}
777
778
@@ -854,15 +855,15 @@ extension LLBuildManifestBuilder {
854
855
extension TypedVirtualPath {
855
856
/// Resolve a typed virtual path provided by the Swift driver to
856
857
/// a node in the build graph.
857
- func resolveToNode( ) -> Node {
858
+ func resolveToNode( ) throws -> Node {
858
859
if let absolutePath = file. absolutePath {
859
860
return Node . file ( absolutePath)
860
861
} else if let relativePath = file. relativePath {
861
862
return Node . file ( localFileSystem. currentWorkingDirectory!. appending ( relativePath) )
862
863
} else if let temporaryFileName = file. temporaryFileName {
863
864
return Node . virtual ( temporaryFileName. pathString)
864
865
} else {
865
- fatalError ( " Cannot resolve VirtualPath: \( file) " )
866
+ throw InternalError ( " Cannot resolve VirtualPath: \( file) " )
866
867
}
867
868
}
868
869
}
0 commit comments