Skip to content

[6.2] Simplify fallback developer directory calculation #537

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

Merged
merged 1 commit into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 2 deletions Sources/SWBApplePlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import SWBTaskConstruction
}

struct AppleDeveloperDirectoryExtension: DeveloperDirectoryExtension {
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Path? {
try await hostOperatingSystem == .macOS ? Xcode.getActiveDeveloperDirectoryPath() : nil
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Core.DeveloperPath? {
try await hostOperatingSystem == .macOS ? .xcode(Xcode.getActiveDeveloperDirectoryPath()) : nil
}
}

Expand Down
28 changes: 10 additions & 18 deletions Sources/SWBCore/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@ public final class Core: Sendable {
delegate.error("Could not determine path to developer directory because no extensions provided a fallback value")
return nil
case 1:
let path = values[0]
if path.str.hasSuffix(".app/Contents/Developer") {
resolvedDeveloperPath = .xcode(path)
} else {
resolvedDeveloperPath = .fallback(values[0])
}
resolvedDeveloperPath = values[0]
default:
delegate.error("Could not determine path to developer directory because multiple extensions provided conflicting fallback values: \(values.sorted().map { $0.str }.joined(separator: ", "))")
delegate.error("Could not determine path to developer directory because multiple extensions provided conflicting fallback values: \(values.map { $0.path.str }.sorted().joined(separator: ", "))")
return nil
}
}
Expand Down Expand Up @@ -181,12 +176,9 @@ public final class Core: Sendable {
// A path to the root of a Swift toolchain, optionally paired with the developer path of an installed Xcode
case swiftToolchain(Path, xcodeDeveloperPath: Path?)

// A fallback resolved path.
case fallback(Path)

public var path: Path {
switch self {
case .xcode(let path), .swiftToolchain(let path, xcodeDeveloperPath: _), .fallback(let path):
case .xcode(let path), .swiftToolchain(let path, xcodeDeveloperPath: _):
return path
}
}
Expand Down Expand Up @@ -259,7 +251,7 @@ public final class Core: Sendable {
self.xcodeProductBuildVersion = ProductBuildVersion(major: 99, train: "T", build: 999)
self.xcodeProductBuildVersionString = xcodeProductBuildVersion.description
}
case .swiftToolchain, .fallback:
case .swiftToolchain:
// FIXME: Eliminate this requirment for Swift toolchains
self.xcodeVersion = Version(99, 99, 99)
self.xcodeProductBuildVersion = ProductBuildVersion(major: 99, train: "T", build: 999)
Expand All @@ -277,12 +269,14 @@ public final class Core: Sendable {
case .xcode(let path):
toolchainPaths.append((path.join("Toolchains"), strict: path.str.hasSuffix(".app/Contents/Developer")))
case .swiftToolchain(let path, xcodeDeveloperPath: let xcodeDeveloperPath):
toolchainPaths.append((path, strict: true))
if hostOperatingSystem == .windows {
toolchainPaths.append((path.join("Toolchains"), strict: true))
} else {
toolchainPaths.append((path, strict: true))
}
if let xcodeDeveloperPath {
toolchainPaths.append((xcodeDeveloperPath.join("Toolchains"), strict: xcodeDeveloperPath.str.hasSuffix(".app/Contents/Developer")))
}
case .fallback(let path):
toolchainPaths.append((path.join("Toolchains"), strict: false))
}

// FIXME: We should support building the toolchain locally (for `inferiorProductsPath`).
Expand Down Expand Up @@ -418,7 +412,7 @@ public final class Core: Sendable {
let pluginPath = path.join("usr/lib/libToolchainCASPlugin.dylib")
let plugin = try? ToolchainCASPlugin(dylib: pluginPath)
casPlugin = plugin
case .swiftToolchain, .fallback:
case .swiftToolchain:
// Unimplemented
break
}
Expand Down Expand Up @@ -454,8 +448,6 @@ public final class Core: Sendable {
} else {
searchPaths = []
}
case .fallback:
searchPaths = []
}
}
if let additionalPlatformSearchPaths = getEnvironmentVariable("XCODE_EXTRA_PLATFORM_FOLDERS") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public struct DeveloperDirectoryExtensionPoint: ExtensionPoint {
}

