Skip to content

Commit 9763820

Browse files
authored
Merge pull request #1360 from rintaro/5.9-revert-external-plugin-path
[5.9] Revert "[Macros] Set -external-plugin-path when the toolchain is not Xcode"
2 parents 2938a1d + cf9eb1e commit 9763820

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
@@ -6727,77 +6727,6 @@ final class SwiftDriverTests: XCTestCase {
67276727
XCTAssertTrue(job.commandLine.contains(.path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "local", "lib", "swift", "host", "plugins")))))
67286728
}
67296729

6730-
func testExternalPluginPaths() throws {
6731-
#if !os(macOS)
6732-
throw XCTSkip("Supported only in macOS")
6733-
#endif
6734-
6735-
try withTemporaryDirectory { tmpDir in
6736-
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"],
6737-
integratedDriver: false,
6738-
compilerExecutableDir: tmpDir)
6739-
guard driver.isFrontendArgSupported(.externalPluginPath) else {
6740-
return
6741-
}
6742-
6743-
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
6744-
XCTAssertEqual(jobs.count, 1)
6745-
let job = jobs.first!
6746-
6747-
// This happens only Xcode toolchain has 'swift-plugin-server' which we
6748-
// don't know.
6749-
let idx1 = job.commandLine.firstIndex(of: .flag("-external-plugin-path"))
6750-
try XCTSkipIf(idx1 == nil)
6751-
switch job.commandLine[job.commandLine.index(after: idx1!)] {
6752-
case .flag(let value):
6753-
let components = value.split(separator: "#")
6754-
if components.count == 2 {
6755-
XCTAssertTrue(components[0].hasSuffix("/usr/lib/swift/host/plugins"))
6756-
XCTAssertTrue(components[1].hasSuffix("/usr/bin/swift-plugin-server"))
6757-
} else {
6758-
XCTFail("# separated count must 2")
6759-
}
6760-
default:
6761-
XCTFail("invalid arg type after '-external-plugin-path'")
6762-
}
6763-
6764-
let idx2 = job.commandLine[job.commandLine.index(after: idx1!)...].firstIndex(of: .flag("-external-plugin-path"))
6765-
switch job.commandLine[job.commandLine.index(after: try XCTUnwrap(idx2))] {
6766-
case .flag(let value):
6767-
let components = value.split(separator: "#")
6768-
if (components.count == 2) {
6769-
XCTAssertTrue(components[0].hasSuffix("/usr/local/lib/swift/host/plugins"))
6770-
XCTAssertTrue(components[1].hasSuffix("/usr/bin/swift-plugin-server"))
6771-
} else {
6772-
XCTFail("# separated count must 2")
6773-
}
6774-
default:
6775-
XCTFail("invalid arg type after '-external-plugin-path'")
6776-
}
6777-
}
6778-
}
6779-
6780-
func testExternalPluginPathsDisabled() throws {
6781-
#if !os(macOS)
6782-
throw XCTSkip("Supported only in macOS")
6783-
#endif
6784-
6785-
try withTemporaryDirectory { tmpDir in
6786-
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"],
6787-
integratedDriver: true,
6788-
compilerExecutableDir: tmpDir)
6789-
guard driver.isFrontendArgSupported(.externalPluginPath) else {
6790-
return
6791-
}
6792-
6793-
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
6794-
XCTAssertEqual(jobs.count, 1)
6795-
let job = jobs.first!
6796-
6797-
XCTAssertFalse(job.commandLine.contains(.flag("-external-plugin-path")))
6798-
}
6799-
}
6800-
68016730
func testClangModuleValidateOnce() throws {
68026731
let flagTest = try Driver(args: ["swiftc", "-typecheck", "foo.swift"])
68036732
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
diagnosticsEngine: 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)