From 9189ae9004af1ee1a699d978d7f392487ec16cc2 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 9 May 2023 11:07:16 -0700 Subject: [PATCH 1/4] Revert "Add test case" This reverts commit c75cfd485ff2a4efd8a0e0afa076d7d2537d2618. --- Tests/SwiftDriverTests/SwiftDriverTests.swift | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index 6b38190b0..24241ed2f 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -6776,7 +6776,6 @@ final class SwiftDriverTests: XCTestCase { try withTemporaryDirectory { tmpDir in var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"], - integratedDriver: false, compilerExecutableDir: tmpDir) guard driver.isFrontendArgSupported(.externalPluginPath) else { return @@ -6819,27 +6818,6 @@ final class SwiftDriverTests: XCTestCase { } } - func testExternalPluginPathsDisabled() throws { -#if !os(macOS) - throw XCTSkip("Supported only in macOS") -#endif - - try withTemporaryDirectory { tmpDir in - var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"], - integratedDriver: true, - compilerExecutableDir: tmpDir) - guard driver.isFrontendArgSupported(.externalPluginPath) else { - return - } - - let jobs = try driver.planBuild().removingAutolinkExtractJobs() - XCTAssertEqual(jobs.count, 1) - let job = jobs.first! - - XCTAssertFalse(job.commandLine.contains(.flag("-external-plugin-path"))) - } - } - func testClangModuleValidateOnce() throws { let flagTest = try Driver(args: ["swiftc", "-typecheck", "foo.swift"]) guard flagTest.isFrontendArgSupported(.clangBuildSessionFile), From ac7ceb544c482fd1d670b3cb4838b03ba8c79001 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 9 May 2023 11:07:29 -0700 Subject: [PATCH 2/4] Revert "Disable adding '-external-plugin-path' in integrated driver mode" This reverts commit bf2de71f699de561d688e6414cd87b3252917e5f. --- Sources/SwiftDriver/Toolchains/DarwinToolchain.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift b/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift index 36463f827..ae08c02ed 100644 --- a/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift +++ b/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift @@ -376,7 +376,6 @@ public final class DarwinToolchain: Toolchain { // Pass -external-plugin-path if the current toolchain is not a Xcode // default toolchain. if - !driver.integratedDriver, driver.isFrontendArgSupported(.externalPluginPath), let xcodeDir = try self.findCurrentSelectedXcodeDir(), try !self.executableDir.isDescendant(of: xcodeDir), From a615f58f0385fcd689c8db1857b519101aa30b7a Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 9 May 2023 11:08:02 -0700 Subject: [PATCH 3/4] Revert "[Macros] Set -external-plugin-path when the toolchain is not Xcode" This reverts commit 53ad3a99e9cbe355d50328f9af702e8211fa7a71. --- .../SwiftDriver/Jobs/FrontendJobHelpers.swift | 4 -- .../Toolchains/DarwinToolchain.swift | 61 ------------------- Tests/SwiftDriverTests/SwiftDriverTests.swift | 49 --------------- Tests/TestUtilities/DriverExtensions.swift | 6 +- 4 files changed, 2 insertions(+), 118 deletions(-) diff --git a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift index aae05f9b4..035f7a115 100644 --- a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift +++ b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift @@ -275,10 +275,6 @@ extension Driver { commandLine.appendPath(localPluginPath) } - if isFrontendArgSupported(.externalPluginPath) { - try commandLine.appendAll(.externalPluginPath, from: &parsedOptions) - } - if isFrontendArgSupported(.blockListFile) { try Driver.findBlocklists(RelativeTo: try toolchain.executableDir).forEach { commandLine.appendFlag(.blockListFile) diff --git a/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift b/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift index ae08c02ed..ea1ebd1ef 100644 --- a/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift +++ b/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift @@ -373,32 +373,6 @@ public final class DarwinToolchain: Toolchain { frontendTargetInfo: FrontendTargetInfo, driver: inout Driver ) throws { - // Pass -external-plugin-path if the current toolchain is not a Xcode - // default toolchain. - if - driver.isFrontendArgSupported(.externalPluginPath), - let xcodeDir = try self.findCurrentSelectedXcodeDir(), - try !self.executableDir.isDescendant(of: xcodeDir), - let xcodeExecutableDir = try self.findXcodeExecutableDir() - { - let xcodePluginServerPath = xcodeExecutableDir - .appending(component: "swift-plugin-server") - - if fileSystem.isExecutableFile(xcodePluginServerPath) { - let xcodeToolchainUsrPath = xcodeExecutableDir.parentDirectory - - let xcodePluginPath = xcodeToolchainUsrPath - .appending(components: "lib", "swift", "host", "plugins") - commandLine.appendFlag(.externalPluginPath) - commandLine.appendFlag(xcodePluginPath.pathString + "#" + xcodePluginServerPath.pathString) - - let xcodeLocalPluginPath = xcodeToolchainUsrPath - .appending(components: "local", "lib", "swift", "host", "plugins") - commandLine.appendFlag(.externalPluginPath) - commandLine.appendFlag(xcodeLocalPluginPath.pathString + "#" + xcodePluginServerPath.pathString) - } - } - guard let sdkPath = frontendTargetInfo.sdkPath?.path, let sdkInfo = getTargetSDKInfo(sdkPath: sdkPath) else { return } @@ -467,38 +441,3 @@ private extension Version { return self.description } } - -extension DarwinToolchain { - func findXcodeExecutableDir() throws -> AbsolutePath? { -#if os(macOS) - let result = try executor.checkNonZeroExit( - args: "xcrun", "-toolchain", "default", "-f", "swiftc", - environment: env - ).trimmingCharacters(in: .whitespacesAndNewlines) - - guard !result.isEmpty else { - return nil - } - return try AbsolutePath(validating: result) - .parentDirectory // swiftc -#else - return nil -#endif - } - - func findCurrentSelectedXcodeDir() throws -> AbsolutePath? { -#if os(macOS) - let result = try executor.checkNonZeroExit( - args: "xcode-select", "-p", - environment: env - ).trimmingCharacters(in: .whitespacesAndNewlines) - - guard !result.isEmpty else { - return nil - } - return try AbsolutePath(validating: result) -#else - return nil -#endif - } -} diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index 24241ed2f..69ca48cd6 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -6769,55 +6769,6 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(job.commandLine.contains(.path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "local", "lib", "swift", "host", "plugins"))))) } - func testExternalPluginPaths() throws { -#if !os(macOS) - throw XCTSkip("Supported only in macOS") -#endif - - try withTemporaryDirectory { tmpDir in - var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"], - compilerExecutableDir: tmpDir) - guard driver.isFrontendArgSupported(.externalPluginPath) else { - return - } - - let jobs = try driver.planBuild().removingAutolinkExtractJobs() - XCTAssertEqual(jobs.count, 1) - let job = jobs.first! - - // This happens only Xcode toolchain has 'swift-plugin-server' which we - // don't know. - let idx1 = job.commandLine.firstIndex(of: .flag("-external-plugin-path")) - try XCTSkipIf(idx1 == nil) - switch job.commandLine[job.commandLine.index(after: idx1!)] { - case .flag(let value): - let components = value.split(separator: "#") - if components.count == 2 { - XCTAssertTrue(components[0].hasSuffix("/usr/lib/swift/host/plugins")) - XCTAssertTrue(components[1].hasSuffix("/usr/bin/swift-plugin-server")) - } else { - XCTFail("# separated count must 2") - } - default: - XCTFail("invalid arg type after '-external-plugin-path'") - } - - let idx2 = job.commandLine[job.commandLine.index(after: idx1!)...].firstIndex(of: .flag("-external-plugin-path")) - switch job.commandLine[job.commandLine.index(after: try XCTUnwrap(idx2))] { - case .flag(let value): - let components = value.split(separator: "#") - if (components.count == 2) { - XCTAssertTrue(components[0].hasSuffix("/usr/local/lib/swift/host/plugins")) - XCTAssertTrue(components[1].hasSuffix("/usr/bin/swift-plugin-server")) - } else { - XCTFail("# separated count must 2") - } - default: - XCTFail("invalid arg type after '-external-plugin-path'") - } - } - } - func testClangModuleValidateOnce() throws { let flagTest = try Driver(args: ["swiftc", "-typecheck", "foo.swift"]) guard flagTest.isFrontendArgSupported(.clangBuildSessionFile), diff --git a/Tests/TestUtilities/DriverExtensions.swift b/Tests/TestUtilities/DriverExtensions.swift index d089d7a99..4431b0d74 100644 --- a/Tests/TestUtilities/DriverExtensions.swift +++ b/Tests/TestUtilities/DriverExtensions.swift @@ -23,8 +23,7 @@ extension Driver { env: [String: String] = ProcessEnv.vars, diagnosticsEngine: DiagnosticsEngine = DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]), fileSystem: FileSystem = localFileSystem, - integratedDriver: Bool = true, - compilerExecutableDir: AbsolutePath? = nil + integratedDriver: Bool = true ) throws { let executor = try SwiftDriverExecutor(diagnosticsEngine: diagnosticsEngine, processSet: ProcessSet(), @@ -35,8 +34,7 @@ extension Driver { diagnosticsOutput: .engine(diagnosticsEngine), fileSystem: fileSystem, executor: executor, - integratedDriver: integratedDriver, - compilerExecutableDir: compilerExecutableDir) + integratedDriver: integratedDriver) } /// For tests that need to set the sdk path. From 6ac0b90bf938d02afae1319f3770fb9971c014c3 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 9 May 2023 11:16:55 -0700 Subject: [PATCH 4/4] Add back propagating '-external-plugin-path' driver agruments --- Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift index 035f7a115..aae05f9b4 100644 --- a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift +++ b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift @@ -275,6 +275,10 @@ extension Driver { commandLine.appendPath(localPluginPath) } + if isFrontendArgSupported(.externalPluginPath) { + try commandLine.appendAll(.externalPluginPath, from: &parsedOptions) + } + if isFrontendArgSupported(.blockListFile) { try Driver.findBlocklists(RelativeTo: try toolchain.executableDir).forEach { commandLine.appendFlag(.blockListFile)