@@ -329,7 +329,8 @@ public struct Driver {
329
329
case . absolute( let path) :
330
330
return path
331
331
case . relative( let path) :
332
- return workingDirectory. map { AbsolutePath ( $0, path) }
332
+ let cwd = workingDirectory ?? fileSystem. currentWorkingDirectory
333
+ return cwd. map { AbsolutePath ( $0, path) }
333
334
case . standardInput, . standardOutput, . temporary, . temporaryWithKnownContents, . fileList:
334
335
fatalError ( " Frontend target information will never include a path of this type. " )
335
336
}
@@ -688,14 +689,14 @@ public struct Driver {
688
689
compilerMode: compilerMode)
689
690
690
691
// Compute the working directory.
691
- let cwd = fileSystem . currentWorkingDirectory
692
- workingDirectory = try parsedOptions . getLastArgument ( . workingDirectory ) . map { workingDirectoryArg in
692
+ self . workingDirectory = try parsedOptions . getLastArgument ( . workingDirectory ) . map { workingDirectoryArg in
693
+ let cwd = fileSystem . currentWorkingDirectory
693
694
return try cwd. map { try AbsolutePath ( validating: workingDirectoryArg. asSingle, relativeTo: $0) } ?? AbsolutePath ( validating: workingDirectoryArg. asSingle)
694
- } ?? cwd
695
-
696
- // Apply the working directory to the parsed options.
697
- if let workingDirectory = self . workingDirectory {
698
- try Self . applyWorkingDirectory ( workingDirectory , to: & self . parsedOptions)
695
+ }
696
+
697
+ if let specifiedWorkingDir = self . workingDirectory {
698
+ // Apply the working directory to the parsed options if passed explicitly.
699
+ try Self . applyWorkingDirectory ( specifiedWorkingDir , to: & self . parsedOptions)
699
700
}
700
701
701
702
let staticExecutable = parsedOptions. hasFlag ( positive: . staticExecutable,
@@ -776,6 +777,8 @@ public struct Driver {
776
777
}
777
778
778
779
if let workingDirectory = self . workingDirectory {
780
+ // Input paths are prefixed with the working directory when specified,
781
+ // apply the same logic to the output file map keys.
779
782
self . outputFileMap = outputFileMap? . resolveRelativePaths ( relativeTo: workingDirectory)
780
783
} else {
781
784
self . outputFileMap = outputFileMap
@@ -854,7 +857,7 @@ public struct Driver {
854
857
self . buildRecordInfo = BuildRecordInfo (
855
858
actualSwiftVersion: self . frontendTargetInfo. compilerVersion,
856
859
compilerOutputType: compilerOutputType,
857
- workingDirectory: self . workingDirectory,
860
+ workingDirectory: self . workingDirectory ?? fileSystem . currentWorkingDirectory ,
858
861
diagnosticEngine: diagnosticEngine,
859
862
fileSystem: fileSystem,
860
863
moduleOutputInfo: moduleOutputInfo,
@@ -3099,7 +3102,7 @@ extension Driver {
3099
3102
}
3100
3103
3101
3104
if let profileArgs = parsedOptions. getLastArgument ( . profileUse) ? . asMultiple,
3102
- let workingDirectory = workingDirectory {
3105
+ let workingDirectory = workingDirectory ?? fileSystem . currentWorkingDirectory {
3103
3106
for profilingData in profileArgs {
3104
3107
if let path = try ? AbsolutePath ( validating: profilingData,
3105
3108
relativeTo: workingDirectory) {
0 commit comments