public protocol DeveloperDirectoryExtension: Sendable {
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Path?
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Core.DeveloperPath?
}
2 changes: 1 addition & 1 deletion Sources/SWBCore/MacroConfigFileLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ final class MacroConfigFileLoader: Sendable {
// FIXME: Move this to its proper home, and support the other special cases Xcode has (PLATFORM_DIR and SDK_DIR). This should move to using a generic facility, e.g., source trees: <rdar://problem/23576831> Add search paths for .xcconfig macros to match what Xcode has
if path.str.hasPrefix("<DEVELOPER_DIR>") {
switch developerPath {
case .xcode(let developerPath), .swiftToolchain(let developerPath, _), .fallback(let developerPath):
case .xcode(let developerPath), .swiftToolchain(let developerPath, _):
path = Path(path.str.replacingOccurrences(of: "<DEVELOPER_DIR>", with: developerPath.str))
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBCore/Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ extension WorkspaceContext {

// Add the standard search paths.
switch core.developerPath {
case .xcode(let path), .fallback(let path):
case .xcode(let path):
paths.append(path.join("usr").join("bin"))
paths.append(path.join("usr").join("local").join("bin"))
case .swiftToolchain(let path, let xcodeDeveloperPath):
Expand Down
4 changes: 2 additions & 2 deletions Sources/SWBGenericUnixPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import Foundation
}

struct GenericUnixDeveloperDirectoryExtension: DeveloperDirectoryExtension {
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Path? {
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Core.DeveloperPath? {
if hostOperatingSystem == .windows || hostOperatingSystem == .macOS {
// Handled by the Windows and Apple plugins
return nil
}

return .root
return .swiftToolchain(.root, xcodeDeveloperPath: nil)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBTestSupport/CoreTestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension Core {
if hostOperatingSystem == .macOS {
developerPath = .xcode(try await Xcode.getActiveDeveloperDirectoryPath())
} else {
developerPath = .fallback(Path.root)
developerPath = .swiftToolchain(.root, xcodeDeveloperPath: nil)
}
let delegate = TestingCoreDelegate()
return await (try Core(delegate: delegate, hostOperatingSystem: hostOperatingSystem, pluginManager: PluginManager(skipLoadingPluginIdentifiers: []), developerPath: developerPath, resourceSearchPaths: [], inferiorProductsPath: nil, additionalContentPaths: [], environment: [:], buildServiceModTime: Date(), connectionMode: .inProcess), delegate.diagnostics)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBTestSupport/DummyCommandProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ package struct MockCommandProducer: CommandProducer, Sendable {
paths.append(path)
}
switch core.developerPath {
case .xcode(let path), .fallback(let path):
case .xcode(let path):
paths.append(path.join("usr").join("bin"))
paths.append(path.join("usr").join("local").join("bin"))
case .swiftToolchain(let path, xcodeDeveloperPath: let xcodeDeveloperPath):
Expand Down
14 changes: 3 additions & 11 deletions Sources/SWBWindowsPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public final class WindowsPlugin: Sendable {
}

struct WindowsDeveloperDirectoryExtension: DeveloperDirectoryExtension {
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Path? {
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Core.DeveloperPath? {
guard hostOperatingSystem == .windows else {
return nil
}
guard let userProgramFiles = URL.userProgramFiles, let swiftPath = try? userProgramFiles.appending(component: "Swift").filePath else {
throw StubError.error("Could not determine path to user program files")
}
return swiftPath
return .swiftToolchain(swiftPath, xcodeDeveloperPath: nil)
}
}

Expand Down Expand Up @@ -94,15 +94,7 @@ struct WindowsPlatformExtension: PlatformInfoExtension {
return []
}

let platformsPath: Path
switch context.developerPath {
case .xcode(let path):
platformsPath = path.join("Platforms")
case .swiftToolchain(let path, _):
platformsPath = path.join("Platforms")
case .fallback(let path):
platformsPath = path.join("Platforms")
}
let platformsPath = context.developerPath.path.join("Platforms")
return try context.fs.listdir(platformsPath).compactMap { version in
let versionedPlatformsPath = platformsPath.join(version)
guard context.fs.isDirectory(versionedPlatformsPath) else {
Expand Down
Loading
Loading