Skip to content
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
2 changes: 1 addition & 1 deletion Sources/SWBAndroidPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public import SWBCore
import SWBMacro
import Foundation

@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
public let initializePlugin: PluginInitializationFunction = { manager in
let plugin = AndroidPlugin()
manager.register(AndroidPlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
manager.register(AndroidEnvironmentExtension(plugin: plugin), type: EnvironmentExtensionPoint.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBApplePlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import SWBProtocol
import Foundation
import SWBTaskConstruction

@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
public let initializePlugin: PluginInitializationFunction = { manager in
manager.register(AppleDeveloperDirectoryExtension(), type: DeveloperDirectoryExtensionPoint.self)
manager.register(ApplePlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
manager.register(ActoolInputFileGroupingStrategyExtension(), type: InputFileGroupingStrategyExtensionPoint.self)
Expand Down
44 changes: 28 additions & 16 deletions Sources/SWBBuildService/BuildServiceEntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,39 @@ extension BuildService {

pluginManager.register(BuiltinTaskActionsExtension(), type: TaskActionExtensionPoint.self)

let staticPluginInitializers: [PluginInitializationFunction]

// This MUST be a compile-time check because the module dependencies on the plugins are conditional.
// Minimize the amount of code that is conditionally compiled to avoid breaking the build during refactoring.
#if USE_STATIC_PLUGIN_INITIALIZATION
// Statically initialize the plugins.
SWBAndroidPlatform.initializePlugin(pluginManager)
SWBApplePlatform.initializePlugin(pluginManager)
SWBGenericUnixPlatform.initializePlugin(pluginManager)
SWBQNXPlatform.initializePlugin(pluginManager)
SWBUniversalPlatform.initializePlugin(pluginManager)
SWBWebAssemblyPlatform.initializePlugin(pluginManager)
SWBWindowsPlatform.initializePlugin(pluginManager)
staticPluginInitializers = [
SWBAndroidPlatform.initializePlugin,
SWBApplePlatform.initializePlugin,
SWBGenericUnixPlatform.initializePlugin,
SWBQNXPlatform.initializePlugin,
SWBUniversalPlatform.initializePlugin,
SWBWebAssemblyPlatform.initializePlugin,
SWBWindowsPlatform.initializePlugin,
]
#else
// Otherwise, load the normal plugins.
if let pluginsDirectory {
let pluginsPath = try pluginsDirectory.filePath
pluginManager.load(at: pluginsPath)
for subpath in (try? localFS.listdir(pluginsPath).sorted().map({ pluginsPath.join($0) })) ?? [] {
if localFS.isDirectory(subpath) {
pluginManager.load(at: subpath)
staticPluginInitializers = []
#endif

if useStaticPluginInitialization {
// Statically initialize the plugins.
staticPluginInitializers.forEach { $0(pluginManager) }
} else {
// Otherwise, load the normal plugins.
if let pluginsDirectory {
let pluginsPath = try pluginsDirectory.filePath
pluginManager.load(at: pluginsPath)
for subpath in (try? localFS.listdir(pluginsPath).sorted().map({ pluginsPath.join($0) })) ?? [] {
if localFS.isDirectory(subpath) {
pluginManager.load(at: subpath)
}
}
}
}
#endif

return pluginManager
}()
Expand Down
41 changes: 20 additions & 21 deletions Sources/SWBCore/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public final class Core: Sendable {
return nil
}

#if USE_STATIC_PLUGIN_INITIALIZATION
// In a package context, plugins are statically linked into the build system.
// Load specs from service plugins if requested since we don't have a Service in certain tests
// Here we don't have access to `core.pluginPaths` like we do in the call below,
// but it doesn't matter because it will return an empty array when USE_STATIC_PLUGIN_INITIALIZATION is defined.
await extraPluginRegistration(pluginManager, [])
#endif
if useStaticPluginInitialization {
// In a package context, plugins are statically linked into the build system.
// Load specs from service plugins if requested since we don't have a Service in certain tests
// Here we don't have access to `core.pluginPaths` like we do in the call below,
// but it doesn't matter because `core.pluginPaths` will return an empty array when USE_STATIC_PLUGIN_INITIALIZATION is defined.
await extraPluginRegistration(pluginManager, [])
}

let resolvedDeveloperPath: DeveloperPath
do {
Expand All @@ -81,6 +81,12 @@ public final class Core: Sendable {
return nil
}

if !useStaticPluginInitialization {
// In a package context, plugins are statically linked into the build system.
// Load specs from service plugins if requested since we don't have a Service in certain tests.
await extraPluginRegistration(pluginManager, Self.pluginPaths(inferiorProductsPath: inferiorProductsPath, developerPath: resolvedDeveloperPath))
}

let core: Core
do {
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)
Expand All @@ -103,12 +109,6 @@ public final class Core: Sendable {
}
}

#if !USE_STATIC_PLUGIN_INITIALIZATION
// In a package context, plugins are statically linked into the build system.
// Load specs from service plugins if requested since we don't have a Service in certain tests
await extraPluginRegistration(core.pluginManager, core.pluginPaths)
#endif

await core.initializeSpecRegistry()

await core.initializePlatformRegistry()
Expand Down Expand Up @@ -313,19 +313,19 @@ public final class Core: Sendable {
}()

/// The list of plugin search paths.
@_spi(Testing) public lazy var pluginPaths: [Path] = {
#if USE_STATIC_PLUGIN_INITIALIZATION
// In a package context, plugins are statically linked into the build system.
return []
#else
private static func pluginPaths(inferiorProductsPath: Path?, developerPath: DeveloperPath) -> [Path] {
if useStaticPluginInitialization {
// In a package context, plugins are statically linked into the build system.
return []
}

var result = [Path]()

// If we are inferior, then search the built products directory first.
//
// FIXME: This is error prone, as it won't validate that any of these are installed in the expected location.
// FIXME: If we remove, move or rename something in the built Xcode, then this will still find the old item in the installed Xcode.
if let inferiorProductsPath = self.inferiorProductsPath {
if let inferiorProductsPath {
result.append(inferiorProductsPath)
}

Expand Down Expand Up @@ -359,8 +359,7 @@ public final class Core: Sendable {
}

return result.map { $0.normalize() }
#endif
}()
}

/// The list of SDK search paths.
@_spi(Testing) public lazy var sdkPaths: [(Path, Platform?)] = {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBGenericUnixPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public import SWBUtil
import SWBCore
import Foundation

@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
public let initializePlugin: PluginInitializationFunction = { manager in
let plugin = GenericUnixPlugin()
manager.register(GenericUnixDeveloperDirectoryExtension(), type: DeveloperDirectoryExtensionPoint.self)
manager.register(GenericUnixPlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBQNXPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SWBCore
import SWBMacro
import Foundation

@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
public let initializePlugin: PluginInitializationFunction = { manager in
let plugin = QNXPlugin()
manager.register(QNXPlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
manager.register(QNXEnvironmentExtension(plugin: plugin), type: EnvironmentExtensionPoint.self)
Expand Down
42 changes: 21 additions & 21 deletions Sources/SWBTestSupport/CoreTestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,30 +140,30 @@ extension Core {
pluginManager.load(at: path)
}

let staticPluginInitializers: [String: PluginInitializationFunction]

// This MUST be a compile-time check because the module dependencies on the plugins are conditional.
// Minimize the amount of code that is conditionally compiled to avoid breaking the build during refactoring.
#if USE_STATIC_PLUGIN_INITIALIZATION
if !skipLoadingPluginsNamed.contains("com.apple.dt.SWBAndroidPlatformPlugin") {
SWBAndroidPlatform.initializePlugin(pluginManager)
}
if !skipLoadingPluginsNamed.contains("com.apple.dt.SWBApplePlatformPlugin") {
SWBApplePlatform.initializePlugin(pluginManager)
}
if !skipLoadingPluginsNamed.contains("com.apple.dt.SWBGenericUnixPlatformPlugin") {
SWBGenericUnixPlatform.initializePlugin(pluginManager)
}
if !skipLoadingPluginsNamed.contains("com.apple.dt.SWBQNXPlatformPlugin") {
SWBQNXPlatform.initializePlugin(pluginManager)
}
if !skipLoadingPluginsNamed.contains("com.apple.dt.SWBUniversalPlatformPlugin") {
SWBUniversalPlatform.initializePlugin(pluginManager)
}
if !skipLoadingPluginsNamed.contains("com.apple.dt.SWBWebAssemblyPlatformPlugin") {
SWBWebAssemblyPlatform.initializePlugin(pluginManager)
}
if !skipLoadingPluginsNamed.contains("com.apple.dt.SWBWindowsPlatformPlugin") {
SWBWindowsPlatform.initializePlugin(pluginManager)
}
staticPluginInitializers = [
"Android": SWBAndroidPlatform.initializePlugin,
"Apple": SWBApplePlatform.initializePlugin,
"GenericUnix": SWBGenericUnixPlatform.initializePlugin,
"QNX": SWBQNXPlatform.initializePlugin,
"Universal": SWBUniversalPlatform.initializePlugin,
"WebAssembly": SWBWebAssemblyPlatform.initializePlugin,
"Windows": SWBWindowsPlatform.initializePlugin,
]
#else
staticPluginInitializers = [:]
#endif

if useStaticPluginInitialization {
for (infix, initializer) in staticPluginInitializers where !skipLoadingPluginsNamed.contains("com.apple.dt.SWB\(infix)PlatformPlugin") {
initializer(pluginManager)
}
}

registerExtraPlugins(pluginManager)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBUniversalPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
import SWBTaskConstruction
import SWBTaskExecution

@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
public let initializePlugin: PluginInitializationFunction = { manager in
manager.register(UniversalPlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
manager.register(UniversalPlatformTaskProducerExtension(), type: TaskProducerExtensionPoint.self)
manager.register(UniversalPlatformTaskActionExtension(), type: TaskActionExtensionPoint.self)
Expand Down
10 changes: 10 additions & 0 deletions Sources/SWBUtil/PluginManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,13 @@ private final class ImmutablePluginManager: Sendable, PluginManager {
}
}
}

public typealias PluginInitializationFunction = @Sendable @PluginExtensionSystemActor (_ manager: MutablePluginManager) -> ()

public var useStaticPluginInitialization: Bool {
#if USE_STATIC_PLUGIN_INITIALIZATION
true
#else
false
#endif
}
2 changes: 1 addition & 1 deletion Sources/SWBWebAssemblyPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SWBCore
import SWBMacro
import Foundation

@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
public let initializePlugin: PluginInitializationFunction = { manager in
manager.register(WebAssemblyPlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
manager.register(WebAssemblyPlatformExtension(), type: PlatformInfoExtensionPoint.self)
manager.register(WebAssemblySDKRegistryExtension(), type: SDKRegistryExtensionPoint.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBWindowsPlatform/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public import SWBUtil
public import SWBCore
import Foundation

@PluginExtensionSystemActor public func initializePlugin(_ manager: MutablePluginManager) {
public let initializePlugin: PluginInitializationFunction = { manager in
let plugin = WindowsPlugin()
manager.register(WindowsDeveloperDirectoryExtension(), type: DeveloperDirectoryExtensionPoint.self)
manager.register(WindowsPlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
Expand Down