@@ -25,8 +25,57 @@ extension Driver {
25
25
}
26
26
}
27
27
28
- /// Add the compiler inputs for a frontend compilation job, and return the corresponding primary set of outputs.
29
- func addCompileInputs( primaryInputs: [ TypedVirtualPath ] , inputs: inout [ TypedVirtualPath ] , commandLine: inout [ Job . ArgTemplate ] ) -> [ TypedVirtualPath ] {
28
+ fileprivate mutating func computePrimaryOutput( for input: TypedVirtualPath , outputType: FileType ,
29
+ isTopLevel: Bool ) -> TypedVirtualPath {
30
+ if let path = outputFileMap? . existingOutput ( inputFile: input. file, outputType: outputType) {
31
+ return TypedVirtualPath ( file: path, type: outputType)
32
+ }
33
+
34
+ if isTopLevel {
35
+ if let baseOutput = parsedOptions. getLastArgument ( . o) ? . asSingle,
36
+ let baseOutputPath = try ? VirtualPath ( path: baseOutput) {
37
+ return TypedVirtualPath ( file: baseOutputPath, type: outputType)
38
+ } else if compilerOutputType? . isTextual == true {
39
+ return TypedVirtualPath ( file: . standardOutput, type: outputType)
40
+ }
41
+ }
42
+
43
+ let baseName : String
44
+ if ( !compilerMode. usesPrimaryFileInputs && numThreads == 0 ) {
45
+ baseName = moduleName
46
+ } else {
47
+ baseName = input. file. basenameWithoutExt
48
+ }
49
+
50
+ if !isTopLevel {
51
+ return TypedVirtualPath ( file: VirtualPath . temporary ( . init( baseName. appendingFileTypeExtension ( outputType) ) ) ,
52
+ type: outputType)
53
+ }
54
+
55
+ return TypedVirtualPath ( file: . relative( . init( baseName. appendingFileTypeExtension ( outputType) ) ) , type: outputType)
56
+ }
57
+
58
+ /// Add the compiler inputs for a frontend compilation job, and return the
59
+ /// corresponding primary set of outputs.
60
+ mutating func addCompileInputs( primaryInputs: [ TypedVirtualPath ] ,
61
+ inputs: inout [ TypedVirtualPath ] ,
62
+ commandLine: inout [ Job . ArgTemplate ] ) -> [ TypedVirtualPath ] {
63
+ // Is this compile job top-level
64
+ let isTopLevel : Bool
65
+
66
+ switch compilerOutputType {
67
+ case . assembly, . sil, . raw_sil, . llvmIR, . ast:
68
+ isTopLevel = true
69
+ case . object:
70
+ isTopLevel = ( linkerOutputType == nil )
71
+ case . swift, . sib, . image, . dSYM, . dependencies, . autolink,
72
+ . swiftModule, . swiftDocumentation, . swiftInterface,
73
+ . swiftSourceInfoFile, . raw_sib, . llvmBitcode, . diagnostics,
74
+ . objcHeader, . swiftDeps, . remap, . importedModules, . tbd, . moduleTrace,
75
+ . indexData, . optimizationRecord, . pcm, . pch, nil :
76
+ isTopLevel = false
77
+ }
78
+
30
79
// Collect the set of input files that are part of the Swift compilation.
31
80
let swiftInputFiles : [ TypedVirtualPath ] = inputFiles. compactMap { inputFile in
32
81
if inputFile. type. isPartOfSwiftCompilation {
@@ -58,21 +107,19 @@ extension Driver {
58
107
// add an output for the input.
59
108
if isPrimary || numThreads > 0 ,
60
109
let compilerOutputType = compilerOutputType {
61
- let output = ( outputFileMap ?? OutputFileMap ( ) ) . getOutput (
62
- inputFile: input. file,
63
- outputType: compilerOutputType
64
- )
65
- primaryOutputs. append ( TypedVirtualPath ( file: output, type: compilerOutputType) )
110
+ primaryOutputs. append ( computePrimaryOutput ( for: input,
111
+ outputType: compilerOutputType,
112
+ isTopLevel: isTopLevel) )
66
113
}
67
114
}
68
115
69
116
// When not using primary file inputs or multithreading, add a single output.
70
117
if !usesPrimaryFileInputs && numThreads == 0 ,
71
118
let outputType = compilerOutputType {
72
- let existingOutputPath = outputFileMap ? . existingOutputForSingleInput (
73
- outputType : outputType )
74
- let output = existingOutputPath ?? VirtualPath . temporary ( . init ( moduleName . appendingFileTypeExtension ( outputType ) ) )
75
- primaryOutputs . append ( TypedVirtualPath ( file : output , type : outputType ) )
119
+ primaryOutputs . append ( computePrimaryOutput (
120
+ for : TypedVirtualPath ( file : try ! VirtualPath ( path : " " ) ,
121
+ type : swiftInputFiles [ 0 ] . type ) ,
122
+ outputType : outputType , isTopLevel : isTopLevel ) )
76
123
}
77
124
78
125
return primaryOutputs
0 commit comments