Skip to content

Commit 0dfb2b7

Browse files
authored
Merge pull request #1359 from rintaro/revert-external-plugin-path
Revert "[Macros] Set -external-plugin-path when the toolchain is not Xcode"
2 parents 9cff36e + 6ac0b90 commit 0dfb2b7

File tree

3 files changed

+2
-137
lines changed

3 files changed

+2
-137
lines changed

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -373,33 +373,6 @@ public final class DarwinToolchain: Toolchain {
373373
frontendTargetInfo: FrontendTargetInfo,
374374
driver: inout Driver
375375
) throws {
376-
// Pass -external-plugin-path if the current toolchain is not a Xcode
377-
// default toolchain.
378-
if
379-
!driver.integratedDriver,
380-
driver.isFrontendArgSupported(.externalPluginPath),
381-
let xcodeDir = try self.findCurrentSelectedXcodeDir(),
382-
try !self.executableDir.isDescendant(of: xcodeDir),
383-
let xcodeExecutableDir = try self.findXcodeExecutableDir()
384-
{
385-
let xcodePluginServerPath = xcodeExecutableDir
386-
.appending(component: "swift-plugin-server")
387-
388-
if fileSystem.isExecutableFile(xcodePluginServerPath) {
389-
let xcodeToolchainUsrPath = xcodeExecutableDir.parentDirectory
390-
391-
let xcodePluginPath = xcodeToolchainUsrPath
392-
.appending(components: "lib", "swift", "host", "plugins")
393-
commandLine.appendFlag(.externalPluginPath)
394-
commandLine.appendFlag(xcodePluginPath.pathString + "#" + xcodePluginServerPath.pathString)
395-
396-
let xcodeLocalPluginPath = xcodeToolchainUsrPath
397-
.appending(components: "local", "lib", "swift", "host", "plugins")
398-
commandLine.appendFlag(.externalPluginPath)
399-
commandLine.appendFlag(xcodeLocalPluginPath.pathString + "#" + xcodePluginServerPath.pathString)
400-
}
401-
}
402-
403376
guard let sdkPath = frontendTargetInfo.sdkPath?.path,
404377
let sdkInfo = getTargetSDKInfo(sdkPath: sdkPath) else { return }
405378

@@ -468,38 +441,3 @@ private extension Version {
468441
return self.description
469442
}
470443
}
471-
472-
extension DarwinToolchain {
473-
func findXcodeExecutableDir() throws -> AbsolutePath? {
474-
#if os(macOS)
475-
let result = try executor.checkNonZeroExit(
476-
args: "xcrun", "-toolchain", "default", "-f", "swiftc",
477-
environment: env
478-
).trimmingCharacters(in: .whitespacesAndNewlines)
479-
480-
guard !result.isEmpty else {
481-
return nil
482-
}
483-
return try AbsolutePath(validating: result)
484-
.parentDirectory // swiftc
485-
#else
486-
return nil
487-
#endif
488-
}
489-
490-
func findCurrentSelectedXcodeDir() throws -> AbsolutePath? {
491-
#if os(macOS)
492-
let result = try executor.checkNonZeroExit(
493-
args: "xcode-select", "-p",
494-
environment: env
495-
).trimmingCharacters(in: .whitespacesAndNewlines)
496-
497-
guard !result.isEmpty else {
498-
return nil
499-
}
500-
return try AbsolutePath(validating: result)
501-
#else
502-
return nil
503-
#endif
504-
}
505-
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6769,77 +6769,6 @@ final class SwiftDriverTests: XCTestCase {
67696769
XCTAssertTrue(job.commandLine.contains(.path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "local", "lib", "swift", "host", "plugins")))))
67706770
}
67716771

