Skip to content

Commit 95575f4

Browse files
kcieplakowenv
authored andcommitted
Search in registered platforms for linkers.
* Make the executableSearchPaths for a platform a StackedSearchPath so we can more easily search for things. * Search the regisitered platforms for linkers as well as toolchains. * Small workaround to avoid finding linkers in XCode SDKs.
1 parent 6c99d13 commit 95575f4

File tree

6 files changed

+56
-22
lines changed

6 files changed

+56
-22
lines changed

Sources/SWBCore/Core.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ public final class Core: Sendable {
306306

307307
// Search the default location first (unless directed not to), then search any extra locations we've been passed.
308308
var searchPaths: [Path]
309+
let fs = localFS
309310
if let onlySearchAdditionalPlatformPaths = getEnvironmentVariable("XCODE_ONLY_EXTRA_PLATFORM_FOLDERS"), onlySearchAdditionalPlatformPaths.boolValue {
310311
searchPaths = []
311312
}
@@ -324,7 +325,7 @@ public final class Core: Sendable {
324325
}
325326
}
326327
searchPaths += UserDefaults.additionalPlatformSearchPaths
327-
return PlatformRegistry(delegate: self.registryDelegate, searchPaths: searchPaths, hostOperatingSystem: hostOperatingSystem)
328+
return PlatformRegistry(delegate: self.registryDelegate, searchPaths: searchPaths, hostOperatingSystem: hostOperatingSystem, fs: fs)
328329
}()
329330

