Skip to content

Commit be93573

Browse files
committed
Simplify fallback developer directory calculation
Have the fallback logic specify the type of developer directory as well as just the location, and eliminate the initialization distinction on whether a Core was initialized with a "fallback" path vs one explicitly given, since it shouldn't matter.
1 parent 724c104 commit be93573

File tree

12 files changed

+83
-87
lines changed

12 files changed

+83
-87
lines changed

Sources/SWBApplePlatform/Plugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import SWBTaskConstruction
3131
}
3232

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

Sources/SWBCore/Core.swift

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,9 @@ public final class Core: Sendable {
7070
delegate.error("Could not determine path to developer directory because no extensions provided a fallback value")
7171
return nil
7272
case 1:
73-
let path = values[0]
74-
if path.str.hasSuffix(".app/Contents/Developer") {
75-
resolvedDeveloperPath = .xcode(path)
76-
} else {
77-
resolvedDeveloperPath = .fallback(values[0])
78-
}
73+
resolvedDeveloperPath = values[0]
7974
default:
80-
delegate.error("Could not determine path to developer directory because multiple extensions provided conflicting fallback values: \(values.sorted().map { $0.str }.joined(separator: ", "))")
75+
delegate.error("Could not determine path to developer directory because multiple extensions provided conflicting fallback values: \(values.map { $0.path.str }.sorted().joined(separator: ", "))")
8176
return nil
8277
}
8378
}
@@ -181,12 +176,9 @@ public final class Core: Sendable {
181176
// A path to the root of a Swift toolchain, optionally paired with the developer path of an installed Xcode
182177
case swiftToolchain(Path, xcodeDeveloperPath: Path?)
183178

184-
// A fallback resolved path.
185-
case fallback(Path)
186-
187179
public var path: Path {
188180
switch self {
189-
case .xcode(let path), .swiftToolchain(let path, xcodeDeveloperPath: _), .fallback(let path):
181+
case .xcode(let path), .swiftToolchain(let path, xcodeDeveloperPath: _):
190182
return path
191183
}
192184
}
@@ -259,7 +251,7 @@ public final class Core: Sendable {
259251
self.xcodeProductBuildVersion = ProductBuildVersion(major: 99, train: "T", build: 999)
260252
self.xcodeProductBuildVersionString = xcodeProductBuildVersion.description
261253
}
262-
case .swiftToolchain, .fallback:
254+
case .swiftToolchain:
263255
// FIXME: Eliminate this requirment for Swift toolchains
264256
self.xcodeVersion = Version(99, 99, 99)
265257
self.xcodeProductBuildVersion = ProductBuildVersion(major: 99, train: "T", build: 999)
@@ -277,12 +269,14 @@ public final class Core: Sendable {
277269
case .xcode(let path):
278270
toolchainPaths.append((path.join("Toolchains"), strict: path.str.hasSuffix(".app/Contents/Developer")))
279271
case .swiftToolchain(let path, xcodeDeveloperPath: let xcodeDeveloperPath):
280-
toolchainPaths.append((path, strict: true))
272+
if hostOperatingSystem == .windows {
273+
toolchainPaths.append((path.join("Toolchains"), strict: true))
274+
} else {
275+
toolchainPaths.append((path, strict: true))
276+
}
281277
if let xcodeDeveloperPath {
282278
toolchainPaths.append((xcodeDeveloperPath.join("Toolchains"), strict: xcodeDeveloperPath.str.hasSuffix(".app/Contents/Developer")))
283279
}
284-
case .fallback(let path):
285-
toolchainPaths.append((path.join("Toolchains"), strict: false))
286280
}
287281

288282
// FIXME: We should support building the toolchain locally (for `inferiorProductsPath`).
@@ -418,7 +412,7 @@ public final class Core: Sendable {
418412
let pluginPath = path.join("usr/lib/libToolchainCASPlugin.dylib")
419413
let plugin = try? ToolchainCASPlugin(dylib: pluginPath)
420414
casPlugin = plugin
421-
case .swiftToolchain, .fallback:
415+
case .swiftToolchain:
422416
// Unimplemented
423417
break
424418
}
@@ -454,8 +448,6 @@ public final class Core: Sendable {
454448
} else {
455449
searchPaths = []
456450
}
457-
case .fallback:
458-
searchPaths = []
459451
}
460452
}
461453
if let additionalPlatformSearchPaths = getEnvironmentVariable("XCODE_EXTRA_PLATFORM_FOLDERS") {

Sources/SWBCore/Extensions/DeveloperDirectoryExtension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ public struct DeveloperDirectoryExtensionPoint: ExtensionPoint {
2121
}
2222

2323
public protocol DeveloperDirectoryExtension: Sendable {
24-
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Path?
24+
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Core.DeveloperPath?
2525
}

Sources/SWBCore/MacroConfigFileLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ final class MacroConfigFileLoader: Sendable {
133133
// 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
134134
if path.str.hasPrefix("<DEVELOPER_DIR>") {
135135
switch developerPath {
136-
case .xcode(let developerPath), .swiftToolchain(let developerPath, _), .fallback(let developerPath):
136+
case .xcode(let developerPath), .swiftToolchain(let developerPath, _):
137137
path = Path(path.str.replacingOccurrences(of: "<DEVELOPER_DIR>", with: developerPath.str))
138138
}
139139
}

Sources/SWBCore/Settings/Settings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ extension WorkspaceContext {
10261026

10271027
// Add the standard search paths.
10281028
switch core.developerPath {
1029-
case .xcode(let path), .fallback(let path):
1029+
case .xcode(let path):
10301030
paths.append(path.join("usr").join("bin"))
10311031
paths.append(path.join("usr").join("local").join("bin"))
10321032
case .swiftToolchain(let path, let xcodeDeveloperPath):

Sources/SWBGenericUnixPlatform/Plugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import Foundation
2323
}
2424

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

32-
return .root
32+
return .swiftToolchain(.root, xcodeDeveloperPath: nil)
3333
}
3434
}
3535

Sources/SWBTestSupport/CoreTestSupport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension Core {
3838
if hostOperatingSystem == .macOS {
3939
developerPath = .xcode(try await Xcode.getActiveDeveloperDirectoryPath())
4040
} else {
41-
developerPath = .fallback(Path.root)
41+
developerPath = .swiftToolchain(.root, xcodeDeveloperPath: nil)
4242
}
4343
let delegate = TestingCoreDelegate()
4444
return await (try Core(delegate: delegate, hostOperatingSystem: hostOperatingSystem, pluginManager: PluginManager(skipLoadingPluginIdentifiers: []), developerPath: developerPath, resourceSearchPaths: [], inferiorProductsPath: nil, additionalContentPaths: [], environment: [:], buildServiceModTime: Date(), connectionMode: .inProcess), delegate.diagnostics)

Sources/SWBTestSupport/DummyCommandProducer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ package struct MockCommandProducer: CommandProducer, Sendable {
6060
paths.append(path)
6161
}
6262
switch core.developerPath {
63-
case .xcode(let path), .fallback(let path):
63+
case .xcode(let path):
6464
paths.append(path.join("usr").join("bin"))
6565
paths.append(path.join("usr").join("local").join("bin"))
6666
case .swiftToolchain(let path, xcodeDeveloperPath: let xcodeDeveloperPath):

Sources/SWBWindowsPlatform/Plugin.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ public final class WindowsPlugin: Sendable {
5353
}
5454

5555
struct WindowsDeveloperDirectoryExtension: DeveloperDirectoryExtension {
56-
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Path? {
56+
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Core.DeveloperPath? {
5757
guard hostOperatingSystem == .windows else {
5858
return nil
5959
}
6060
guard let userProgramFiles = URL.userProgramFiles, let swiftPath = try? userProgramFiles.appending(component: "Swift").filePath else {
6161
throw StubError.error("Could not determine path to user program files")
6262
}
63-
return swiftPath
63+
return .swiftToolchain(swiftPath, xcodeDeveloperPath: nil)
6464
}
6565
}
6666

@@ -94,15 +94,7 @@ struct WindowsPlatformExtension: PlatformInfoExtension {
9494
return []
9595
}
9696

97-
let platformsPath: Path
98-
switch context.developerPath {
99-
case .xcode(let path):
100-
platformsPath = path.join("Platforms")
101-
case .swiftToolchain(let path, _):
102-
platformsPath = path.join("Platforms")
103-
case .fallback(let path):
104-
platformsPath = path.join("Platforms")
105-
}
97+
let platformsPath = context.developerPath.path.join("Platforms")
10698
return try context.fs.listdir(platformsPath).compactMap { version in
10799
let versionedPlatformsPath = platformsPath.join(version)
108100
guard context.fs.isDirectory(versionedPlatformsPath) else {

0 commit comments

Comments
 (0)