diff --git a/Sources/Build/BuildDescription/ProductBuildDescription.swift b/Sources/Build/BuildDescription/ProductBuildDescription.swift index 185d2d4d661..bd63fa749c4 100644 --- a/Sources/Build/BuildDescription/ProductBuildDescription.swift +++ b/Sources/Build/BuildDescription/ProductBuildDescription.swift @@ -16,12 +16,6 @@ import PackageModel import OrderedCollections import SPMBuildCore -#if USE_IMPL_ONLY_IMPORTS -@_implementationOnly import DriverSupport -#else -import DriverSupport -#endif - import struct TSCBasic.SortedArray /// The build description for a product. diff --git a/Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift b/Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift index fc6c670cd15..1816daef37a 100644 --- a/Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift +++ b/Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift @@ -55,8 +55,6 @@ public final class SwiftTargetBuildDescription { /// These are the resource files derived from plugins. private var pluginDerivedResources: [Resource] - private let driverSupport = DriverSupport() - /// Path to the bundle generated for this module (if any). var bundlePath: AbsolutePath? { if let bundleName = target.underlyingTarget.potentialBundleName, needsResourceBundle { @@ -255,6 +253,7 @@ public final class SwiftTargetBuildDescription { guard target.underlyingTarget is SwiftTarget else { throw InternalError("underlying target type mismatch \(target)") } + self.package = package self.target = target self.toolsVersion = toolsVersion @@ -267,13 +266,14 @@ public final class SwiftTargetBuildDescription { } else { self.testTargetRole = nil } - self.fileSystem = fileSystem + self.tempsPath = buildParameters.buildPath.appending(component: target.c99name + ".build") self.derivedSources = Sources(paths: [], root: self.tempsPath.appending("DerivedSources")) self.buildToolPluginInvocationResults = buildToolPluginInvocationResults self.prebuildCommandResults = prebuildCommandResults self.requiredMacroProducts = requiredMacroProducts self.shouldGenerateTestObservation = shouldGenerateTestObservation + self.fileSystem = fileSystem self.observabilityScope = observabilityScope (self.pluginDerivedSources, self.pluginDerivedResources) = SharedTargetBuildDescription.computePluginGeneratedFiles( @@ -411,7 +411,7 @@ public final class SwiftTargetBuildDescription { private func packageNameArgumentIfSupported(with pkg: ResolvedPackage, packageAccess: Bool) -> [String] { let flag = "-package-name" if pkg.manifest.usePackageNameFlag, - driverSupport.checkToolchainDriverFlags(flags: [flag], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem) { + DriverSupport.checkToolchainDriverFlags(flags: [flag], toolchain: self.buildParameters.toolchain, fileSystem: self.fileSystem) { if packageAccess { let pkgID = pkg.identity.description.spm_mangledToC99ExtendedIdentifier() return [flag, pkgID] @@ -439,7 +439,7 @@ public final class SwiftTargetBuildDescription { #endif // If we're using an OSS toolchain, add the required arguments bringing in the plugin server from the default toolchain if available. - 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 { + 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 { let toolchainUsrPath = pluginServer.parentDirectory.parentDirectory let pluginPathComponents = ["lib", "swift", "host", "plugins"] diff --git a/Sources/Build/BuildManifest/LLBuildManifestBuilder.swift b/Sources/Build/BuildManifest/LLBuildManifestBuilder.swift index b465fb156dc..8f369287a3b 100644 --- a/Sources/Build/BuildManifest/LLBuildManifestBuilder.swift +++ b/Sources/Build/BuildManifest/LLBuildManifestBuilder.swift @@ -17,10 +17,8 @@ import PackageModel import SPMBuildCore #if USE_IMPL_ONLY_IMPORTS -@_implementationOnly import DriverSupport @_implementationOnly import SwiftDriver #else -import DriverSupport import SwiftDriver #endif diff --git a/Sources/Build/BuildOperation.swift b/Sources/Build/BuildOperation.swift index 0394090a68b..94b8328502a 100644 --- a/Sources/Build/BuildOperation.swift +++ b/Sources/Build/BuildOperation.swift @@ -101,8 +101,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS /// Alternative path to search for pkg-config `.pc` files. private let pkgConfigDirectories: [AbsolutePath] - private let driverSupport = DriverSupport() - public init( buildParameters: BuildParameters, cacheBuildManifest: Bool, @@ -186,7 +184,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS return } // Ensure the compiler supports the import-scan operation - guard driverSupport.checkSupportedFrontendFlags(flags: ["import-prescan"], toolchain: self.buildParameters.toolchain, fileSystem: localFileSystem) else { + guard DriverSupport.checkSupportedFrontendFlags(flags: ["import-prescan"], toolchain: self.buildParameters.toolchain, fileSystem: localFileSystem) else { return } diff --git a/Sources/Build/BuildPlan/BuildPlan.swift b/Sources/Build/BuildPlan/BuildPlan.swift index a2bcac36ac0..fadea472769 100644 --- a/Sources/Build/BuildPlan/BuildPlan.swift +++ b/Sources/Build/BuildPlan/BuildPlan.swift @@ -374,7 +374,12 @@ public class BuildPlan: SPMBuildCore.BuildPlan { // Plan the derived test targets, if necessary. if buildParameters.testingParameters.testProductStyle.requiresAdditionalDerivedTestTargets { - let derivedTestTargets = try Self.makeDerivedTestTargets(buildParameters, graph, self.fileSystem, self.observabilityScope) + let derivedTestTargets = try Self.makeDerivedTestTargets( + buildParameters, + graph, + self.fileSystem, + self.observabilityScope + ) for item in derivedTestTargets { var derivedTestTargets = [item.entryPointTargetBuildDescription.target] diff --git a/Sources/Commands/Utilities/SymbolGraphExtract.swift b/Sources/Commands/Utilities/SymbolGraphExtract.swift index e3dc9946ec2..72dda527f71 100644 --- a/Sources/Commands/Utilities/SymbolGraphExtract.swift +++ b/Sources/Commands/Utilities/SymbolGraphExtract.swift @@ -36,7 +36,6 @@ public struct SymbolGraphExtract { var includeSPISymbols = false var emitExtensionBlockSymbols = false var outputFormat = OutputFormat.json(pretty: false) - private let driverSupport = DriverSupport() /// Access control levels. public enum AccessLevel: String, RawRepresentable, CaseIterable, ExpressibleByArgument { @@ -82,7 +81,7 @@ public struct SymbolGraphExtract { } let extensionBlockSymbolsFlag = emitExtensionBlockSymbols ? "-emit-extension-block-symbols" : "-omit-extension-block-symbols" - if driverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], toolchain: buildParameters.toolchain, fileSystem: fileSystem) { + if DriverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], toolchain: buildParameters.toolchain, fileSystem: fileSystem) { commandLine += [extensionBlockSymbolsFlag] } else { observabilityScope.emit(warning: "dropped \(extensionBlockSymbolsFlag) flag because it is not supported by this compiler version") diff --git a/Sources/CoreCommands/SwiftTool.swift b/Sources/CoreCommands/SwiftTool.swift index f520d12e54f..b07894d29b3 100644 --- a/Sources/CoreCommands/SwiftTool.swift +++ b/Sources/CoreCommands/SwiftTool.swift @@ -253,8 +253,6 @@ public final class SwiftTool { fileprivate var buildSystemProvider: BuildSystemProvider? - private let driverSupport = DriverSupport() - /// Create an instance of this tool. /// /// - parameter options: The command line options to be passed to this tool. @@ -707,7 +705,7 @@ public final class SwiftTool { omitFramePointers: options.build.omitFramePointers ), driverParameters: .init( - canRenameEntrypointFunctionName: driverSupport.checkSupportedFrontendFlags( + canRenameEntrypointFunctionName: DriverSupport.checkSupportedFrontendFlags( flags: ["entry-point-function-name"], toolchain: toolchain, fileSystem: self.fileSystem @@ -859,11 +857,11 @@ public final class SwiftTool { var extraManifestFlags = self.options.build.manifestFlags // 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. - if driverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-concurrency-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) { + if DriverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-concurrency-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) { extraManifestFlags += ["-Xfrontend", "-disable-implicit-concurrency-module-import"] } // 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. - if driverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-string-processing-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) { + if DriverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-string-processing-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) { extraManifestFlags += ["-Xfrontend", "-disable-implicit-string-processing-module-import"] } diff --git a/Sources/DriverSupport/DriverSupportUtils.swift b/Sources/DriverSupport/DriverSupportUtils.swift index 238c703d8bf..9e5bf00a739 100644 --- a/Sources/DriverSupport/DriverSupportUtils.swift +++ b/Sources/DriverSupport/DriverSupportUtils.swift @@ -17,12 +17,11 @@ import class TSCBasic.Process import enum TSCBasic.ProcessEnv import struct TSCBasic.ProcessResult -public class DriverSupport { - private var flagsMap = ThreadSafeBox<[String: Set]>() - public init() {} +public enum DriverSupport { + private static var flagsMap = ThreadSafeBox<[String: Set]>() // This checks _frontend_ supported flags, which are not necessarily supported in the driver. - public func checkSupportedFrontendFlags( + public static func checkSupportedFrontendFlags( flags: Set, toolchain: PackageModel.Toolchain, fileSystem: FileSystem @@ -55,7 +54,7 @@ public class DriverSupport { // This checks if given flags are supported in the built-in toolchain driver. Currently // there's no good way to get the supported flags from it, so run `swiftc -h` directly // to get the flags and cache the result. - public func checkToolchainDriverFlags( + public static func checkToolchainDriverFlags( flags: Set, toolchain: PackageModel.Toolchain, fileSystem: FileSystem diff --git a/Sources/SPMTestSupport/misc.swift b/Sources/SPMTestSupport/misc.swift index 6b71bd90ad8..2d701640102 100644 --- a/Sources/SPMTestSupport/misc.swift +++ b/Sources/SPMTestSupport/misc.swift @@ -20,6 +20,7 @@ import PackageGraph import PackageLoading import PackageModel import SourceControl +import struct SPMBuildCore.BuildParameters import TSCTestSupport import Workspace import func XCTest.XCTFail diff --git a/Tests/BuildTests/BuildPlanTests.swift b/Tests/BuildTests/BuildPlanTests.swift index 25945e3e9e7..31540e8361b 100644 --- a/Tests/BuildTests/BuildPlanTests.swift +++ b/Tests/BuildTests/BuildPlanTests.swift @@ -12,6 +12,7 @@ @testable import Basics @testable import Build +import DriverSupport import PackageLoading @testable import PackageGraph @testable import PackageModel @@ -21,12 +22,6 @@ import SwiftDriver import Workspace import XCTest -#if USE_IMPL_ONLY_IMPORTS -@_implementationOnly import DriverSupport -#else -import DriverSupport -#endif - import struct TSCBasic.ByteString import class TSCBasic.InMemoryFileSystem @@ -34,7 +29,6 @@ import enum TSCUtility.Diagnostics final class BuildPlanTests: XCTestCase { let inputsDir = AbsolutePath(#file).parentDirectory.appending(components: "Inputs") - private let driverSupport = DriverSupport() /// The j argument. private var j: String { @@ -533,7 +527,7 @@ final class BuildPlanTests: XCTestCase { } func testPackageNameFlag() throws { - let isFlagSupportedInDriver = try driverSupport.checkToolchainDriverFlags(flags: ["package-name"], toolchain: UserToolchain.default, fileSystem: localFileSystem) + let isFlagSupportedInDriver = try DriverSupport.checkToolchainDriverFlags(flags: ["package-name"], toolchain: UserToolchain.default, fileSystem: localFileSystem) try fixture(name: "Miscellaneous/PackageNameFlag") { fixturePath in let (stdout, _) = try executeSwiftBuild(fixturePath.appending("appPkg"), extraArgs: ["-v"]) XCTAssertMatch(stdout, .contains("-module-name Foo")) @@ -555,7 +549,7 @@ final class BuildPlanTests: XCTestCase { } func testTargetsWithPackageAccess() throws { - let isFlagSupportedInDriver = try driverSupport.checkToolchainDriverFlags(flags: ["package-name"], toolchain: UserToolchain.default, fileSystem: localFileSystem) + let isFlagSupportedInDriver = try DriverSupport.checkToolchainDriverFlags(flags: ["package-name"], toolchain: UserToolchain.default, fileSystem: localFileSystem) try fixture(name: "Miscellaneous/TargetPackageAccess") { fixturePath in let (stdout, _) = try executeSwiftBuild(fixturePath.appending("libPkg"), extraArgs: ["-v"]) if isFlagSupportedInDriver { diff --git a/Tests/CommandsTests/APIDiffTests.swift b/Tests/CommandsTests/APIDiffTests.swift index ecfd6bc73f5..7ab9a5fdd20 100644 --- a/Tests/CommandsTests/APIDiffTests.swift +++ b/Tests/CommandsTests/APIDiffTests.swift @@ -13,6 +13,7 @@ import Basics import Build import Commands +import DriverSupport import Foundation import PackageModel import SourceControl @@ -20,17 +21,9 @@ import SPMTestSupport import Workspace import XCTest -#if USE_IMPL_ONLY_IMPORTS -@_implementationOnly import DriverSupport -#else -import DriverSupport -#endif - import enum TSCBasic.ProcessEnv final class APIDiffTests: CommandsTestCase { - private let driverSupport = DriverSupport() - @discardableResult private func execute( _ args: [String], @@ -61,7 +54,7 @@ final class APIDiffTests: CommandsTestCase { // not all of which can be tested for easily. Fortunately, we can test for the // `-disable-fail-on-error` option, and any version which supports this flag // will meet the other requirements. - guard driverSupport.checkSupportedFrontendFlags(flags: ["disable-fail-on-error"], toolchain: try UserToolchain.default, fileSystem: localFileSystem) else { + guard DriverSupport.checkSupportedFrontendFlags(flags: ["disable-fail-on-error"], toolchain: try UserToolchain.default, fileSystem: localFileSystem) else { throw XCTSkip("swift-api-digester is too old") } }