Skip to content

Commit 02e2422

Browse files
committed
make DriverSupport a static util
1 parent 13c28f2 commit 02e2422

File tree

13 files changed

+19
-105
lines changed

13 files changed

+19
-105
lines changed

Sources/Build/BuildDescription/ProductBuildDescription.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ import PackageModel
1616
import OrderedCollections
1717
import SPMBuildCore
1818

19-
#if USE_IMPL_ONLY_IMPORTS
20-
@_implementationOnly import DriverSupport
21-
#else
22-
import DriverSupport
23-
#endif
24-
2519
import struct TSCBasic.SortedArray
2620

2721
/// The build description for a product.

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ public final class SwiftTargetBuildDescription {
5555
/// These are the resource files derived from plugins.
5656
private var pluginDerivedResources: [Resource]
5757

58-
private let driverSupport: DriverSupport
59-
6058
/// Path to the bundle generated for this module (if any).
6159
var bundlePath: AbsolutePath? {
6260
if let bundleName = target.underlyingTarget.potentialBundleName, needsResourceBundle {
@@ -249,7 +247,6 @@ public final class SwiftTargetBuildDescription {
249247
requiredMacroProducts: [ResolvedProduct] = [],
250248
testTargetRole: TestTargetRole? = nil,
251249
shouldGenerateTestObservation: Bool = false,
252-
driverSupport: DriverSupport,
253250
fileSystem: FileSystem,
254251
observabilityScope: ObservabilityScope
255252
) throws {
@@ -276,7 +273,6 @@ public final class SwiftTargetBuildDescription {
276273
self.prebuildCommandResults = prebuildCommandResults
277274
self.requiredMacroProducts = requiredMacroProducts
278275
self.shouldGenerateTestObservation = shouldGenerateTestObservation
279-
self.driverSupport = driverSupport
280276
self.fileSystem = fileSystem
281277
self.observabilityScope = observabilityScope
282278

@@ -415,7 +411,7 @@ public final class SwiftTargetBuildDescription {
415411
private func packageNameArgumentIfSupported(with pkg: ResolvedPackage, packageAccess: Bool) -> [String] {
416412
let flag = "-package-name"
417413
if pkg.manifest.usePackageNameFlag,
418-
driverSupport.checkToolchainDriverFlags(flags: [flag], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem) {
414+
DriverSupport.checkToolchainDriverFlags(flags: [flag], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem) {
419415
if packageAccess {
420416
let pkgID = pkg.identity.description.spm_mangledToC99ExtendedIdentifier()
421417
return [flag, pkgID]
@@ -443,7 +439,7 @@ public final class SwiftTargetBuildDescription {
443439
#endif
444440

445441
// If we're using an OSS toolchain, add the required arguments bringing in the plugin server from the default toolchain if available.
446-
if self.buildParameters.toolchain.isSwiftDevelopmentToolchain, driverSupport.checkSupportedFrontendFlags(flags: ["-external-plugin-path"], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem), let pluginServer = try self.buildParameters.toolchain.swiftPluginServerPath {
442+
if self.buildParameters.toolchain.isSwiftDevelopmentToolchain, DriverSupport.checkSupportedFrontendFlags(flags: ["-external-plugin-path"], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem), let pluginServer = try self.buildParameters.toolchain.swiftPluginServerPath {
447443
let toolchainUsrPath = pluginServer.parentDirectory.parentDirectory
448444
let pluginPathComponents = ["lib", "swift", "host", "plugins"]
449445

Sources/Build/BuildManifest/LLBuildManifestBuilder.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ import PackageModel
1717
import SPMBuildCore
1818

1919
#if USE_IMPL_ONLY_IMPORTS
20-
@_implementationOnly import DriverSupport
2120
@_implementationOnly import SwiftDriver
2221
#else
23-
import DriverSupport
2422
import SwiftDriver
2523
#endif
2624

Sources/Build/BuildOperation.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
101101
/// Alternative path to search for pkg-config `.pc` files.
102102
private let pkgConfigDirectories: [AbsolutePath]
103103

104-
private let driverSupport: DriverSupport
105-
106104
public init(
107105
buildParameters: BuildParameters,
108106
cacheBuildManifest: Bool,
@@ -112,7 +110,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
112110
pkgConfigDirectories: [AbsolutePath],
113111
outputStream: OutputByteStream,
114112
logLevel: Basics.Diagnostic.Severity,
115-
driverSupport: DriverSupport,
116113
fileSystem: Basics.FileSystem,
117114
observabilityScope: ObservabilityScope
118115
) {
@@ -128,7 +125,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
128125
self.pkgConfigDirectories = pkgConfigDirectories
129126
self.outputStream = outputStream
130127
self.logLevel = logLevel
131-
self.driverSupport = driverSupport
132128
self.fileSystem = fileSystem
133129
self.observabilityScope = observabilityScope.makeChildScope(description: "Build Operation")
134130
}
@@ -188,7 +184,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
188184
return
189185
}
190186
// Ensure the compiler supports the import-scan operation
191-
guard driverSupport.checkSupportedFrontendFlags(flags: ["import-prescan"], toolchain: self.buildParameters.toolchain, fileSystem: localFileSystem) else {
187+
guard DriverSupport.checkSupportedFrontendFlags(flags: ["import-prescan"], toolchain: self.buildParameters.toolchain, fileSystem: localFileSystem) else {
192188
return
193189
}
194190

@@ -441,7 +437,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
441437
pkgConfigDirectories: self.pkgConfigDirectories,
442438
outputStream: self.outputStream,
443439
logLevel: self.logLevel,
444-
driverSupport: self.driverSupport,
445440
fileSystem: self.fileSystem,
446441
observabilityScope: self.observabilityScope
447442
)
@@ -536,7 +531,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
536531
additionalFileRules: additionalFileRules,
537532
buildToolPluginInvocationResults: buildToolPluginInvocationResults,
538533
prebuildCommandResults: prebuildCommandResults,
539-
driverSupport: self.driverSupport,
540534
fileSystem: self.fileSystem,
541535
observabilityScope: self.observabilityScope
542536
)

Sources/Build/BuildPlan/BuildPlan+Test.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,10 @@ import class PackageModel.Target
2424
import struct SPMBuildCore.BuildParameters
2525
import protocol TSCBasic.FileSystem
2626

27-
#if USE_IMPL_ONLY_IMPORTS
28-
@_implementationOnly import DriverSupport
29-
#else
30-
import DriverSupport
31-
#endif
32-
3327
extension BuildPlan {
3428
static func makeDerivedTestTargets(
3529
_ buildParameters: BuildParameters,
3630
_ graph: PackageGraph,
37-
_ driverSupport: DriverSupport,
3831
_ fileSystem: FileSystem,
3932
_ observabilityScope: ObservabilityScope
4033
) throws -> [(product: ResolvedProduct, discoveryTargetBuildDescription: SwiftTargetBuildDescription?, entryPointTargetBuildDescription: SwiftTargetBuildDescription)] {
@@ -102,7 +95,6 @@ extension BuildPlan {
10295
toolsVersion: toolsVersion,
10396
buildParameters: buildParameters,
10497
testTargetRole: .discovery,
105-
driverSupport: driverSupport,
10698
fileSystem: fileSystem,
10799
observabilityScope: observabilityScope
108100
)
@@ -136,7 +128,6 @@ extension BuildPlan {
136128
toolsVersion: toolsVersion,
137129
buildParameters: buildParameters,
138130
testTargetRole: .entryPoint(isSynthesized: true),
139-
driverSupport: driverSupport,
140131
fileSystem: fileSystem,
141132
observabilityScope: observabilityScope
142133
)
@@ -166,7 +157,6 @@ extension BuildPlan {
166157
toolsVersion: toolsVersion,
167158
buildParameters: buildParameters,
168159
testTargetRole: .entryPoint(isSynthesized: false),
169-
driverSupport: driverSupport,
170160
fileSystem: fileSystem,
171161
observabilityScope: observabilityScope
172162
)
@@ -185,7 +175,6 @@ extension BuildPlan {
185175
toolsVersion: toolsVersion,
186176
buildParameters: buildParameters,
187177
testTargetRole: .entryPoint(isSynthesized: false),
188-
driverSupport: driverSupport,
189178
fileSystem: fileSystem,
190179
observabilityScope: observabilityScope
191180
)

Sources/Build/BuildPlan/BuildPlan.swift

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ import SPMBuildCore
2121

2222
#if USE_IMPL_ONLY_IMPORTS
2323
@_implementationOnly import SwiftDriver
24-
@_implementationOnly import DriverSupport
2524
#else
2625
import SwiftDriver
27-
import DriverSupport
2826
#endif
2927

3028
import enum TSCBasic.ProcessEnv
@@ -231,53 +229,26 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
231229
/// Cache for tools information.
232230
var externalExecutablesCache = [BinaryTarget: [ExecutableInfo]]()
233231

234-
/// driver support utility
235-
let driverSupport: DriverSupport
236-
237232
/// The filesystem to operate on.
238233
let fileSystem: FileSystem
239234

240235
/// ObservabilityScope with which to emit diagnostics
241236
let observabilityScope: ObservabilityScope
242237

243238
/// Create a build plan with build parameters and a package graph.
244-
public convenience init(
245-
buildParameters: BuildParameters,
246-
graph: PackageGraph,
247-
additionalFileRules: [FileRuleDescription],
248-
buildToolPluginInvocationResults: [ResolvedTarget: [BuildToolPluginInvocationResult]],
249-
prebuildCommandResults: [ResolvedTarget: [PrebuildCommandResult]],
250-
fileSystem: FileSystem,
251-
observabilityScope: ObservabilityScope
252-
) throws {
253-
try self.init(
254-
buildParameters: buildParameters,
255-
graph: graph,
256-
additionalFileRules: additionalFileRules,
257-
buildToolPluginInvocationResults: buildToolPluginInvocationResults,
258-
prebuildCommandResults: prebuildCommandResults,
259-
driverSupport: DriverSupport(), // for external use cases
260-
fileSystem: fileSystem,
261-
observabilityScope: observabilityScope
262-
)
263-
}
264-
265-
// internally we want to take DriverSupport to share across calls
266-
internal init(
239+
public init(
267240
buildParameters: BuildParameters,
268241
graph: PackageGraph,
269242
additionalFileRules: [FileRuleDescription],
270243
buildToolPluginInvocationResults: [ResolvedTarget: [BuildToolPluginInvocationResult]],
271244
prebuildCommandResults: [ResolvedTarget: [PrebuildCommandResult]],
272-
driverSupport: DriverSupport,
273245
fileSystem: FileSystem,
274246
observabilityScope: ObservabilityScope
275247
) throws {
276248
self.buildParameters = buildParameters
277249
self.graph = graph
278250
self.buildToolPluginInvocationResults = buildToolPluginInvocationResults
279251
self.prebuildCommandResults = prebuildCommandResults
280-
self.driverSupport = driverSupport
281252
self.fileSystem = fileSystem
282253
self.observabilityScope = observabilityScope.makeChildScope(description: "Build Plan")
283254

@@ -360,7 +331,6 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
360331
prebuildCommandResults: prebuildCommandResults[target] ?? [],
361332
requiredMacroProducts: requiredMacroProducts,
362333
shouldGenerateTestObservation: generateTestObservation,
363-
driverSupport: driverSupport,
364334
fileSystem: fileSystem,
365335
observabilityScope: observabilityScope)
366336
)
@@ -407,7 +377,6 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
407377
let derivedTestTargets = try Self.makeDerivedTestTargets(
408378
buildParameters,
409379
graph,
410-
self.driverSupport,
411380
self.fileSystem,
412381
self.observabilityScope
413382
)

Sources/Commands/Utilities/SymbolGraphExtract.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public struct SymbolGraphExtract {
3636
var includeSPISymbols = false
3737
var emitExtensionBlockSymbols = false
3838
var outputFormat = OutputFormat.json(pretty: false)
39-
private let driverSupport = DriverSupport()
4039

4140
/// Access control levels.
4241
public enum AccessLevel: String, RawRepresentable, CaseIterable, ExpressibleByArgument {
@@ -82,7 +81,7 @@ public struct SymbolGraphExtract {
8281
}
8382

8483
let extensionBlockSymbolsFlag = emitExtensionBlockSymbols ? "-emit-extension-block-symbols" : "-omit-extension-block-symbols"
85-
if driverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], toolchain: buildParameters.toolchain, fileSystem: fileSystem) {
84+
if DriverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], toolchain: buildParameters.toolchain, fileSystem: fileSystem) {
8685
commandLine += [extensionBlockSymbolsFlag]
8786
} else {
8887
observabilityScope.emit(warning: "dropped \(extensionBlockSymbolsFlag) flag because it is not supported by this compiler version")

Sources/CoreCommands/BuildSystemSupport.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ private struct NativeBuildSystemFactory: BuildSystemFactory {
4646
pkgConfigDirectories: self.swiftTool.options.locations.pkgConfigDirectories,
4747
outputStream: customOutputStream ?? self.swiftTool.outputStream,
4848
logLevel: customLogLevel ?? self.swiftTool.logLevel,
49-
driverSupport: self.swiftTool.driverSupport,
5049
fileSystem: self.swiftTool.fileSystem,
5150
observabilityScope: customObservabilityScope ?? self.swiftTool.observabilityScope)
5251
}

Sources/CoreCommands/SwiftTool.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ public final class SwiftTool {
240240
// should use sandbox on external subcommands
241241
public var shouldDisableSandbox: Bool
242242

243-
/// The driver support utility
244-
public let driverSupport = DriverSupport()
245-
246243
/// The file system in use
247244
public let fileSystem: FileSystem
248245

@@ -708,7 +705,7 @@ public final class SwiftTool {
708705
omitFramePointers: options.build.omitFramePointers
709706
),
710707
driverParameters: .init(
711-
canRenameEntrypointFunctionName: driverSupport.checkSupportedFrontendFlags(
708+
canRenameEntrypointFunctionName: DriverSupport.checkSupportedFrontendFlags(
712709
flags: ["entry-point-function-name"],
713710
toolchain: toolchain,
714711
fileSystem: self.fileSystem
@@ -850,11 +847,11 @@ public final class SwiftTool {
850847

851848
var extraManifestFlags = self.options.build.manifestFlags
852849
// Disable the implicit concurrency import if the compiler in use supports it to avoid warnings if we are building against an older SDK that does not contain a Concurrency module.
853-
if driverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-concurrency-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) {
850+
if DriverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-concurrency-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) {
854851
extraManifestFlags += ["-Xfrontend", "-disable-implicit-concurrency-module-import"]
855852
}
856853
// Disable the implicit string processing import if the compiler in use supports it to avoid warnings if we are building against an older SDK that does not contain a StringProcessing module.
857-
if driverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-string-processing-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) {
854+
if DriverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-string-processing-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) {
858855
extraManifestFlags += ["-Xfrontend", "-disable-implicit-string-processing-module-import"]
859856
}
860857

Sources/DriverSupport/DriverSupportUtils.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import class TSCBasic.Process
1717
import enum TSCBasic.ProcessEnv
1818
import struct TSCBasic.ProcessResult
1919

20-
public class DriverSupport {
21-
private var flagsMap = ThreadSafeBox<[String: Set<String>]>()
22-
public init() {}
20+
21+
public enum DriverSupport {
22+
private static var flagsMap = ThreadSafeBox<[String: Set<String>]>()
23+
//public init() {}
2324

2425
// This checks _frontend_ supported flags, which are not necessarily supported in the driver.
25-
public func checkSupportedFrontendFlags(
26+
public static func checkSupportedFrontendFlags(
2627
flags: Set<String>,
2728
toolchain: PackageModel.Toolchain,
2829
fileSystem: FileSystem
@@ -55,7 +56,7 @@ public class DriverSupport {
5556
// This checks if given flags are supported in the built-in toolchain driver. Currently
5657
// there's no good way to get the supported flags from it, so run `swiftc -h` directly
5758
// to get the flags and cache the result.
58-
public func checkToolchainDriverFlags(
59+
public static func checkToolchainDriverFlags(
5960
flags: Set<String>,
6061
toolchain: PackageModel.Toolchain,
6162
fileSystem: FileSystem

Sources/swift-bootstrap/main.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ import var TSCBasic.stdoutStream
2929
import enum TSCUtility.Diagnostics
3030
import struct TSCUtility.Version
3131

32-
#if USE_IMPL_ONLY_IMPORTS
33-
@_implementationOnly import DriverSupport
34-
#else
35-
import DriverSupport
36-
#endif
37-
3832
SwiftBootstrapBuildTool.main()
3933

4034
struct SwiftBootstrapBuildTool: ParsableCommand {
@@ -211,7 +205,6 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
211205
let dependencyMapper: DependencyMapper
212206
let hostToolchain: UserToolchain
213207
let targetToolchain: UserToolchain
214-
let driverSupport: DriverSupport
215208
let fileSystem: FileSystem
216209
let observabilityScope: ObservabilityScope
217210
let logLevel: Basics.Diagnostic.Severity
@@ -230,7 +223,6 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
230223
self.dependencyMapper = DefaultDependencyMapper(identityResolver: self.identityResolver)
231224
self.hostToolchain = try UserToolchain(swiftSDK: SwiftSDK.hostSwiftSDK(originalWorkingDirectory: cwd))
232225
self.targetToolchain = hostToolchain // TODO: support cross-compilation?
233-
self.driverSupport = DriverSupport()
234226
self.fileSystem = fileSystem
235227
self.observabilityScope = observabilityScope
236228
self.logLevel = logLevel
@@ -323,7 +315,6 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
323315
pkgConfigDirectories: [],
324316
outputStream: TSCBasic.stdoutStream,
325317
logLevel: logLevel,
326-
driverSupport: self.driverSupport,
327318
fileSystem: self.fileSystem,
328319
observabilityScope: self.observabilityScope
329320
)

0 commit comments

Comments
 (0)