diff --git a/Sources/Commands/SwiftTool.swift b/Sources/Commands/SwiftTool.swift index 0f93f164e8f..906e757a626 100644 --- a/Sources/Commands/SwiftTool.swift +++ b/Sources/Commands/SwiftTool.swift @@ -644,7 +644,7 @@ public class SwiftTool { // The `cache` directory is in the plugins directory and is where the plugin script runner caches // compiled plugin binaries and any other derived information. let cacheDir = pluginsDir.appending(component: "cache") - let pluginScriptRunner = try DefaultPluginScriptRunner(cacheDir: cacheDir, manifestResources: self._hostToolchain.get().manifestResources) + let pluginScriptRunner = try DefaultPluginScriptRunner(cacheDir: cacheDir, toolchain: self._hostToolchain.get().configuration) // The `outputs` directory contains subdirectories for each combination of package, target, and plugin. // Each usage of a plugin has an output directory that is writable by the plugin, where it can write @@ -873,7 +873,7 @@ public class SwiftTool { return try ManifestLoader( // Always use the host toolchain's resources for parsing manifest. - manifestResources: self._hostToolchain.get().manifestResources, + toolchain: self._hostToolchain.get().configuration, isManifestSandboxEnabled: !self.options.shouldDisableSandbox, cacheDir: cachePath, extraManifestFlags: extraManifestFlags diff --git a/Sources/PackageLoading/CMakeLists.txt b/Sources/PackageLoading/CMakeLists.txt index facd787ee44..1720e359f39 100644 --- a/Sources/PackageLoading/CMakeLists.txt +++ b/Sources/PackageLoading/CMakeLists.txt @@ -17,8 +17,7 @@ add_library(PackageLoading PlatformRegistry.swift Target+PkgConfig.swift TargetSourcesBuilder.swift - ToolsVersionLoader.swift - UserManifestResources.swift) + ToolsVersionLoader.swift) target_link_libraries(PackageLoading PUBLIC TSCBasic Basics diff --git a/Sources/PackageLoading/ManifestLoader.swift b/Sources/PackageLoading/ManifestLoader.swift index e7f7adffed9..fc54d844549 100644 --- a/Sources/PackageLoading/ManifestLoader.swift +++ b/Sources/PackageLoading/ManifestLoader.swift @@ -23,52 +23,6 @@ public enum ManifestParseError: Swift.Error, Equatable { case runtimeManifestErrors([String]) } -/// Resources required for manifest loading. -/// -/// These requirements are abstracted out to make it easier to add support for -/// using the package manager with alternate toolchains in the future. -public protocol ManifestResourceProvider { - /// The path of the swift compiler. - var swiftCompiler: AbsolutePath { get } - - /// The path of the library resources. - var libDir: AbsolutePath { get } - - /// The path to SDK root. - /// - /// If provided, it will be passed to the swift interpreter. - var sdkRoot: AbsolutePath? { get } - - /// The bin directory. - var binDir: AbsolutePath? { get } - - /// Extra flags to pass the Swift compiler. - var swiftCompilerFlags: [String] { get } - - /// XCTest Location - var xctestLocation: AbsolutePath? { get } -} - -/// Default implemention for the resource provider. -public extension ManifestResourceProvider { - - var sdkRoot: AbsolutePath? { - return nil - } - - var binDir: AbsolutePath? { - return nil - } - - var swiftCompilerFlags: [String] { - return [] - } - - var xctestLocation: AbsolutePath? { - return nil - } -} - /// Protocol for the manifest loader interface. public protocol ManifestLoaderProtocol { /// Load the manifest for the package at `path`. @@ -124,7 +78,7 @@ public final class ManifestLoader: ManifestLoaderProtocol { private static var _hostTriple = ThreadSafeBox() private static var _packageDescriptionMinimumDeploymentTarget = ThreadSafeBox() - private let resources: ManifestResourceProvider + private let toolchain: ToolchainConfiguration private let serializedDiagnostics: Bool private let isManifestSandboxEnabled: Bool private let delegate: ManifestLoaderDelegate? @@ -137,14 +91,14 @@ public final class ManifestLoader: ManifestLoaderProtocol { private let operationQueue: OperationQueue public init( - manifestResources: ManifestResourceProvider, + toolchain: ToolchainConfiguration, serializedDiagnostics: Bool = false, isManifestSandboxEnabled: Bool = true, cacheDir: AbsolutePath? = nil, delegate: ManifestLoaderDelegate? = nil, extraManifestFlags: [String] = [] ) { - self.resources = manifestResources + self.toolchain = toolchain self.serializedDiagnostics = serializedDiagnostics self.isManifestSandboxEnabled = isManifestSandboxEnabled self.delegate = delegate @@ -157,6 +111,26 @@ public final class ManifestLoader: ManifestLoaderProtocol { self.operationQueue.maxConcurrentOperationCount = Concurrency.maxOperations } + // deprecated 8/2021 + @available(*, deprecated, message: "use non-deprecated constructor instead") + public convenience init( + manifestResources: ToolchainConfiguration, + serializedDiagnostics: Bool = false, + isManifestSandboxEnabled: Bool = true, + cacheDir: AbsolutePath? = nil, + delegate: ManifestLoaderDelegate? = nil, + extraManifestFlags: [String] = [] + ) { + self.init( + toolchain: manifestResources, + serializedDiagnostics: serializedDiagnostics, + isManifestSandboxEnabled: isManifestSandboxEnabled, + cacheDir: cacheDir, + delegate: delegate, + extraManifestFlags: extraManifestFlags + ) + } + /// Loads a root manifest from a path using the resources associated with a particular `swiftc` executable. /// /// - Parameters: @@ -177,8 +151,8 @@ public final class ManifestLoader: ManifestLoaderProtocol { completion: @escaping (Result) -> Void ) { do { - let resources = try UserManifestResources(swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags) - let loader = ManifestLoader(manifestResources: resources) + let toolchain = try ToolchainConfiguration(swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags) + let loader = ManifestLoader(toolchain: toolchain) let toolsVersion = try ToolsVersionLoader().load(at: path, fileSystem: fileSystem) let packageLocation = fileSystem.isFile(path) ? path.parentDirectory : path let packageIdentity = identityResolver.resolveIdentity(for: packageLocation) @@ -713,14 +687,14 @@ public final class ManifestLoader: ManifestLoaderProtocol { let moduleCachePath = (ProcessEnv.vars["SWIFTPM_MODULECACHE_OVERRIDE"] ?? ProcessEnv.vars["SWIFTPM_TESTS_MODULECACHE"]).flatMap{ AbsolutePath.init($0) } var cmd: [String] = [] - cmd += [resources.swiftCompiler.pathString] + cmd += [self.toolchain.swiftCompiler.pathString] cmd += verbosity.ccArgs let macOSPackageDescriptionPath: AbsolutePath // If we got the binDir that means we could be developing SwiftPM in Xcode // which produces a framework for dynamic package products. let packageFrameworkPath = runtimePath.appending(component: "PackageFrameworks") - if resources.binDir != nil, localFileSystem.exists(packageFrameworkPath) { + if self.toolchain.binDir != nil, localFileSystem.exists(packageFrameworkPath) { cmd += [ "-F", packageFrameworkPath.pathString, "-framework", "PackageDescription", @@ -746,7 +720,7 @@ public final class ManifestLoader: ManifestLoaderProtocol { // Use the same minimum deployment target as the PackageDescription library (with a fallback of 10.15). #if os(macOS) let triple = Self._hostTriple.memoize { - Triple.getHostTriple(usingSwiftCompiler: resources.swiftCompiler) + Triple.getHostTriple(usingSwiftCompiler: self.toolchain.swiftCompiler) } let version = try Self._packageDescriptionMinimumDeploymentTarget.memoize { @@ -756,7 +730,7 @@ public final class ManifestLoader: ManifestLoaderProtocol { #endif // Add any extra flags required as indicated by the ManifestLoader. - cmd += resources.swiftCompilerFlags + cmd += self.toolchain.swiftCompilerFlags cmd += self.interpreterFlags(for: toolsVersion) if let moduleCachePath = moduleCachePath { @@ -879,7 +853,7 @@ public final class ManifestLoader: ManifestLoaderProtocol { cmd += ["-swift-version", toolsVersion.swiftLanguageVersion.rawValue] cmd += ["-I", runtimePath.pathString] #if os(macOS) - if let sdkRoot = resources.sdkRoot ?? self.sdkRoot() { + if let sdkRoot = self.toolchain.sdkRoot ?? self.sdkRoot() { cmd += ["-sdk", sdkRoot.pathString] } #endif @@ -890,18 +864,18 @@ public final class ManifestLoader: ManifestLoaderProtocol { /// Returns the runtime path given the manifest version and path to libDir. private func runtimePath(for version: ToolsVersion) -> AbsolutePath { // Bin dir will be set when developing swiftpm without building all of the runtimes. - if let binDir = resources.binDir { + if let binDir = self.toolchain.binDir { return binDir } // Otherwise we use the standard location of the manifest API in the toolchain, if it exists. - let manifestAPIDir = resources.libDir.appending(component: "ManifestAPI") + let manifestAPIDir = self.toolchain.libDir.appending(component: "ManifestAPI") if localFileSystem.exists(manifestAPIDir) { return manifestAPIDir } // Otherwise, fall back on the old location (this would indicate that we're using an old toolchain). - return resources.libDir.appending(version.runtimeSubpath) + return self.toolchain.libDir.appending(version.runtimeSubpath) } /// Returns path to the manifest database inside the given cache directory. diff --git a/Sources/PackageModel/CMakeLists.txt b/Sources/PackageModel/CMakeLists.txt index d3feb38570f..f313c4918a4 100644 --- a/Sources/PackageModel/CMakeLists.txt +++ b/Sources/PackageModel/CMakeLists.txt @@ -31,6 +31,7 @@ add_library(PackageModel SupportedLanguageExtension.swift SwiftLanguageVersion.swift Target.swift + ToolchainConfiguration.swift ToolsVersion.swift ToolsVersionSpecificationGeneration.swift) target_link_libraries(PackageModel PUBLIC diff --git a/Sources/PackageLoading/UserManifestResources.swift b/Sources/PackageModel/ToolchainConfiguration.swift similarity index 66% rename from Sources/PackageLoading/UserManifestResources.swift rename to Sources/PackageModel/ToolchainConfiguration.swift index 4c8d3146c85..54ed60794dd 100644 --- a/Sources/PackageLoading/UserManifestResources.swift +++ b/Sources/PackageModel/ToolchainConfiguration.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors + Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See http://swift.org/LICENSE.txt for license information @@ -10,33 +10,45 @@ import TSCBasic -/// Concrete object for manifest resource provider. -public struct UserManifestResources: ManifestResourceProvider { +/// Toolchain configuration required for evaluation os swift code such as the manifests or plugins +/// +/// These requirements are abstracted out to make it easier to add support for +/// using the package manager with alternate toolchains in the future. +public struct ToolchainConfiguration { + /// The path of the swift compiler. public let swiftCompiler: AbsolutePath + + /// Extra flags to pass the Swift compiler. public let swiftCompilerFlags: [String] + + /// The path of the library resources. public let libDir: AbsolutePath + + /// The bin directory. + public let binDir: AbsolutePath? + + /// The path to SDK root. + /// + /// If provided, it will be passed to the swift interpreter. public let sdkRoot: AbsolutePath? + + /// XCTest Location public let xctestLocation: AbsolutePath? - public let binDir: AbsolutePath? public init( swiftCompiler: AbsolutePath, swiftCompilerFlags: [String], libDir: AbsolutePath, + binDir: AbsolutePath? = nil, sdkRoot: AbsolutePath? = nil, - xctestLocation: AbsolutePath? = nil, - binDir: AbsolutePath? = nil + xctestLocation: AbsolutePath? = nil ) { self.swiftCompiler = swiftCompiler self.swiftCompilerFlags = swiftCompilerFlags self.libDir = libDir + self.binDir = binDir self.sdkRoot = sdkRoot self.xctestLocation = xctestLocation - self.binDir = binDir - } - - public static func libDir(forBinDir binDir: AbsolutePath) -> AbsolutePath { - return binDir.parentDirectory.appending(components: "lib", "swift", "pm") } /// Creates the set of manifest resources associated with a `swiftc` executable. @@ -48,7 +60,11 @@ public struct UserManifestResources: ManifestResourceProvider { self.init( swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags, - libDir: UserManifestResources.libDir(forBinDir: binDir) + libDir: Self.libDir(forBinDir: binDir) ) } + + public static func libDir(forBinDir binDir: AbsolutePath) -> AbsolutePath { + return binDir.parentDirectory.appending(components: "lib", "swift", "pm") + } } diff --git a/Sources/SPMTestSupport/Resources.swift b/Sources/SPMTestSupport/Resources.swift deleted file mode 100644 index 0d155bb5510..00000000000 --- a/Sources/SPMTestSupport/Resources.swift +++ /dev/null @@ -1,63 +0,0 @@ -/* - This source file is part of the Swift.org open source project - - Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors - Licensed under Apache License v2.0 with Runtime Library Exception - - See http://swift.org/LICENSE.txt for license information - See http://swift.org/CONTRIBUTORS.txt for Swift project authors -*/ - -import TSCBasic -import SPMBuildCore -import Foundation -import PackageLoading -import Workspace - -#if os(macOS) -private func bundleRoot() -> AbsolutePath { - for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { - return AbsolutePath(bundle.bundlePath).parentDirectory - } - fatalError() -} -#endif - -public class Resources: ManifestResourceProvider { - - public var swiftCompiler: AbsolutePath { - return toolchain.manifestResources.swiftCompiler - } - - public var libDir: AbsolutePath { - return toolchain.manifestResources.libDir - } - - public var binDir: AbsolutePath? { - return toolchain.manifestResources.binDir - } - - public var swiftCompilerFlags: [String] { - return [] - } - - #if os(macOS) - public var sdkPlatformFrameworksPath: AbsolutePath { - return Destination.sdkPlatformFrameworkPaths()!.fwk - } - #endif - - public let toolchain: UserToolchain - - public static let `default` = Resources() - - private init() { - let binDir: AbsolutePath - #if os(macOS) - binDir = bundleRoot() - #else - binDir = AbsolutePath(CommandLine.arguments[0], relativeTo: localFileSystem.currentWorkingDirectory!).parentDirectory - #endif - toolchain = try! UserToolchain(destination: Destination.hostDestination(binDir)) - } -} diff --git a/Sources/SPMTestSupport/Toolchain.swift b/Sources/SPMTestSupport/Toolchain.swift new file mode 100644 index 00000000000..31cd15d35fb --- /dev/null +++ b/Sources/SPMTestSupport/Toolchain.swift @@ -0,0 +1,61 @@ +/* + This source file is part of the Swift.org open source project + + Copyright (c) 2021 Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + + See http://swift.org/LICENSE.txt for license information + See http://swift.org/CONTRIBUTORS.txt for Swift project authors + */ + +import Foundation +import PackageModel +import Workspace +import TSCBasic + +#if os(macOS) +private func macOSBundleRoot() -> AbsolutePath { + for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { + return AbsolutePath(bundle.bundlePath).parentDirectory + } + fatalError() +} +#endif + +private func resolveBinDir() -> AbsolutePath { +#if os(macOS) + return macOSBundleRoot() +#else + return AbsolutePath(CommandLine.arguments[0], relativeTo: localFileSystem.currentWorkingDirectory!).parentDirectory +#endif +} + +extension ToolchainConfiguration { + public static var `default`: Self { + get { + let toolchain = UserToolchain.default + return .init( + swiftCompiler: toolchain.configuration.swiftCompiler, + swiftCompilerFlags: [], + libDir: toolchain.configuration.libDir, + binDir: toolchain.configuration.binDir + ) + } + } + +#if os(macOS) + public var sdkPlatformFrameworksPath: AbsolutePath { + return Destination.sdkPlatformFrameworkPaths()!.fwk + } +#endif + +} + +extension UserToolchain { + public static var `default`: Self { + get { + let binDir = resolveBinDir() + return try! .init(destination: Destination.hostDestination(binDir)) + } + } +} diff --git a/Sources/Workspace/DefaultPluginScriptRunner.swift b/Sources/Workspace/DefaultPluginScriptRunner.swift index 048e0b8933c..04ea6874f11 100644 --- a/Sources/Workspace/DefaultPluginScriptRunner.swift +++ b/Sources/Workspace/DefaultPluginScriptRunner.swift @@ -11,7 +11,6 @@ import Basics import Foundation import PackageGraph -import PackageLoading // for ManifestResourceProvider import PackageModel import SPMBuildCore import TSCBasic @@ -20,16 +19,16 @@ import TSCUtility /// A plugin script runner that compiles the plugin source files as an executable binary for the host platform, and invokes it as a subprocess. public struct DefaultPluginScriptRunner: PluginScriptRunner { let cacheDir: AbsolutePath - let resources: ManifestResourceProvider + let toolchain: ToolchainConfiguration let enableSandbox: Bool private static var _hostTriple = ThreadSafeBox() private static var _packageDescriptionMinimumDeploymentTarget = ThreadSafeBox() private let sdkRootCache = ThreadSafeBox() - public init(cacheDir: AbsolutePath, manifestResources: ManifestResourceProvider, enableSandbox: Bool = true) { + public init(cacheDir: AbsolutePath, toolchain: ToolchainConfiguration, enableSandbox: Bool = true) { self.cacheDir = cacheDir - self.resources = manifestResources + self.toolchain = toolchain self.enableSandbox = enableSandbox } @@ -41,7 +40,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner { public var hostTriple: Triple { return Self._hostTriple.memoize { - Triple.getHostTriple(usingSwiftCompiler: resources.swiftCompiler) + Triple.getHostTriple(usingSwiftCompiler: self.toolchain.swiftCompiler) } } @@ -50,10 +49,10 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner { // FIXME: Much of this is copied from the ManifestLoader and should be consolidated. // Bin dir will be set when developing swiftpm without building all of the runtimes. - let runtimePath = self.resources.binDir ?? self.resources.libDir.appending(component: "PluginAPI") + let runtimePath = self.toolchain.binDir ?? self.toolchain.libDir.appending(component: "PluginAPI") // Compile the package plugin script. - var command = [resources.swiftCompiler.pathString] + var command = [self.toolchain.swiftCompiler.pathString] // FIXME: Workaround for the module cache bug that's been haunting Swift CI // @@ -64,7 +63,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner { let packageFrameworkPath = runtimePath.appending(component: "PackageFrameworks") let macOSPackageDescriptionPath: AbsolutePath - if self.resources.binDir != nil, localFileSystem.exists(packageFrameworkPath) { + if self.toolchain.binDir != nil, localFileSystem.exists(packageFrameworkPath) { command += [ "-F", packageFrameworkPath.pathString, "-framework", "PackagePlugin", @@ -97,12 +96,12 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner { #endif // Add any extra flags required as indicated by the ManifestLoader. - command += self.resources.swiftCompilerFlags + command += self.toolchain.swiftCompilerFlags command += ["-swift-version", toolsVersion.swiftLanguageVersion.rawValue] command += ["-I", runtimePath.pathString] #if os(macOS) - if let sdkRoot = resources.sdkRoot ?? self.sdkRoot() { + if let sdkRoot = self.toolchain.sdkRoot ?? self.sdkRoot() { command += ["-sdk", sdkRoot.pathString] } #endif diff --git a/Sources/Workspace/UserToolchain.swift b/Sources/Workspace/UserToolchain.swift index c5bbd0d8240..8787f88a7af 100644 --- a/Sources/Workspace/UserToolchain.swift +++ b/Sources/Workspace/UserToolchain.swift @@ -9,11 +9,12 @@ */ import Basics -import TSCBasic -import TSCUtility +import Foundation import PackageLoading +import PackageModel import SPMBuildCore -import Foundation +import TSCBasic +import TSCUtility #if os(Windows) private let hostExecutableSuffix = ".exe" @@ -25,7 +26,7 @@ private let hostExecutableSuffix = "" public final class UserToolchain: Toolchain { /// The manifest resource provider. - public let manifestResources: ManifestResourceProvider + public let configuration: ToolchainConfiguration /// Path of the `swiftc` compiler. public let swiftCompiler: AbsolutePath @@ -36,6 +37,12 @@ public final class UserToolchain: Toolchain { public var extraCPPFlags: [String] + // deprecated 8/2021 + @available(*, deprecated, message: "use configuration instead") + public var manifestResources: ToolchainConfiguration { + return self.configuration + } + /// Path of the `swift` interpreter. public var swiftInterpreter: AbsolutePath { return swiftCompiler.parentDirectory.appending(component: "swift" + hostExecutableSuffix) @@ -359,7 +366,7 @@ public final class UserToolchain: Toolchain { } // Compute the path of directory containing the PackageDescription libraries. - var pdLibDir = UserManifestResources.libDir(forBinDir: binDir) + var pdLibDir = ToolchainConfiguration.libDir(forBinDir: binDir) // Look for an override in the env. if let pdLibDirEnvStr = ProcessEnv.vars["SWIFTPM_PD_LIBS"] { @@ -402,14 +409,14 @@ public final class UserToolchain: Toolchain { } #endif - manifestResources = UserManifestResources( + self.configuration = .init( swiftCompiler: swiftCompilers.manifest, swiftCompilerFlags: self.extraSwiftCFlags, libDir: pdLibDir, - sdkRoot: self.destination.sdk, - xctestLocation: xctestLocation, // Set the bin directory if we don't have a lib dir. - binDir: localFileSystem.exists(pdLibDir) ? nil : binDir + binDir: localFileSystem.exists(pdLibDir) ? nil : binDir, + sdkRoot: self.destination.sdk, + xctestLocation: xctestLocation ) } } diff --git a/Sources/Workspace/Workspace.swift b/Sources/Workspace/Workspace.swift index daf780c017c..1e6e214a133 100644 --- a/Sources/Workspace/Workspace.swift +++ b/Sources/Workspace/Workspace.swift @@ -635,8 +635,8 @@ extension Workspace { identityResolver: IdentityResolver? = nil, diagnostics: DiagnosticsEngine ) throws -> PackageGraph { - let resources = try UserManifestResources(swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags) - let loader = ManifestLoader(manifestResources: resources) + let toolchain = try ToolchainConfiguration(swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags) + let loader = ManifestLoader(toolchain: toolchain) let workspace = Workspace.create(forRootPackage: packagePath, manifestLoader: loader, identityResolver: identityResolver) return try workspace.loadPackageGraph(rootPath: packagePath, diagnostics: diagnostics) } diff --git a/Tests/BuildTests/BuildPlanTests.swift b/Tests/BuildTests/BuildPlanTests.swift index ded3fa4bc51..cf81a5c6b56 100644 --- a/Tests/BuildTests/BuildPlanTests.swift +++ b/Tests/BuildTests/BuildPlanTests.swift @@ -19,7 +19,7 @@ import TSCUtility import Workspace import XCTest -let hostTriple = Resources.default.toolchain.triple +let hostTriple = UserToolchain.default.triple #if os(macOS) let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVersion: "10.10") #else @@ -228,8 +228,8 @@ final class BuildPlanTests: XCTestCase { buildParameters: mockBuildParameters( buildPath: buildDirPath, config: .release, - toolchain: Resources.default.toolchain, - destinationTriple: Resources.default.toolchain.triple, + toolchain: UserToolchain.default, + destinationTriple: UserToolchain.default.triple, useExplicitModuleBuild: true ), graph: graph, @@ -2132,7 +2132,7 @@ final class BuildPlanTests: XCTestCase { XCTAssertNoDiagnostics(diagnostics) let userDestination = Destination(sdk: AbsolutePath("/fake/sdk"), - binDir: Resources.default.toolchain.destination.binDir, + binDir: UserToolchain.default.destination.binDir, extraCCFlags: ["-I/fake/sdk/sysroot", "-clang-flag-from-json"], extraSwiftCFlags: ["-swift-flag-from-json"]) let mockToolchain = try UserToolchain(destination: userDestination) diff --git a/Tests/CommandsTests/APIDiffTests.swift b/Tests/CommandsTests/APIDiffTests.swift index bec80cfc988..183674a9ff6 100644 --- a/Tests/CommandsTests/APIDiffTests.swift +++ b/Tests/CommandsTests/APIDiffTests.swift @@ -8,13 +8,14 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ -import XCTest -import Foundation -import TSCBasic import Build import Commands +import Foundation import SourceControl import SPMTestSupport +import TSCBasic +import Workspace +import XCTest final class APIDiffTests: XCTestCase { @discardableResult @@ -31,7 +32,7 @@ final class APIDiffTests: XCTestCase { func skipIfApiDigesterUnsupported() throws { // swift-api-digester is required to run tests. - guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else { + guard (try? UserToolchain.default.getSwiftAPIDigester()) != nil else { throw XCTSkip("swift-api-digester unavailable") } // SwiftPM's swift-api-digester integration relies on post-5.5 bugfixes and features, diff --git a/Tests/CommandsTests/BuildToolTests.swift b/Tests/CommandsTests/BuildToolTests.swift index 66ef10600a7..554caf74a5e 100644 --- a/Tests/CommandsTests/BuildToolTests.swift +++ b/Tests/CommandsTests/BuildToolTests.swift @@ -8,13 +8,13 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ -import XCTest - +import Commands +import PackageModel +import SPMBuildCore import SPMTestSupport import TSCBasic -import SPMBuildCore -import Commands import Workspace +import XCTest struct BuildResult { let binPath: AbsolutePath @@ -75,7 +75,7 @@ final class BuildToolTests: XCTestCase { func testBinPathAndSymlink() throws { fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { path in let fullPath = resolveSymlinks(path) - let targetPath = fullPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString) + let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.tripleString) let xcbuildTargetPath = fullPath.appending(components: ".build", "apple") XCTAssertEqual(try execute(["--show-bin-path"], packagePath: fullPath).stdout, "\(targetPath.appending(component: "debug").pathString)\n") @@ -291,7 +291,7 @@ final class BuildToolTests: XCTestCase { let defaultOutput = try execute(["-c", "debug", "-v"], packagePath: path).stdout // Look for certain things in the output from XCBuild. - XCTAssert(defaultOutput.contains("-target \(Resources.default.toolchain.triple.tripleString)"), defaultOutput) + XCTAssert(defaultOutput.contains("-target \(UserToolchain.default.triple.tripleString)"), defaultOutput) } } @@ -302,12 +302,12 @@ final class BuildToolTests: XCTestCase { fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { path in // Try building using XCBuild without specifying overrides. This should succeed, and should use the default compiler path. let defaultOutput = try execute(["-c", "debug", "-v"], packagePath: path).stdout - XCTAssert(defaultOutput.contains(Resources.default.swiftCompiler.pathString), defaultOutput) + XCTAssert(defaultOutput.contains(ToolchainConfiguration.default.swiftCompiler.pathString), defaultOutput) // Now try building using XCBuild while specifying a faulty compiler override. This should fail. Note that we need to set the executable to use for the manifest itself to the default one, since it defaults to SWIFT_EXEC if not provided. var overriddenOutput = "" do { - overriddenOutput = try execute(["-c", "debug", "-v"], environment: ["SWIFT_EXEC": "/usr/bin/false", "SWIFT_EXEC_MANIFEST": Resources.default.swiftCompiler.pathString], packagePath: path).stdout + overriddenOutput = try execute(["-c", "debug", "-v"], environment: ["SWIFT_EXEC": "/usr/bin/false", "SWIFT_EXEC_MANIFEST": ToolchainConfiguration.default.swiftCompiler.pathString], packagePath: path).stdout XCTFail("unexpected success (was SWIFT_EXEC not overridden properly?)") } catch SwiftPMProductError.executionFailure(let error, let stdout, _) { diff --git a/Tests/CommandsTests/PackageToolTests.swift b/Tests/CommandsTests/PackageToolTests.swift index 6b29a4a0b4e..be815b1ec62 100644 --- a/Tests/CommandsTests/PackageToolTests.swift +++ b/Tests/CommandsTests/PackageToolTests.swift @@ -588,7 +588,7 @@ final class PackageToolTests: XCTestCase { _ = try SwiftPMProduct.SwiftPackage.execute(["edit", "baz", "--branch", "bugfix"], packagePath: fooPath) // Path to the executable. - let exec = [fooPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "foo").pathString] + let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "foo").pathString] // We should see it now in packages directory. let editsPath = fooPath.appending(components: "Packages", "bar") @@ -662,7 +662,7 @@ final class PackageToolTests: XCTestCase { // Build it. XCTAssertBuilds(packageRoot) let buildPath = packageRoot.appending(component: ".build") - let binFile = buildPath.appending(components: Resources.default.toolchain.triple.tripleString, "debug", "Bar") + let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar") XCTAssertFileExists(binFile) XCTAssert(localFileSystem.isDirectory(buildPath)) @@ -681,7 +681,7 @@ final class PackageToolTests: XCTestCase { // Build it. XCTAssertBuilds(packageRoot) let buildPath = packageRoot.appending(component: ".build") - let binFile = buildPath.appending(components: Resources.default.toolchain.triple.tripleString, "debug", "Bar") + let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar") XCTAssertFileExists(binFile) XCTAssert(localFileSystem.isDirectory(buildPath)) // Clean, and check for removal of the build directory but not Packages. @@ -751,7 +751,7 @@ final class PackageToolTests: XCTestCase { func build() throws -> String { return try SwiftPMProduct.SwiftBuild.execute([], packagePath: fooPath).stdout } - let exec = [fooPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "foo").pathString] + let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "foo").pathString] // Build and sanity check. _ = try build() diff --git a/Tests/FunctionalPerformanceTests/BuildPerfTests.swift b/Tests/FunctionalPerformanceTests/BuildPerfTests.swift index 9043beb35f4..ec116efbe0a 100644 --- a/Tests/FunctionalPerformanceTests/BuildPerfTests.swift +++ b/Tests/FunctionalPerformanceTests/BuildPerfTests.swift @@ -8,19 +8,20 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ -import XCTest import Commands +import PackageModel import SPMTestSupport import TSCBasic import TSCUtility import Workspace +import XCTest class BuildPerfTests: XCTestCasePerf { @discardableResult func execute(args: [String] = [], packagePath: AbsolutePath) throws -> (stdout: String, stderr: String) { // FIXME: We should pass the SWIFT_EXEC at lower level. - return try SwiftPMProduct.SwiftBuild.execute(args + [], packagePath: packagePath, env: ["SWIFT_EXEC": Resources.default.swiftCompiler.pathString]) + return try SwiftPMProduct.SwiftBuild.execute(args + [], packagePath: packagePath, env: ["SWIFT_EXEC": ToolchainConfiguration.default.swiftCompiler.pathString]) } func clean(packagePath: AbsolutePath) throws { @@ -54,7 +55,7 @@ class BuildPerfTests: XCTestCasePerf { func runFullBuildTest(for name: String, app appString: String? = nil, product productString: String) { fixture(name: name) { prefix in let app = prefix.appending(components: (appString ?? "")) - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple let product = app.appending(components: ".build", triple.tripleString, "debug", productString) try self.execute(packagePath: app) measure { @@ -68,7 +69,7 @@ class BuildPerfTests: XCTestCasePerf { func runNullBuildTest(for name: String, app appString: String? = nil, product productString: String) { fixture(name: name) { prefix in let app = prefix.appending(components: (appString ?? "")) - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple let product = app.appending(components: ".build", triple.tripleString, "debug", productString) try self.execute(packagePath: app) measure { diff --git a/Tests/FunctionalTests/CFamilyTargetTests.swift b/Tests/FunctionalTests/CFamilyTargetTests.swift index 3dfd98ccc84..25c740892f9 100644 --- a/Tests/FunctionalTests/CFamilyTargetTests.swift +++ b/Tests/FunctionalTests/CFamilyTargetTests.swift @@ -36,7 +36,7 @@ class CFamilyTargetTestCase: XCTestCase { func testCLibraryWithSpaces() { fixture(name: "CFamilyTargets/CLibraryWithSpaces") { prefix in XCTAssertBuilds(prefix) - let debugPath = prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug") + let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Bar.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") } @@ -46,7 +46,7 @@ class CFamilyTargetTestCase: XCTestCase { fixture(name: "DependencyResolution/External/CUsingCDep") { prefix in let packageRoot = prefix.appending(component: "Bar") XCTAssertBuilds(packageRoot) - let debugPath = prefix.appending(components: "Bar", ".build", Resources.default.toolchain.triple.tripleString, "debug") + let debugPath = prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.tripleString, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Sea.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot) @@ -57,7 +57,7 @@ class CFamilyTargetTestCase: XCTestCase { func testModuleMapGenerationCases() { fixture(name: "CFamilyTargets/ModuleMapGenerationCases") { prefix in XCTAssertBuilds(prefix) - let debugPath = prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug") + let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Jaz.c.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "main.swift.o") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "FlatInclude.c.o") @@ -80,7 +80,7 @@ class CFamilyTargetTestCase: XCTestCase { // Try building a fixture which needs extra flags to be able to build. fixture(name: "CFamilyTargets/CDynamicLookup") { prefix in XCTAssertBuilds(prefix, Xld: ["-undefined", "dynamic_lookup"]) - let debugPath = prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug") + let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug") XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o") } } @@ -90,7 +90,7 @@ class CFamilyTargetTestCase: XCTestCase { fixture(name: "CFamilyTargets/ObjCmacOSPackage") { prefix in // Build the package. XCTAssertBuilds(prefix) - XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug"), filename: "HelloWorldExample.m.o") + XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug"), filename: "HelloWorldExample.m.o") // Run swift-test on package. XCTAssertSwiftTest(prefix) } diff --git a/Tests/FunctionalTests/DependencyResolutionTests.swift b/Tests/FunctionalTests/DependencyResolutionTests.swift index 461b51af6db..f0c0146b3d8 100644 --- a/Tests/FunctionalTests/DependencyResolutionTests.swift +++ b/Tests/FunctionalTests/DependencyResolutionTests.swift @@ -8,20 +8,20 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ -import XCTest - -import TSCBasic import Commands -import SPMTestSupport +import PackageModel import SourceControl +import SPMTestSupport +import TSCBasic import Workspace +import XCTest class DependencyResolutionTests: XCTestCase { func testInternalSimple() { fixture(name: "DependencyResolution/Internal/Simple") { prefix in XCTAssertBuilds(prefix) - let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "Foo").pathString) + let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Foo").pathString) XCTAssertEqual(output, "Foo\nBar\n") } } @@ -36,7 +36,7 @@ class DependencyResolutionTests: XCTestCase { fixture(name: "DependencyResolution/Internal/Complex") { prefix in XCTAssertBuilds(prefix) - let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "Foo").pathString) + let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Foo").pathString) XCTAssertEqual(output, "meiow Baz\n") } } @@ -52,7 +52,7 @@ class DependencyResolutionTests: XCTestCase { let packageRoot = prefix.appending(component: "Bar") XCTAssertBuilds(packageRoot) - XCTAssertFileExists(prefix.appending(components: "Bar", ".build", Resources.default.toolchain.triple.tripleString, "debug", "Bar")) + XCTAssertFileExists(prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.tripleString, "debug", "Bar")) let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot) XCTAssert(try GitRepository(path: path).getTags().contains("1.2.3")) } @@ -61,7 +61,7 @@ class DependencyResolutionTests: XCTestCase { func testExternalComplex() { fixture(name: "DependencyResolution/External/Complex") { prefix in XCTAssertBuilds(prefix.appending(component: "app")) - let output = try Process.checkNonZeroExit(args: prefix.appending(components: "app", ".build", Resources.default.toolchain.triple.tripleString, "debug", "Dealer").pathString) + let output = try Process.checkNonZeroExit(args: prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug", "Dealer").pathString) XCTAssertEqual(output, "♣︎K\n♣︎Q\n♣︎J\n♣︎10\n♣︎9\n♣︎8\n♣︎7\n♣︎6\n♣︎5\n♣︎4\n") } } diff --git a/Tests/FunctionalTests/MiscellaneousTests.swift b/Tests/FunctionalTests/MiscellaneousTests.swift index 0be51085679..da67a9aeb9b 100644 --- a/Tests/FunctionalTests/MiscellaneousTests.swift +++ b/Tests/FunctionalTests/MiscellaneousTests.swift @@ -47,7 +47,7 @@ class MiscellaneousTestCase: XCTestCase { fixture(name: "Miscellaneous/ExactDependencies") { prefix in XCTAssertBuilds(prefix.appending(component: "app")) - let buildDir = prefix.appending(components: "app", ".build", Resources.default.toolchain.triple.tripleString, "debug") + let buildDir = prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug") XCTAssertFileExists(buildDir.appending(component: "FooExec")) XCTAssertFileExists(buildDir.appending(component: "FooLib1.swiftmodule")) XCTAssertFileExists(buildDir.appending(component: "FooLib2.swiftmodule")) @@ -120,7 +120,7 @@ class MiscellaneousTestCase: XCTestCase { */ func testInternalDependencyEdges() { fixture(name: "Miscellaneous/DependencyEdges/Internal") { prefix in - let execpath = prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "Foo").pathString + let execpath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Foo").pathString XCTAssertBuilds(prefix) var output = try Process.checkNonZeroExit(args: execpath) @@ -144,7 +144,7 @@ class MiscellaneousTestCase: XCTestCase { */ func testExternalDependencyEdges1() { fixture(name: "DependencyResolution/External/Complex") { prefix in - let execpath = prefix.appending(components: "app", ".build", Resources.default.toolchain.triple.tripleString, "debug", "Dealer").pathString + let execpath = prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug", "Dealer").pathString let packageRoot = prefix.appending(component: "app") XCTAssertBuilds(packageRoot) @@ -171,7 +171,7 @@ class MiscellaneousTestCase: XCTestCase { */ func testExternalDependencyEdges2() { fixture(name: "Miscellaneous/DependencyEdges/External") { prefix in - let execpath = [prefix.appending(components: "root", ".build", Resources.default.toolchain.triple.tripleString, "debug", "dep2").pathString] + let execpath = [prefix.appending(components: "root", ".build", UserToolchain.default.triple.tripleString, "debug", "dep2").pathString] let packageRoot = prefix.appending(component: "root") XCTAssertBuilds(prefix.appending(component: "root")) @@ -195,7 +195,7 @@ class MiscellaneousTestCase: XCTestCase { func testSpaces() { fixture(name: "Miscellaneous/Spaces Fixture") { prefix in XCTAssertBuilds(prefix) - XCTAssertFileExists(prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "Module_Name_1.build", "Foo.swift.o")) + XCTAssertFileExists(prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Module_Name_1.build", "Foo.swift.o")) } } @@ -300,7 +300,7 @@ class MiscellaneousTestCase: XCTestCase { func testOverridingDeploymentTargetUsingSwiftCompilerArgument() throws { #if os(macOS) fixture(name: "Miscellaneous/DistantFutureDeploymentTarget") { prefix in - let hostTriple = Resources.default.toolchain.triple + let hostTriple = UserToolchain.default.triple try executeSwiftBuild(prefix, Xswiftc: ["-target", "\(hostTriple.arch)-apple-macosx41.0"]) } #endif @@ -311,7 +311,7 @@ class MiscellaneousTestCase: XCTestCase { let systemModule = prefix.appending(component: "SystemModule") // Create a shared library. let input = systemModule.appending(components: "Sources", "SystemModule.c") - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple let output = systemModule.appending(component: "libSystemModule\(triple.dynamicLibraryExtension)") try systemQuietly(["clang", "-shared", input.pathString, "-o", output.pathString]) diff --git a/Tests/FunctionalTests/ModuleMapTests.swift b/Tests/FunctionalTests/ModuleMapTests.swift index de1a04aba0e..f201c47a9a4 100644 --- a/Tests/FunctionalTests/ModuleMapTests.swift +++ b/Tests/FunctionalTests/ModuleMapTests.swift @@ -8,19 +8,20 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ -import XCTest import Commands +import PackageModel import SPMTestSupport import TSCBasic import TSCUtility import Workspace +import XCTest class ModuleMapsTestCase: XCTestCase { private func fixture(name: String, cModuleName: String, rootpkg: String, body: @escaping (AbsolutePath, [String]) throws -> Void) { SPMTestSupport.fixture(name: name) { prefix in let input = prefix.appending(components: cModuleName, "C", "foo.c") - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple let outdir = prefix.appending(components: rootpkg, ".build", triple.tripleString, "debug") try makeDirectories(outdir) let output = outdir.appending(component: "libfoo\(triple.dynamicLibraryExtension)") @@ -40,7 +41,7 @@ class ModuleMapsTestCase: XCTestCase { XCTAssertBuilds(prefix.appending(component: "App"), Xld: Xld) - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple let targetPath = prefix.appending(components: "App", ".build", triple.tripleString) let debugout = try Process.checkNonZeroExit(args: targetPath.appending(components: "debug", "App").pathString) XCTAssertEqual(debugout, "123\n") @@ -55,7 +56,7 @@ class ModuleMapsTestCase: XCTestCase { XCTAssertBuilds(prefix.appending(component: "packageA"), Xld: Xld) func verify(_ conf: String, file: StaticString = #file, line: UInt = #line) throws { - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple let out = try Process.checkNonZeroExit(args: prefix.appending(components: "packageA", ".build", triple.tripleString, conf, "packageA").pathString) XCTAssertEqual(out, """ calling Y.bar() diff --git a/Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift b/Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift index 3623596b061..fe23e843aad 100644 --- a/Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift +++ b/Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift @@ -8,12 +8,13 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ -import TSCBasic +import Commands +import PackageModel import SPMTestSupport -import XCTest +import TSCBasic import TSCUtility -import Commands import Workspace +import XCTest class SwiftPMXCTestHelperTests: XCTestCase { func testBasicXCTestHelper() throws { @@ -21,7 +22,7 @@ class SwiftPMXCTestHelperTests: XCTestCase { fixture(name: "Miscellaneous/SwiftPMXCTestHelper") { prefix in // Build the package. XCTAssertBuilds(prefix) - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple XCTAssertFileExists(prefix.appending(components: ".build", triple.tripleString, "debug", "SwiftPMXCTestHelper.swiftmodule")) // Run swift-test on package. XCTAssertSwiftTest(prefix) @@ -39,7 +40,7 @@ class SwiftPMXCTestHelperTests: XCTestCase { ] as Array>]] as Array> ] as Dictionary as NSDictionary // Run the XCTest helper tool and check result. - XCTAssertXCTestHelper(prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "SwiftPMXCTestHelperPackageTests.xctest"), testCases: testCases) + XCTAssertXCTestHelper(prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "SwiftPMXCTestHelperPackageTests.xctest"), testCases: testCases) } #endif } @@ -49,7 +50,7 @@ class SwiftPMXCTestHelperTests: XCTestCase { #if os(macOS) func XCTAssertXCTestHelper(_ bundlePath: AbsolutePath, testCases: NSDictionary) { do { - let env = ["DYLD_FRAMEWORK_PATH": Resources.default.sdkPlatformFrameworksPath.pathString] + let env = ["DYLD_FRAMEWORK_PATH": ToolchainConfiguration.default.sdkPlatformFrameworksPath.pathString] let outputFile = bundlePath.parentDirectory.appending(component: "tests.txt") let _ = try SwiftPMProduct.XCTestHelper.execute([bundlePath.pathString, outputFile.pathString], env: env) guard let data = NSData(contentsOfFile: outputFile.pathString) else { diff --git a/Tests/FunctionalTests/ToolsVersionTests.swift b/Tests/FunctionalTests/ToolsVersionTests.swift index aeb63a88b87..7f12c1bc103 100644 --- a/Tests/FunctionalTests/ToolsVersionTests.swift +++ b/Tests/FunctionalTests/ToolsVersionTests.swift @@ -91,7 +91,7 @@ class ToolsVersionTests: XCTestCase { // Build the primary package. _ = try SwiftPMProduct.SwiftBuild.execute([], packagePath: primaryPath) - let exe = primaryPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "Primary").pathString + let exe = primaryPath.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Primary").pathString // v1 should get selected because v1.0.1 depends on a (way) higher set of tools. XCTAssertEqual(try Process.checkNonZeroExit(args: exe).spm_chomp(), "foo@1.0") diff --git a/Tests/PackageLoadingPerformanceTests/ManifestLoadingTests.swift b/Tests/PackageLoadingPerformanceTests/ManifestLoadingTests.swift index e67798c353d..057b99a1259 100644 --- a/Tests/PackageLoadingPerformanceTests/ManifestLoadingTests.swift +++ b/Tests/PackageLoadingPerformanceTests/ManifestLoadingTests.swift @@ -8,14 +8,14 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ -import XCTest - -import TSCBasic -import SPMTestSupport +import PackageModel import PackageLoading +import SPMTestSupport +import TSCBasic +import XCTest class ManifestLoadingPerfTests: XCTestCasePerf { - let manifestLoader = ManifestLoader(manifestResources: Resources.default) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default) func write(_ bytes: ByteString, body: (AbsolutePath) -> ()) throws { try testWithTemporaryDirectory { tmpdir in diff --git a/Tests/PackageLoadingTests/PDLoadingTests.swift b/Tests/PackageLoadingTests/PDLoadingTests.swift index 55d8e3d64c5..3c025f7350c 100644 --- a/Tests/PackageLoadingTests/PDLoadingTests.swift +++ b/Tests/PackageLoadingTests/PDLoadingTests.swift @@ -17,7 +17,7 @@ import PackageModel import PackageLoading class PackageDescriptionLoadingTests: XCTestCase { - let manifestLoader = ManifestLoader(manifestResources: Resources.default) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default) var toolsVersion: ToolsVersion { fatalError("implement in subclass") diff --git a/Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift b/Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift index 9003c75937a..cd7ac4aa61e 100644 --- a/Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift +++ b/Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift @@ -542,7 +542,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests { let delegate = ManifestTestDelegate() - let manifestLoader = ManifestLoader(manifestResources: Resources.default, cacheDir: path, delegate: delegate) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default, cacheDir: path, delegate: delegate) func check(loader: ManifestLoader, expectCached: Bool) { delegate.clear() @@ -598,7 +598,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests { let delegate = ManifestTestDelegate() - let manifestLoader = ManifestLoader(manifestResources: Resources.default, cacheDir: path, delegate: delegate) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default, cacheDir: path, delegate: delegate) func check(loader: ManifestLoader, expectCached: Bool) { delegate.clear() @@ -643,7 +643,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests { check(loader: manifestLoader, expectCached: true) } - let noCacheLoader = ManifestLoader(manifestResources: Resources.default, delegate: delegate) + let noCacheLoader = ManifestLoader(toolchain: ToolchainConfiguration.default, delegate: delegate) for _ in 0..<2 { check(loader: noCacheLoader, expectCached: false) } @@ -670,7 +670,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests { let delegate = ManifestTestDelegate() - let manifestLoader = ManifestLoader(manifestResources: Resources.default, cacheDir: path, delegate: delegate) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default, cacheDir: path, delegate: delegate) func check(loader: ManifestLoader) throws { let fs = InMemoryFileSystem() @@ -775,7 +775,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests { let diagnostics = DiagnosticsEngine() let delegate = ManifestTestDelegate() - let manifestLoader = ManifestLoader(manifestResources: Resources.default, cacheDir: path, delegate: delegate) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default, cacheDir: path, delegate: delegate) let identityResolver = DefaultIdentityResolver() // warm up caches @@ -837,7 +837,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests { let diagnostics = DiagnosticsEngine() let delegate = ManifestTestDelegate() - let manifestLoader = ManifestLoader(manifestResources: Resources.default, cacheDir: path, delegate: delegate) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default, cacheDir: path, delegate: delegate) let identityResolver = DefaultIdentityResolver() let sync = DispatchGroup() diff --git a/Tests/PackageLoadingTests/PD_5_0_LoadingTests.swift b/Tests/PackageLoadingTests/PD_5_0_LoadingTests.swift index 00693117355..acaac00378a 100644 --- a/Tests/PackageLoadingTests/PD_5_0_LoadingTests.swift +++ b/Tests/PackageLoadingTests/PD_5_0_LoadingTests.swift @@ -362,7 +362,7 @@ class PackageDescription5_0LoadingTests: PackageDescriptionLoadingTests { } let loader = ManifestLoader( - manifestResources: Resources.default, + toolchain: ToolchainConfiguration.default, serializedDiagnostics: true, cacheDir: path) diff --git a/Tests/SPMBuildCoreTests/PluginInvocationTests.swift b/Tests/SPMBuildCoreTests/PluginInvocationTests.swift index b5cd54a4796..9dd3d056e8a 100644 --- a/Tests/SPMBuildCoreTests/PluginInvocationTests.swift +++ b/Tests/SPMBuildCoreTests/PluginInvocationTests.swift @@ -8,15 +8,14 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ -import XCTest -import TSCBasic -import TSCUtility - import PackageGraph import PackageModel @testable import SPMBuildCore import SPMTestSupport - +import TSCBasic +import TSCUtility +import Workspace +import XCTest class PluginInvocationTests: XCTestCase { @@ -85,7 +84,7 @@ class PluginInvocationTests: XCTestCase { // A fake PluginScriptRunner that just checks the input conditions and returns canned output. struct MockPluginScriptRunner: PluginScriptRunner { var hostTriple: Triple { - return Resources.default.toolchain.triple + return UserToolchain.default.triple } func runPluginScript( sources: Sources, diff --git a/Tests/WorkspaceTests/InitTests.swift b/Tests/WorkspaceTests/InitTests.swift index 24fb816843a..43b3d268592 100644 --- a/Tests/WorkspaceTests/InitTests.swift +++ b/Tests/WorkspaceTests/InitTests.swift @@ -90,7 +90,7 @@ class InitTests: XCTestCase { // If we have a compiler that supports `-entry-point-function-name`, we try building it (we need that flag now). #if swift(>=5.5) XCTAssertBuilds(path) - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple let binPath = path.appending(components: ".build", triple.tripleString, "debug") XCTAssertFileExists(binPath.appending(component: "Foo")) XCTAssertFileExists(binPath.appending(components: "Foo.swiftmodule")) @@ -146,7 +146,7 @@ class InitTests: XCTestCase { // Try building it XCTAssertBuilds(path) - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple XCTAssertFileExists(path.appending(components: ".build", triple.tripleString, "debug", "Foo.swiftmodule")) } } @@ -229,7 +229,7 @@ class InitTests: XCTestCase { // Try building it. XCTAssertBuilds(packageRoot) - let triple = Resources.default.toolchain.triple + let triple = UserToolchain.default.triple XCTAssertFileExists(packageRoot.appending(components: ".build", triple.tripleString, "debug", "some_package.swiftmodule")) } } diff --git a/Tests/WorkspaceTests/ManifestSourceGenerationTests.swift b/Tests/WorkspaceTests/ManifestSourceGenerationTests.swift index 7834d072d58..34a23b413d9 100644 --- a/Tests/WorkspaceTests/ManifestSourceGenerationTests.swift +++ b/Tests/WorkspaceTests/ManifestSourceGenerationTests.swift @@ -21,7 +21,7 @@ class ManifestSourceGenerationTests: XCTestCase { try withTemporaryDirectory { packageDir in // Write the original manifest file contents, and load it. try fs.writeFileContents(packageDir.appending(component: Manifest.filename), bytes: ByteString(encodingAsUTF8: manifestContents)) - let manifestLoader = ManifestLoader(manifestResources: Resources.default) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default) let identityResolver = DefaultIdentityResolver() let manifest = try tsc_await { manifestLoader.load(at: packageDir, diff --git a/Tests/WorkspaceTests/WorkspaceTests.swift b/Tests/WorkspaceTests/WorkspaceTests.swift index 6a5bf4d9964..4b79b2c659c 100644 --- a/Tests/WorkspaceTests/WorkspaceTests.swift +++ b/Tests/WorkspaceTests/WorkspaceTests.swift @@ -133,7 +133,7 @@ final class WorkspaceTests: XCTestCase { manifest($0) } - let manifestLoader = ManifestLoader(manifestResources: Resources.default) + let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default) let sandbox = path.appending(component: "ws") return Workspace( @@ -3829,7 +3829,7 @@ final class WorkspaceTests: XCTestCase { // Clients must locate the corresponding “swiftc” exectuable themselves for now. // (This just uses the same one used by all the other tests.) - let swiftCompiler = Resources.default.swiftCompiler + let swiftCompiler = ToolchainConfiguration.default.swiftCompiler // identity resolver helps go from textual description to actual identity let identityResolver = DefaultIdentityResolver() diff --git a/Tests/XcodeprojTests/FunctionalTests.swift b/Tests/XcodeprojTests/FunctionalTests.swift index f2f5cf3868f..6c9600fb143 100644 --- a/Tests/XcodeprojTests/FunctionalTests.swift +++ b/Tests/XcodeprojTests/FunctionalTests.swift @@ -139,7 +139,7 @@ func XCTAssertXcodeBuild(project: AbsolutePath, file: StaticString = #file, line env["TOOLCHAINS"] = "default" } let xcconfig = project.appending(component: "overrides.xcconfig") - let swiftCompilerPath = Resources.default.swiftCompiler + let swiftCompilerPath = ToolchainConfiguration.default.swiftCompiler // Override path to the Swift compiler. let stream = BufferedOutputByteStream()