Skip to content

Commit cb41070

Browse files
Merge pull request #750 from jakepetroules/eng/PR-swbutil-swift6
Upgrade SWBUtil to Swift 6
2 parents 2d963f0 + e80c447 commit cb41070

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+213
-196
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ let package = Package(
209209
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .openbsd, .android, .windows, .custom("freebsd")])),
210210
],
211211
exclude: ["CMakeLists.txt"],
212-
swiftSettings: swiftSettings(languageMode: .v5)),
212+
swiftSettings: swiftSettings(languageMode: .v6)),
213213
.target(
214214
name: "SWBCAS",
215215
dependencies: ["SWBUtil", "SWBCSupport"],

Sources/SWBAndroidPlatform/Plugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public import SWBCore
1515
import SWBMacro
1616
import Foundation
1717

18-
@PluginExtensionSystemActor public func initializePlugin(_ manager: PluginManager) {
18+
@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
1919
let plugin = AndroidPlugin()
2020
manager.register(AndroidPlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
2121
manager.register(AndroidEnvironmentExtension(plugin: plugin), type: EnvironmentExtensionPoint.self)

Sources/SWBAndroidPlatformPlugin/PluginMain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ import SWBAndroidPlatform
1616

1717
@_cdecl("initializePlugin")
1818
@PluginExtensionSystemActor public func main(_ ptr: UnsafeRawPointer) {
19-
initializePlugin(Unmanaged<PluginManager>.fromOpaque(ptr).takeUnretainedValue())
19+
initializePlugin(Unmanaged<MutablePluginManager>.fromOpaque(ptr).takeUnretainedValue())
2020
}

Sources/SWBApplePlatform/Plugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import SWBProtocol
1717
import Foundation
1818
import SWBTaskConstruction
1919

20-
@PluginExtensionSystemActor public func initializePlugin(_ manager: PluginManager) {
20+
@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
2121
manager.register(AppleDeveloperDirectoryExtension(), type: DeveloperDirectoryExtensionPoint.self)
2222
manager.register(ApplePlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
2323
manager.register(ActoolInputFileGroupingStrategyExtension(), type: InputFileGroupingStrategyExtensionPoint.self)

Sources/SWBApplePlatformPlugin/PluginMain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ import SWBApplePlatform
1616

1717
@_cdecl("initializePlugin")
1818
@PluginExtensionSystemActor public func main(_ ptr: UnsafeRawPointer) {
19-
initializePlugin(Unmanaged<PluginManager>.fromOpaque(ptr).takeUnretainedValue())
19+
initializePlugin(Unmanaged<MutablePluginManager>.fromOpaque(ptr).takeUnretainedValue())
2020
}

Sources/SWBBuildService/BuildServiceEntryPoint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension BuildService {
9797
fileprivate static func run(inputFD: FileDescriptor, outputFD: FileDescriptor, connectionMode: ServiceHostConnectionMode, pluginsDirectory: URL?, arguments: [String], pluginLoadingFinished: () throws -> Void) async throws {
9898
let pluginManager = try await { @PluginExtensionSystemActor () async throws in
9999
// Create the plugin manager and load plugins.
100-
let pluginManager = PluginManager(skipLoadingPluginIdentifiers: [])
100+
let pluginManager = MutablePluginManager(skipLoadingPluginIdentifiers: [])
101101

102102
// Register plugin extension points.
103103
pluginManager.registerExtensionPoint(ServiceExtensionPoint())

Sources/SWBBuildSystem/BuildOperationExtension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ package struct BuildOperationExtensionPoint: ExtensionPoint {
2323

2424
// MARK: - actual extension point
2525

26-
package static func additionalEnvironmentVariables(pluginManager: PluginManager, fromEnvironment: @autoclosure () -> [String: String], parameters: @autoclosure () -> BuildParameters) throws -> [String: String] {
26+
package static func additionalEnvironmentVariables(pluginManager: any PluginManager, fromEnvironment: @autoclosure () -> [String: String], parameters: @autoclosure () -> BuildParameters) throws -> [String: String] {
2727
let (fromEnvironment, parameters) = (fromEnvironment(), parameters())
2828
return try pluginManager.extensions(of: Self.self).reduce([:], { environment, ext in
2929
try environment.addingContents(of: ext.additionalEnvironmentVariables(fromEnvironment: fromEnvironment, parameters: parameters))

Sources/SWBCLibc/include/SWBCLibc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include <stdio.h>
14+
15+
extern FILE * const swb_stdout();
16+
extern FILE * const swb_stderr();
17+
1318
#if defined(__linux__) && !defined(__ANDROID__)
1419
#include <fcntl.h>
1520
#include <fnmatch.h>

Sources/SWBCLibc/libc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,16 @@ int swb_clibc_anchor(void);
1818
int swb_clibc_anchor(void) {
1919
return 0;
2020
}
21+
22+
#include <stdio.h>
23+
24+
extern FILE * const swb_stdout();
25+
extern FILE * const swb_stderr();
26+
27+
FILE * const swb_stdout() {
28+
return stdout;
29+
}
30+
31+
FILE * const swb_stderr() {
32+
return stderr;
33+
}

Sources/SWBCore/Core.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public final class Core: Sendable {
4040
/// Get a configured instance of the core.
4141
///
4242
/// - returns: An initialized Core instance on which all discovery and loading will have been completed. If there are errors during that process, they will be logged to `stderr` and no instance will be returned. Otherwise, the initialized object is returned.
43-
public static func getInitializedCore(_ delegate: any CoreDelegate, pluginManager: PluginManager, developerPath: DeveloperPath? = nil, resourceSearchPaths: [Path] = [], inferiorProductsPath: Path? = nil, extraPluginRegistration: @PluginExtensionSystemActor (_ pluginPaths: [Path]) -> Void = { _ in }, additionalContentPaths: [Path] = [], environment: [String:String] = [:], buildServiceModTime: Date, connectionMode: ServiceHostConnectionMode) async -> Core? {
43+
public static func getInitializedCore(_ delegate: any CoreDelegate, pluginManager: MutablePluginManager, developerPath: DeveloperPath? = nil, resourceSearchPaths: [Path] = [], inferiorProductsPath: Path? = nil, extraPluginRegistration: @PluginExtensionSystemActor (_ pluginManager: MutablePluginManager, _ pluginPaths: [Path]) -> Void = { _, _ in }, additionalContentPaths: [Path] = [], environment: [String:String] = [:], buildServiceModTime: Date, connectionMode: ServiceHostConnectionMode) async -> Core? {
4444
// Enable macro expression interning during loading.
45-
return await MacroNamespace.withExpressionInterningEnabled {
45+
return await MacroNamespace.withExpressionInterningEnabled { () -> Core? in
4646
let hostOperatingSystem: OperatingSystem
4747
do {
4848
hostOperatingSystem = try ProcessInfo.processInfo.hostOperatingSystem()
@@ -56,7 +56,7 @@ public final class Core: Sendable {
5656
// Load specs from service plugins if requested since we don't have a Service in certain tests
5757
// Here we don't have access to `core.pluginPaths` like we do in the call below,
5858
// but it doesn't matter because it will return an empty array when USE_STATIC_PLUGIN_INITIALIZATION is defined.
59-
await extraPluginRegistration([])
59+
await extraPluginRegistration(pluginManager, [])
6060
#endif
6161

6262
let resolvedDeveloperPath: DeveloperPath
@@ -83,20 +83,20 @@ public final class Core: Sendable {
8383

8484
let core: Core
8585
do {
86-
core = try await Core(delegate: delegate, hostOperatingSystem: hostOperatingSystem, pluginManager: pluginManager, developerPath: resolvedDeveloperPath, resourceSearchPaths: resourceSearchPaths, inferiorProductsPath: inferiorProductsPath, additionalContentPaths: additionalContentPaths, environment: environment, buildServiceModTime: buildServiceModTime, connectionMode: connectionMode)
86+
core = try await Core(delegate: delegate, hostOperatingSystem: hostOperatingSystem, pluginManager: pluginManager.finalize(), developerPath: resolvedDeveloperPath, resourceSearchPaths: resourceSearchPaths, inferiorProductsPath: inferiorProductsPath, additionalContentPaths: additionalContentPaths, environment: environment, buildServiceModTime: buildServiceModTime, connectionMode: connectionMode)
8787
} catch {
8888
delegate.error("\(error)")
8989
return nil
9090
}
9191

9292
if UserDefaults.enablePluginManagerLogging {
93-
let plugins = await core.pluginManager.pluginsByIdentifier
93+
let plugins = core.pluginManager.pluginsByIdentifier
9494
delegate.emit(Diagnostic(behavior: .note, location: .unknown, data: DiagnosticData("Loaded \(plugins.count) plugins"), childDiagnostics: plugins.sorted(byKey: <).map { (identifier, plugin) in
9595
Diagnostic(behavior: .note, location: .path(plugin.path), data: DiagnosticData("Loaded plugin: \(identifier) from \(plugin.path.str)"))
9696
}))
9797
}
9898

99-
for diagnostic in await core.pluginManager.loadingDiagnostics {
99+
for diagnostic in core.pluginManager.loadingDiagnostics {
100100
// Only emit "severe" diagnostics (warning, error) from the plugin manager if the logging dwrite isn't set.
101101
if UserDefaults.enablePluginManagerLogging || [.error, .warning].contains(diagnostic.behavior) {
102102
delegate.emit(diagnostic)
@@ -106,7 +106,7 @@ public final class Core: Sendable {
106106
#if !USE_STATIC_PLUGIN_INITIALIZATION
107107
// In a package context, plugins are statically linked into the build system.
108108
// Load specs from service plugins if requested since we don't have a Service in certain tests
109-
await extraPluginRegistration(core.pluginPaths)
109+
await extraPluginRegistration(core.pluginManager, core.pluginPaths)
110110
#endif
111111

112112
await core.initializeSpecRegistry()
@@ -167,7 +167,7 @@ public final class Core: Sendable {
167167
/// The host operating system.
168168
public let hostOperatingSystem: OperatingSystem
169169

170-
public let pluginManager: PluginManager
170+
public let pluginManager: any PluginManager
171171

172172
public enum DeveloperPath: Sendable, Hashable {
173173
// A path to an Xcode install's "/Contents/Developer" directory
@@ -220,7 +220,7 @@ public final class Core: Sendable {
220220

221221
public let connectionMode: ServiceHostConnectionMode
222222

223-
@_spi(Testing) public init(delegate: any CoreDelegate, hostOperatingSystem: OperatingSystem, pluginManager: PluginManager, developerPath: DeveloperPath, resourceSearchPaths: [Path], inferiorProductsPath: Path?, additionalContentPaths: [Path], environment: [String:String], buildServiceModTime: Date, connectionMode: ServiceHostConnectionMode) async throws {
223+
@_spi(Testing) public init(delegate: any CoreDelegate, hostOperatingSystem: OperatingSystem, pluginManager: any PluginManager, developerPath: DeveloperPath, resourceSearchPaths: [Path], inferiorProductsPath: Path?, additionalContentPaths: [Path], environment: [String:String], buildServiceModTime: Date, connectionMode: ServiceHostConnectionMode) async throws {
224224
self.delegate = delegate
225225
self.hostOperatingSystem = hostOperatingSystem
226226
self.pluginManager = pluginManager
@@ -739,7 +739,7 @@ struct CoreRegistryDelegate : PlatformRegistryDelegate, SDKRegistryDelegate, Spe
739739
return specRegistry.internalMacroNamespace
740740
}
741741

742-
var pluginManager: PluginManager {
742+
var pluginManager: any PluginManager {
743743
core.pluginManager
744744
}
745745

0 commit comments

Comments
 (0)