Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[Macros] Set -external-plugin-path when the toolchain is not Xcode" #1359

Merged
merged 4 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
62 changes: 0 additions & 62 deletions Sources/SwiftDriver/Toolchains/DarwinToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,33 +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.integratedDriver,
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 }

Expand Down Expand Up @@ -468,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
}
}
71 changes: 0 additions & 71 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6769,77 +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"],
integratedDriver: false,
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 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),
Expand Down
6 changes: 2 additions & 4 deletions Tests/TestUtilities/DriverExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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.
Expand Down