From 99f1c1bb3e4f3d3044c0d51fd62153a6bdae6ae5 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Fri, 8 Dec 2023 13:11:52 -0800 Subject: [PATCH] [SwiftCaching] Don't drop `-Xcc` during dependency scanning When using swift caching, `-Xcc` should not be appended to compilation commmands because dependency scanner returns the cc1 command needed to create clang importer. But `-Xcc` options were accidentally dropped from scan-dependencies command, causing them to be ignored. rdar://119391228 --- Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift | 3 ++- Tests/SwiftDriverTests/CachingBuildTests.swift | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift index e82beab26..0547adff1 100644 --- a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift +++ b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift @@ -387,7 +387,8 @@ extension Driver { // Pass through any subsystem flags. try commandLine.appendAll(.Xllvm, from: &parsedOptions) - if !(isCachingEnabled && useClangIncludeTree) { + // If using clang-include-tree, `-Xcc` should only be passed to scanDependencies job. + if (kind == .scanDependencies) || !(isCachingEnabled && useClangIncludeTree) { try commandLine.appendAll(.Xcc, from: &parsedOptions) } diff --git a/Tests/SwiftDriverTests/CachingBuildTests.swift b/Tests/SwiftDriverTests/CachingBuildTests.swift index 415617b46..ad5b632a6 100644 --- a/Tests/SwiftDriverTests/CachingBuildTests.swift +++ b/Tests/SwiftDriverTests/CachingBuildTests.swift @@ -599,6 +599,10 @@ final class CachingBuildTests: XCTestCase { try localFileSystem.writeFileContents(main) { $0.send("import C;import E;import G;") } + let vfsoverlay = path.appending(component: "overlay.yaml") + try localFileSystem.writeFileContents(vfsoverlay) { + $0.send("{\"case-sensitive\":\"false\",\"roots\":[],\"version\":0}") + } let cHeadersPath: AbsolutePath = try testInputsPath.appending(component: "ExplicitModuleBuilds") @@ -615,6 +619,7 @@ final class CachingBuildTests: XCTestCase { "-explicit-module-build", "-cache-compile-job", "-cas-path", casPath.nativePathString(escaped: true), "-working-directory", path.nativePathString(escaped: true), + "-Xcc", "-ivfsoverlay", "-Xcc", vfsoverlay.nativePathString(escaped: true), "-disable-clang-target", main.nativePathString(escaped: true)] + sdkArgumentsForTesting, env: ProcessEnv.vars) @@ -642,6 +647,10 @@ final class CachingBuildTests: XCTestCase { XCTAssertFalse(scannerCommand.contains("-pch-output-dir")) XCTAssertFalse(scannerCommand.contains("Foo.o")) + // Xcc commands are used for scanner command. + XCTAssertTrue(scannerCommand.contains("-Xcc")) + XCTAssertTrue(scannerCommand.contains("-ivfsoverlay")) + // Here purely to dump diagnostic output in a reasonable fashion when things go wrong. let lock = NSLock()