330331
@PluginExtensionSystemActor public var loadedPluginPaths: [Path] {

Sources/SWBCore/PlatformRegistry.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ public final class Platform: Sendable {
180180
@_spi(Testing) public var sdks: [SDK] = []
181181

182182
/// The list of executable search paths in the platform.
183-
@_spi(Testing) public var executableSearchPaths: [Path]
183+
@_spi(Testing) public var executableSearchPaths: StackedSearchPath
184184

185-
init(_ name: String, _ displayName: String, _ familyName: String, _ familyDisplayName: String?, _ identifier: String, _ devicePlatformName: String?, _ simulatorPlatformName: String?, _ path: Path, _ version: String?, _ productBuildVersion: String?, _ defaultSettings: [String: PropertyListItem], _ additionalInfoPlistEntries: [String: PropertyListItem], _ isDeploymentPlatform: Bool, _ specRegistryProvider: any SpecRegistryProvider, preferredArchValue: String?, executableSearchPaths: [Path]) {
185+
init(_ name: String, _ displayName: String, _ familyName: String, _ familyDisplayName: String?, _ identifier: String, _ devicePlatformName: String?, _ simulatorPlatformName: String?, _ path: Path, _ version: String?, _ productBuildVersion: String?, _ defaultSettings: [String: PropertyListItem], _ additionalInfoPlistEntries: [String: PropertyListItem], _ isDeploymentPlatform: Bool, _ specRegistryProvider: any SpecRegistryProvider, preferredArchValue: String?, executableSearchPaths: [Path], fs: any FSProxy) {
186186
self.name = name
187187
self.displayName = displayName
188188
self.familyName = familyName
@@ -198,7 +198,7 @@ public final class Platform: Sendable {
198198
self.isDeploymentPlatform = isDeploymentPlatform
199199
self.specRegistryProvider = specRegistryProvider
200200
self.preferredArch = preferredArchValue
201-
self.executableSearchPaths = executableSearchPaths
201+
self.executableSearchPaths = StackedSearchPath(paths: executableSearchPaths, fs: fs)
202202
self.sdkCanonicalName = name
203203
}
204204

@@ -319,16 +319,16 @@ public final class PlatformRegistry {
319319
})
320320
}
321321

322-
@_spi(Testing) public init(delegate: any PlatformRegistryDelegate, searchPaths: [Path], hostOperatingSystem: OperatingSystem) {
322+
@_spi(Testing) public init(delegate: any PlatformRegistryDelegate, searchPaths: [Path], hostOperatingSystem: OperatingSystem, fs: any FSProxy) {
323323
self.delegate = delegate
324324

325325
for path in searchPaths {
326-
registerPlatformsInDirectory(path)
326+
registerPlatformsInDirectory(path, fs)
327327
}
328328

329329
do {
330330
if hostOperatingSystem.createFallbackSystemToolchain {
331-
try registerFallbackSystemPlatform(operatingSystem: hostOperatingSystem)
331+
try registerFallbackSystemPlatform(operatingSystem: hostOperatingSystem, fs: fs)
332332
}
333333
} catch {
334334
delegate.error(error)
@@ -340,13 +340,13 @@ public final class PlatformRegistry {
340340

341341
for platformExtension in platformInfoExtensions() {
342342
for (path, data) in platformExtension.additionalPlatforms() {
343-
registerPlatform(path, .plDict(data))
343+
registerPlatform(path, .plDict(data), fs)
344344
}
345345
}
346346
}
347347

348-
private func registerFallbackSystemPlatform(operatingSystem: OperatingSystem) throws {
349-
try registerPlatform(Path("/"), .plDict(fallbackSystemPlatformSettings(operatingSystem: operatingSystem)))
348+
private func registerFallbackSystemPlatform(operatingSystem: OperatingSystem, fs: any FSProxy) throws {
349+
try registerPlatform(Path("/"), .plDict(fallbackSystemPlatformSettings(operatingSystem: operatingSystem)), fs)
350350
}
351351

352352
private func fallbackSystemPlatformSettings(operatingSystem: OperatingSystem) throws -> [String: PropertyListItem] {
@@ -413,7 +413,7 @@ public final class PlatformRegistry {
413413
}
414414

415415
/// Register all platforms in the given directory.
416-
private func registerPlatformsInDirectory(_ path: Path) {
416+
private func registerPlatformsInDirectory(_ path: Path, _ fs: any FSProxy) {
417417
for item in (try? localFS.listdir(path))?.sorted(by: <) ?? [] {
418418
let itemPath = path.join(item)
419419

@@ -431,15 +431,14 @@ public final class PlatformRegistry {
431431
// Silently skip loading the platform if it does not have an Info.plist at all. (We will still error below if it has an Info.plist which is malformed.)
432432
continue
433433
}
434-
435-
registerPlatform(itemPath, infoPlist)
434+
registerPlatform(itemPath, infoPlist, fs)
436435
} catch let err {
437436
delegate.error(itemPath, "unable to load platform: 'Info.plist' was malformed: \(err)")
438437
}
439438
}
440439
}
441440

442-
private func registerPlatform(_ path: Path, _ data: PropertyListItem) {
441+
private func registerPlatform(_ path: Path, _ data: PropertyListItem, _ fs: any FSProxy) {
443442
// The data should always be a dictionary.
444443
guard case .plDict(var items) = data else {
445444
delegate.error(path, "unexpected platform data")
@@ -635,7 +634,7 @@ public final class PlatformRegistry {
635634
])
636635

637636
// FIXME: Need to parse other fields. It would also be nice to diagnose unused keys like we do for Spec data (and we might want to just use the spec parser here).
638-
let platform = Platform(name, displayName, familyName, familyDisplayName, identifier, devicePlatformName, simulatorPlatformName, path, version, productBuildVersion, defaultSettings, additionalInfoPlistEntries, isDeploymentPlatform, delegate, preferredArchValue: preferredArchValue, executableSearchPaths: executableSearchPaths)
637+
let platform = Platform(name, displayName, familyName, familyDisplayName, identifier, devicePlatformName, simulatorPlatformName, path, version, productBuildVersion, defaultSettings, additionalInfoPlistEntries, isDeploymentPlatform, delegate, preferredArchValue: preferredArchValue, executableSearchPaths: executableSearchPaths, fs: fs)
639638
if let duplicatePlatform = platformsByIdentifier[identifier] {
640639
delegate.error(path, "platform '\(identifier)' already registered from \(duplicatePlatform.path.str)")
641640
return

Sources/SWBCore/Settings/Settings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ extension WorkspaceContext {
10151015
}
10161016

10171017
// Add the platform search paths.
1018-
for path in platform?.executableSearchPaths ?? [] {
1018+
for path in platform?.executableSearchPaths.paths ?? [] {
10191019
paths.append(path)
10201020
}
10211021

Sources/SWBTestSupport/CoreBasedTests.swift

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,15 @@ extension CoreBasedTests {
261261
package var ldPath: Path? {
262262
get async throws {
263263
let (core, defaultToolchain) = try await coreAndToolchain()
264-
return defaultToolchain.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld")
264+
if let executable = defaultToolchain.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld") {
265+
return executable
266+
}
267+
for platform in core.platformRegistry.platforms {
268+
if let executable = platform.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld") {
269+
return executable
270+
}
271+
}
272+
return nil
265273
}
266274
}
267275
package var linkPath: Path? {
@@ -271,19 +279,45 @@ extension CoreBasedTests {
271279
// Most unixes have a link executable, but that is not a linker
272280
return nil
273281
}
274-
return defaultToolchain.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "link")
282+
if let executable = defaultToolchain.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "link") {
283+
return executable
284+
}
285+
for platform in core.platformRegistry.platforms {
286+
if let executable = platform.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "link") {
287+
return executable
288+
}
289+
}
290+
return nil
275291
}
276292
}
293+
277294
package var lldPath: Path? {
278295
get async throws {
279296
let (core, defaultToolchain) = try await coreAndToolchain()
280-
return defaultToolchain.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld.lld")
297+
if let executable = defaultToolchain.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld.ld") {
298+
return executable
299+
}
300+
for platform in core.platformRegistry.platforms {
301+
if let executable = platform.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld.ld") {
302+
return executable
303+
}
304+
}
305+
return nil
281306
}
282307
}
308+
283309
package var goldPath: Path? {
284310
get async throws {
285311
let (core, defaultToolchain) = try await coreAndToolchain()
286-
return defaultToolchain.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld.gold")
312+
if let executable = defaultToolchain.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld.gold") {
313+
return executable
314+
}
315+
for platform in core.platformRegistry.platforms {
316+
if let executable = platform.executableSearchPaths.findExecutable(operatingSystem: core.hostOperatingSystem, basename: "ld.gold") {
317+
return executable
318+
}
319+
}
320+
return nil
287321
}
288322
}
289323
}

Sources/SWBTestSupport/DummyCommandProducer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ package struct MockCommandProducer: CommandProducer, Sendable {
5656
for path in core.toolchainRegistry.defaultToolchain?.executableSearchPaths.paths ?? [] {
5757
paths.append(path)
5858
}
59-
for path in platform?.executableSearchPaths ?? [] {
59+
for path in platform?.executableSearchPaths.paths ?? [] {
6060
paths.append(path)
6161
}
6262
paths.append(core.developerPath.join("usr").join("bin"))

Tests/SWBCoreTests/PlatformRegistryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import SWBMacro
6666
}
6767

6868
let delegate = await TestDataDelegate(pluginManager: PluginManager(skipLoadingPluginIdentifiers: []))
69-
let registry = PlatformRegistry(delegate: delegate, searchPaths: [tmpDirPath], hostOperatingSystem: try ProcessInfo.processInfo.hostOperatingSystem())
69+
let registry = PlatformRegistry(delegate: delegate, searchPaths: [tmpDirPath], hostOperatingSystem: try ProcessInfo.processInfo.hostOperatingSystem(), fs: localFS)
7070
try await perform(registry, delegate)
7171
}
7272
}

0 commit comments

Comments
 (0)