@@ -329,7 +329,8 @@ public struct Driver {
329329 case . absolute( let path) :
330330 return path
331331 case . relative( let path) :
332- return workingDirectory. map { AbsolutePath ( $0, path) }
332+ let cwd = workingDirectory ?? fileSystem. currentWorkingDirectory
333+ return cwd. map { AbsolutePath ( $0, path) }
333334 case . standardInput, . standardOutput, . temporary, . temporaryWithKnownContents, . fileList:
334335 fatalError ( " Frontend target information will never include a path of this type. " )
335336 }
@@ -688,14 +689,14 @@ public struct Driver {
688689 compilerMode: compilerMode)
689690
690691 // 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
693694 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)
699700 }
700701
701702 let staticExecutable = parsedOptions. hasFlag ( positive: . staticExecutable,
@@ -776,6 +777,8 @@ public struct Driver {
776777 }
777778
778779 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.
779782 self . outputFileMap = outputFileMap? . resolveRelativePaths ( relativeTo: workingDirectory)
780783 } else {
781784 self . outputFileMap = outputFileMap
@@ -854,7 +857,7 @@ public struct Driver {
854857 self . buildRecordInfo = BuildRecordInfo (
855858 actualSwiftVersion: self . frontendTargetInfo. compilerVersion,
856859 compilerOutputType: compilerOutputType,
857- workingDirectory: self . workingDirectory,
860+ workingDirectory: self . workingDirectory ?? fileSystem . currentWorkingDirectory ,
858861 diagnosticEngine: diagnosticEngine,
859862 fileSystem: fileSystem,
860863 moduleOutputInfo: moduleOutputInfo,
@@ -3099,7 +3102,7 @@ extension Driver {
30993102 }
31003103
31013104 if let profileArgs = parsedOptions. getLastArgument ( . profileUse) ? . asMultiple,
3102- let workingDirectory = workingDirectory {
3105+ let workingDirectory = workingDirectory ?? fileSystem . currentWorkingDirectory {
31033106 for profilingData in profileArgs {
31043107 if let path = try ? AbsolutePath ( validating: profilingData,
31053108 relativeTo: workingDirectory) {
0 commit comments