Skip to content

Commit 78f6a18

Browse files
[Caching] Remap the path in -file-compilation-dir if needed
A follow-up to swiftlang#1557 that when caching is enabled and using the scanner prefix mapping option to canonicalize the path, make sure the path passed via `-file-compilation-dir` is remapped.
1 parent 97c24cc commit 78f6a18

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,11 @@ extension Driver {
372372
// TODO: Should we support -fcoverage-compilation-dir?
373373
commandLine.appendFlag(.fileCompilationDir)
374374
if let compilationDir = parsedOptions.getLastArgument(.fileCompilationDir)?.asSingle {
375-
commandLine.appendFlag(compilationDir)
375+
let compDirPath = try VirtualPath.intern(path: compilationDir)
376+
try addPathArgument(VirtualPath.lookup(compDirPath), to:&commandLine, remap: jobNeedPathRemap)
376377
} else if let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory {
377-
commandLine.appendFlag(cwd.pathString)
378+
let compDirPath = VirtualPath.absolute(cwd)
379+
try addPathArgument(compDirPath, to:&commandLine, remap: jobNeedPathRemap)
378380
}
379381
}
380382

Tests/SwiftDriverTests/CachingBuildTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ final class CachingBuildTests: XCTestCase {
748748
var driver = try Driver(args: ["swiftc",
749749
"-I", cHeadersPath.nativePathString(escaped: true),
750750
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
751-
"/tmp/Foo.o", "-v",
751+
"/tmp/Foo.o", "-v", "-g",
752752
"-explicit-module-build",
753753
"-cache-compile-job", "-cas-path", casPath.nativePathString(escaped: true),
754754
"-working-directory", path.nativePathString(escaped: true),

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,16 @@ final class SwiftDriverTests: XCTestCase {
594594

595595
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-file-compilation-dir", ".") { driver in
596596
let jobs = try driver.planBuild()
597+
let path = try VirtualPath.intern(path: ".")
597598
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
598-
XCTAssertTrue(jobs[0].commandLine.contains(.flag(".")))
599+
XCTAssertTrue(jobs[0].commandLine.contains(.path(VirtualPath.lookup(path))))
599600
}
600601

601602
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-working-directory", "/tmp") { driver in
602603
let jobs = try driver.planBuild()
604+
let path = try VirtualPath.intern(path: "/tmp")
603605
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
604-
XCTAssertTrue(jobs[0].commandLine.contains(.flag("/tmp")))
606+
XCTAssertTrue(jobs[0].commandLine.contains(.path(VirtualPath.lookup(path))))
605607
}
606608

607609
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c") { driver in

0 commit comments

Comments
 (0)