6772-
func testExternalPluginPaths() throws {
6773-
#if !os(macOS)
6774-
throw XCTSkip("Supported only in macOS")
6775-
#endif
6776-
6777-
try withTemporaryDirectory { tmpDir in
6778-
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"],
6779-
integratedDriver: false,
6780-
compilerExecutableDir: tmpDir)
6781-
guard driver.isFrontendArgSupported(.externalPluginPath) else {
6782-
return
6783-
}
6784-
6785-
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
6786-
XCTAssertEqual(jobs.count, 1)
6787-
let job = jobs.first!
6788-
6789-
// This happens only Xcode toolchain has 'swift-plugin-server' which we
6790-
// don't know.
6791-
let idx1 = job.commandLine.firstIndex(of: .flag("-external-plugin-path"))
6792-
try XCTSkipIf(idx1 == nil)
6793-
switch job.commandLine[job.commandLine.index(after: idx1!)] {
6794-
case .flag(let value):
6795-
let components = value.split(separator: "#")
6796-
if components.count == 2 {
6797-
XCTAssertTrue(components[0].hasSuffix("/usr/lib/swift/host/plugins"))
6798-
XCTAssertTrue(components[1].hasSuffix("/usr/bin/swift-plugin-server"))
6799-
} else {
6800-
XCTFail("# separated count must 2")
6801-
}
6802-
default:
6803-
XCTFail("invalid arg type after '-external-plugin-path'")
6804-
}
6805-
6806-
let idx2 = job.commandLine[job.commandLine.index(after: idx1!)...].firstIndex(of: .flag("-external-plugin-path"))
6807-
switch job.commandLine[job.commandLine.index(after: try XCTUnwrap(idx2))] {
6808-
case .flag(let value):
6809-
let components = value.split(separator: "#")
6810-
if (components.count == 2) {
6811-
XCTAssertTrue(components[0].hasSuffix("/usr/local/lib/swift/host/plugins"))
6812-
XCTAssertTrue(components[1].hasSuffix("/usr/bin/swift-plugin-server"))
6813-
} else {
6814-
XCTFail("# separated count must 2")
6815-
}
6816-
default:
6817-
XCTFail("invalid arg type after '-external-plugin-path'")
6818-
}
6819-
}
6820-
}
6821-
6822-
func testExternalPluginPathsDisabled() throws {
6823-
#if !os(macOS)
6824-
throw XCTSkip("Supported only in macOS")
6825-
#endif
6826-
6827-
try withTemporaryDirectory { tmpDir in
6828-
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"],
6829-
integratedDriver: true,
6830-
compilerExecutableDir: tmpDir)
6831-
guard driver.isFrontendArgSupported(.externalPluginPath) else {
6832-
return
6833-
}
6834-
6835-
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
6836-
XCTAssertEqual(jobs.count, 1)
6837-
let job = jobs.first!
6838-
6839-
XCTAssertFalse(job.commandLine.contains(.flag("-external-plugin-path")))
6840-
}
6841-
}
6842-
68436772
func testClangModuleValidateOnce() throws {
68446773
let flagTest = try Driver(args: ["swiftc", "-typecheck", "foo.swift"])
68456774
guard flagTest.isFrontendArgSupported(.clangBuildSessionFile),

Tests/TestUtilities/DriverExtensions.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ extension Driver {
2323
env: [String: String] = ProcessEnv.vars,
2424
diagnosticsEngine: DiagnosticsEngine = DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
2525
fileSystem: FileSystem = localFileSystem,
26-
integratedDriver: Bool = true,
27-
compilerExecutableDir: AbsolutePath? = nil
26+
integratedDriver: Bool = true
2827
) throws {
2928
let executor = try SwiftDriverExecutor(diagnosticsEngine: diagnosticsEngine,
3029
processSet: ProcessSet(),
@@ -35,8 +34,7 @@ extension Driver {
3534
diagnosticsOutput: .engine(diagnosticsEngine),
3635
fileSystem: fileSystem,
3736
executor: executor,
38-
integratedDriver: integratedDriver,
39-
compilerExecutableDir: compilerExecutableDir)
37+
integratedDriver: integratedDriver)
4038
}
4139

4240
/// For tests that need to set the sdk path.

0 commit comments

Comments
 (0)