From d91abb30c3898d2a940773d745b2a63474b24e02 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Tue, 23 Apr 2024 12:34:35 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Cover=20`=E2=80=93-toolchain`=20argument=20?= =?UTF-8?q?in=20`SwiftCommandStateTests`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should prevent possible regressions in how this argument is handled. --- .../FileSystem/FileSystem+Extensions.swift | 3 +- .../FileSystem/InMemoryFileSystem.swift | 496 ++++++++++++++++++ Sources/CoreCommands/SwiftCommandState.swift | 18 +- Sources/PackageModel/UserToolchain.swift | 166 ++++-- Sources/SPMTestSupport/Toolchain.swift | 2 +- Sources/Workspace/Workspace.swift | 4 +- .../SwiftCommandStateTests.swift | 64 ++- .../PackageModelTests/PackageModelTests.swift | 29 +- 8 files changed, 703 insertions(+), 79 deletions(-) create mode 100644 Sources/Basics/FileSystem/InMemoryFileSystem.swift diff --git a/Sources/Basics/FileSystem/FileSystem+Extensions.swift b/Sources/Basics/FileSystem/FileSystem+Extensions.swift index d16637d5872..4a61f56f006 100644 --- a/Sources/Basics/FileSystem/FileSystem+Extensions.swift +++ b/Sources/Basics/FileSystem/FileSystem+Extensions.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors +// Copyright (c) 2020-2024 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 @@ -21,7 +21,6 @@ import class TSCBasic.FileLock import enum TSCBasic.FileMode import protocol TSCBasic.FileSystem import enum TSCBasic.FileSystemAttribute -import class TSCBasic.InMemoryFileSystem import var TSCBasic.localFileSystem import protocol TSCBasic.WritableByteStream diff --git a/Sources/Basics/FileSystem/InMemoryFileSystem.swift b/Sources/Basics/FileSystem/InMemoryFileSystem.swift new file mode 100644 index 00000000000..04420e98210 --- /dev/null +++ b/Sources/Basics/FileSystem/InMemoryFileSystem.swift @@ -0,0 +1,496 @@ +/* + This source file is part of the Swift.org open source project + + Copyright (c) 2014 - 2024 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 class Foundation.NSLock +import class Dispatch.DispatchQueue +import struct TSCBasic.AbsolutePath +import struct TSCBasic.ByteString +import class TSCBasic.FileLock +import enum TSCBasic.FileMode +import struct TSCBasic.FileSystemError + +/// Concrete FileSystem implementation which simulates an empty disk. +public final class InMemoryFileSystem: FileSystem { + /// Private internal representation of a file system node. + /// Not thread-safe. + private class Node { + /// The actual node data. + let contents: NodeContents + + /// Whether the node has executable bit enabled. + var isExecutable: Bool + + init(_ contents: NodeContents, isExecutable: Bool = false) { + self.contents = contents + self.isExecutable = isExecutable + } + + /// Creates deep copy of the object. + func copy() -> Node { + return Node(contents.copy()) + } + } + + /// Private internal representation the contents of a file system node. + /// Not thread-safe. + private enum NodeContents { + case file(ByteString) + case directory(DirectoryContents) + case symlink(String) + + /// Creates deep copy of the object. + func copy() -> NodeContents { + switch self { + case .file(let bytes): + return .file(bytes) + case .directory(let contents): + return .directory(contents.copy()) + case .symlink(let path): + return .symlink(path) + } + } + } + + /// Private internal representation the contents of a directory. + /// Not thread-safe. + private final class DirectoryContents { + var entries: [String: Node] + + init(entries: [String: Node] = [:]) { + self.entries = entries + } + + /// Creates deep copy of the object. + func copy() -> DirectoryContents { + let contents = DirectoryContents() + for (key, node) in entries { + contents.entries[key] = node.copy() + } + return contents + } + } + + /// The root node of the filesystem. + private var root: Node + + /// Protects `root` and everything underneath it. + /// FIXME: Using a single lock for this is a performance problem, but in + /// reality, the only practical use for InMemoryFileSystem is for unit + /// tests. + private let lock = NSLock() + /// A map that keeps weak references to all locked files. + private var lockFiles = Dictionary>() + /// Used to access lockFiles in a thread safe manner. + private let lockFilesLock = NSLock() + + /// Exclusive file system lock vended to clients through `withLock()`. + /// Used to ensure that DispatchQueues are released when they are no longer in use. + private struct WeakReference { + weak var reference: Value? + + init(_ value: Value?) { + self.reference = value + } + } + + public init() { + root = Node(.directory(DirectoryContents())) + } + + /// Creates deep copy of the object. + public func copy() -> InMemoryFileSystem { + return lock.withLock { + let fs = InMemoryFileSystem() + fs.root = root.copy() + return fs + } + } + + /// Private function to look up the node corresponding to a path. + /// Not thread-safe. + private func getNode(_ path: TSCBasic.AbsolutePath, followSymlink: Bool = true) throws -> Node? { + func getNodeInternal(_ path: TSCBasic.AbsolutePath) throws -> Node? { + // If this is the root node, return it. + if path.isRoot { + return root + } + + // Otherwise, get the parent node. + guard let parent = try getNodeInternal(path.parentDirectory) else { + return nil + } + + // If we didn't find a directory, this is an error. + guard case .directory(let contents) = parent.contents else { + throw FileSystemError(.notDirectory, path.parentDirectory) + } + + // Return the directory entry. + let node = contents.entries[path.basename] + + switch node?.contents { + case .directory, .file: + return node + case .symlink(let destination): + let destination = try TSCBasic.AbsolutePath(validating: destination, relativeTo: path.parentDirectory) + return followSymlink ? try getNodeInternal(destination) : node + case .none: + return nil + } + } + + // Get the node that corresponds to the path. + return try getNodeInternal(path) + } + + // MARK: FileSystem Implementation + + public func exists(_ path: TSCBasic.AbsolutePath, followSymlink: Bool) -> Bool { + return lock.withLock { + do { + switch try getNode(path, followSymlink: followSymlink)?.contents { + case .file, .directory, .symlink: return true + case .none: return false + } + } catch { + return false + } + } + } + + public func isDirectory(_ path: TSCBasic.AbsolutePath) -> Bool { + return lock.withLock { + do { + if case .directory? = try getNode(path)?.contents { + return true + } + return false + } catch { + return false + } + } + } + + public func isFile(_ path: TSCBasic.AbsolutePath) -> Bool { + return lock.withLock { + do { + if case .file? = try getNode(path)?.contents { + return true + } + return false + } catch { + return false + } + } + } + + public func isSymlink(_ path: TSCBasic.AbsolutePath) -> Bool { + return lock.withLock { + do { + if case .symlink? = try getNode(path, followSymlink: false)?.contents { + return true + } + return false + } catch { + return false + } + } + } + + public func isReadable(_ path: TSCBasic.AbsolutePath) -> Bool { + self.exists(path) + } + + public func isWritable(_ path: TSCBasic.AbsolutePath) -> Bool { + self.exists(path) + } + + public func isExecutableFile(_ path: TSCBasic.AbsolutePath) -> Bool { + (try? self.getNode(path)?.isExecutable) ?? false + } + + public func updatePermissions(_ path: AbsolutePath, isExecutable: Bool) throws { + try lock.withLock { + guard let node = try self.getNode(path.underlying, followSymlink: true) else { + throw FileSystemError(.noEntry, path) + } + node.isExecutable = isExecutable + } + } + + /// Virtualized current working directory. + public var currentWorkingDirectory: TSCBasic.AbsolutePath? { + return try? .init(validating: "/") + } + + public func changeCurrentWorkingDirectory(to path: TSCBasic.AbsolutePath) throws { + throw FileSystemError(.unsupported, path) + } + + public var homeDirectory: TSCBasic.AbsolutePath { + get throws { + // FIXME: Maybe we should allow setting this when creating the fs. + return try .init(validating: "/home/user") + } + } + + public var cachesDirectory: TSCBasic.AbsolutePath? { + return try? self.homeDirectory.appending(component: "caches") + } + + public var tempDirectory: TSCBasic.AbsolutePath { + get throws { + return try .init(validating: "/tmp") + } + } + + public func getDirectoryContents(_ path: TSCBasic.AbsolutePath) throws -> [String] { + return try lock.withLock { + guard let node = try getNode(path) else { + throw FileSystemError(.noEntry, path) + } + guard case .directory(let contents) = node.contents else { + throw FileSystemError(.notDirectory, path) + } + + // FIXME: Perhaps we should change the protocol to allow lazy behavior. + return [String](contents.entries.keys) + } + } + + /// Not thread-safe. + private func _createDirectory(_ path: TSCBasic.AbsolutePath, recursive: Bool) throws { + // Ignore if client passes root. + guard !path.isRoot else { + return + } + // Get the parent directory node. + let parentPath = path.parentDirectory + guard let parent = try getNode(parentPath) else { + // If the parent doesn't exist, and we are recursive, then attempt + // to create the parent and retry. + if recursive && path != parentPath { + // Attempt to create the parent. + try _createDirectory(parentPath, recursive: true) + + // Re-attempt creation, non-recursively. + return try _createDirectory(path, recursive: false) + } else { + // Otherwise, we failed. + throw FileSystemError(.noEntry, parentPath) + } + } + + // Check that the parent is a directory. + guard case .directory(let contents) = parent.contents else { + // The parent isn't a directory, this is an error. + throw FileSystemError(.notDirectory, parentPath) + } + + // Check if the node already exists. + if let node = contents.entries[path.basename] { + // Verify it is a directory. + guard case .directory = node.contents else { + // The path itself isn't a directory, this is an error. + throw FileSystemError(.notDirectory, path) + } + + // We are done. + return + } + + // Otherwise, the node does not exist, create it. + contents.entries[path.basename] = Node(.directory(DirectoryContents())) + } + + public func createDirectory(_ path: TSCBasic.AbsolutePath, recursive: Bool) throws { + return try lock.withLock { + try _createDirectory(path, recursive: recursive) + } + } + + public func createSymbolicLink( + _ path: TSCBasic.AbsolutePath, + pointingAt destination: TSCBasic.AbsolutePath, + relative: Bool + ) throws { + return try lock.withLock { + // Create directory to destination parent. + guard let destinationParent = try getNode(path.parentDirectory) else { + throw FileSystemError(.noEntry, path.parentDirectory) + } + + // Check that the parent is a directory. + guard case .directory(let contents) = destinationParent.contents else { + throw FileSystemError(.notDirectory, path.parentDirectory) + } + + guard contents.entries[path.basename] == nil else { + throw FileSystemError(.alreadyExistsAtDestination, path) + } + + let destination = relative ? destination.relative(to: path.parentDirectory).pathString : destination.pathString + + contents.entries[path.basename] = Node(.symlink(destination)) + } + } + + public func readFileContents(_ path: TSCBasic.AbsolutePath) throws -> ByteString { + return try lock.withLock { + // Get the node. + guard let node = try getNode(path) else { + throw FileSystemError(.noEntry, path) + } + + // Check that the node is a file. + guard case .file(let contents) = node.contents else { + // The path is a directory, this is an error. + throw FileSystemError(.isDirectory, path) + } + + // Return the file contents. + return contents + } + } + + public func writeFileContents(_ path: TSCBasic.AbsolutePath, bytes: ByteString) throws { + return try lock.withLock { + // It is an error if this is the root node. + let parentPath = path.parentDirectory + guard path != parentPath else { + throw FileSystemError(.isDirectory, path) + } + + // Get the parent node. + guard let parent = try getNode(parentPath) else { + throw FileSystemError(.noEntry, parentPath) + } + + // Check that the parent is a directory. + guard case .directory(let contents) = parent.contents else { + // The parent isn't a directory, this is an error. + throw FileSystemError(.notDirectory, parentPath) + } + + // Check if the node exists. + if let node = contents.entries[path.basename] { + // Verify it is a file. + guard case .file = node.contents else { + // The path is a directory, this is an error. + throw FileSystemError(.isDirectory, path) + } + } + + // Write the file. + contents.entries[path.basename] = Node(.file(bytes)) + } + } + + public func writeFileContents(_ path: TSCBasic.AbsolutePath, bytes: ByteString, atomically: Bool) throws { + // In memory file system's writeFileContents is already atomic, so ignore the parameter here + // and just call the base implementation. + try writeFileContents(path, bytes: bytes) + } + + public func removeFileTree(_ path: TSCBasic.AbsolutePath) throws { + return lock.withLock { + // Ignore root and get the parent node's content if its a directory. + guard !path.isRoot, + let parent = try? getNode(path.parentDirectory), + case .directory(let contents) = parent.contents else { + return + } + // Set it to nil to release the contents. + contents.entries[path.basename] = nil + } + } + + public func chmod(_ mode: FileMode, path: TSCBasic.AbsolutePath, options: Set) throws { + // FIXME: We don't have these semantics in InMemoryFileSystem. + } + + /// Private implementation of core copying function. + /// Not thread-safe. + private func _copy(from sourcePath: TSCBasic.AbsolutePath, to destinationPath: TSCBasic.AbsolutePath) throws { + // Get the source node. + guard let source = try getNode(sourcePath) else { + throw FileSystemError(.noEntry, sourcePath) + } + + // Create directory to destination parent. + guard let destinationParent = try getNode(destinationPath.parentDirectory) else { + throw FileSystemError(.noEntry, destinationPath.parentDirectory) + } + + // Check that the parent is a directory. + guard case .directory(let contents) = destinationParent.contents else { + throw FileSystemError(.notDirectory, destinationPath.parentDirectory) + } + + guard contents.entries[destinationPath.basename] == nil else { + throw FileSystemError(.alreadyExistsAtDestination, destinationPath) + } + + contents.entries[destinationPath.basename] = source + } + + public func copy(from sourcePath: TSCBasic.AbsolutePath, to destinationPath: TSCBasic.AbsolutePath) throws { + return try lock.withLock { + try _copy(from: sourcePath, to: destinationPath) + } + } + + public func move(from sourcePath: TSCBasic.AbsolutePath, to destinationPath: TSCBasic.AbsolutePath) throws { + return try lock.withLock { + // Get the source parent node. + guard let sourceParent = try getNode(sourcePath.parentDirectory) else { + throw FileSystemError(.noEntry, sourcePath.parentDirectory) + } + + // Check that the parent is a directory. + guard case .directory(let contents) = sourceParent.contents else { + throw FileSystemError(.notDirectory, sourcePath.parentDirectory) + } + + try _copy(from: sourcePath, to: destinationPath) + + contents.entries[sourcePath.basename] = nil + } + } + + public func withLock( + on path: TSCBasic.AbsolutePath, + type: FileLock.LockType = .exclusive, + _ body: () throws -> T + ) throws -> T { + let resolvedPath: TSCBasic.AbsolutePath = try lock.withLock { + if case let .symlink(destination) = try getNode(path)?.contents { + return try .init(validating: destination, relativeTo: path.parentDirectory) + } else { + return path + } + } + + let fileQueue: DispatchQueue = lockFilesLock.withLock { + if let queueReference = lockFiles[resolvedPath], let queue = queueReference.reference { + return queue + } else { + let queue = DispatchQueue(label: "org.swift.swiftpm.in-memory-file-system.file-queue", attributes: .concurrent) + lockFiles[resolvedPath] = WeakReference(queue) + return queue + } + } + + return try fileQueue.sync(flags: type == .exclusive ? .barrier : .init() , execute: body) + } +} + +// Internal state of `InMemoryFileSystem` is protected with a lock in all of its `public` methods. +extension InMemoryFileSystem: @unchecked Sendable {} diff --git a/Sources/CoreCommands/SwiftCommandState.swift b/Sources/CoreCommands/SwiftCommandState.swift index 754a5401ea4..d1547d03ca8 100644 --- a/Sources/CoreCommands/SwiftCommandState.swift +++ b/Sources/CoreCommands/SwiftCommandState.swift @@ -294,9 +294,10 @@ package final class SwiftCommandState { options: GlobalOptions, toolWorkspaceConfiguration: ToolWorkspaceConfiguration, workspaceDelegateProvider: @escaping WorkspaceDelegateProvider, - workspaceLoaderProvider: @escaping WorkspaceLoaderProvider + workspaceLoaderProvider: @escaping WorkspaceLoaderProvider, + fileSystem: any FileSystem = localFileSystem ) throws { - self.fileSystem = localFileSystem + self.fileSystem = fileSystem // first, bootstrap the observability system self.logLevel = options.logging.logLevel self.observabilityHandler = SwiftCommandObservabilityHandler(outputStream: outputStream, logLevel: self.logLevel) @@ -842,16 +843,19 @@ package final class SwiftCommandState { return self._hostToolchain } - return Result(catching: { try UserToolchain(swiftSDK: swiftSDK) }) + return Result(catching: { try UserToolchain(swiftSDK: swiftSDK, fileSystem: self.fileSystem) }) }() /// Lazily compute the host toolchain used to compile the package description. private lazy var _hostToolchain: Result = { return Result(catching: { - try UserToolchain(swiftSDK: SwiftSDK.hostSwiftSDK( - originalWorkingDirectory: self.originalWorkingDirectory, - observabilityScope: self.observabilityScope - )) + try UserToolchain( + swiftSDK: SwiftSDK.hostSwiftSDK( + originalWorkingDirectory: self.originalWorkingDirectory, + observabilityScope: self.observabilityScope + ), + fileSystem: self.fileSystem + ) }) }() diff --git a/Sources/PackageModel/UserToolchain.swift b/Sources/PackageModel/UserToolchain.swift index 9b7042332bb..ba6ff8eba3b 100644 --- a/Sources/PackageModel/UserToolchain.swift +++ b/Sources/PackageModel/UserToolchain.swift @@ -58,6 +58,8 @@ public final class UserToolchain: Toolchain { self.swiftCompilerPath.parentDirectory.appending("swift" + hostExecutableSuffix) } + private let fileSystem: any FileSystem + /// The compilation destination object. @available(*, deprecated, renamed: "swiftSDK") public var destination: SwiftSDK { swiftSDK } @@ -103,7 +105,7 @@ public final class UserToolchain: Toolchain { ) // Ensure that the runtime is present. - guard localFileSystem.exists(runtime) else { + guard fileSystem.exists(runtime) else { throw InvalidToolchainDiagnostic("Missing runtime for \(sanitizer) sanitizer") } @@ -120,13 +122,17 @@ public final class UserToolchain: Toolchain { lookupExecutablePath(filename: environment[variable], searchPaths: searchPaths) } - private static func getTool(_ name: String, binDirectories: [AbsolutePath]) throws -> AbsolutePath { + private static func getTool( + _ name: String, + binDirectories: [AbsolutePath], + fileSystem: any FileSystem + ) throws -> AbsolutePath { let executableName = "\(name)\(hostExecutableSuffix)" var toolPath: AbsolutePath? for dir in binDirectories { let path = dir.appending(component: executableName) - guard localFileSystem.isExecutableFile(path) else { + guard fileSystem.isExecutableFile(path) else { continue } toolPath = path @@ -142,7 +148,8 @@ public final class UserToolchain: Toolchain { private static func findTool( _ name: String, envSearchPaths: [AbsolutePath], - useXcrun: Bool + useXcrun: Bool, + fileSystem: any FileSystem ) throws -> AbsolutePath { if useXcrun { #if os(macOS) @@ -152,7 +159,7 @@ public final class UserToolchain: Toolchain { #endif } - return try getTool(name, binDirectories: envSearchPaths) + return try getTool(name, binDirectories: envSearchPaths, fileSystem: fileSystem) } // MARK: - public API @@ -163,10 +170,9 @@ public final class UserToolchain: Toolchain { useXcrun: Bool, environment: EnvironmentVariables, searchPaths: [AbsolutePath], - extraSwiftFlags: [String] - ) throws - -> AbsolutePath - { + extraSwiftFlags: [String], + fileSystem: any FileSystem + ) throws -> AbsolutePath { let variable: String = triple.isApple() ? "LIBTOOL" : "AR" let tool: String = { if triple.isApple() { return "libtool" } @@ -196,25 +202,25 @@ public final class UserToolchain: Toolchain { searchPaths: searchPaths, environment: environment ) { - if localFileSystem.isExecutableFile(librarian) { + if fileSystem.isExecutableFile(librarian) { return librarian } } - if let librarian = try? UserToolchain.getTool(tool, binDirectories: binDirectories) { + if let librarian = try? UserToolchain.getTool(tool, binDirectories: binDirectories, fileSystem: fileSystem) { return librarian } if triple.isApple() || triple.isWindows() { - return try UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: useXcrun) + return try UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: useXcrun, fileSystem: fileSystem) } else { - if let librarian = try? UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: false) { + if let librarian = try? UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: false, fileSystem: fileSystem) { return librarian } // Fall back to looking for binutils `ar` if `llvm-ar` can't be found. - if let librarian = try? UserToolchain.getTool("ar", binDirectories: binDirectories) { + if let librarian = try? UserToolchain.getTool("ar", binDirectories: binDirectories, fileSystem: fileSystem) { return librarian } - return try UserToolchain.findTool("ar", envSearchPaths: searchPaths, useXcrun: false) + return try UserToolchain.findTool("ar", envSearchPaths: searchPaths, useXcrun: false, fileSystem: fileSystem) } } @@ -223,11 +229,12 @@ public final class UserToolchain: Toolchain { binDirectories: [AbsolutePath], useXcrun: Bool, environment: EnvironmentVariables, - searchPaths: [AbsolutePath] + searchPaths: [AbsolutePath], + fileSystem: any FileSystem ) throws -> SwiftCompilers { func validateCompiler(at path: AbsolutePath?) throws { guard let path else { return } - guard localFileSystem.isExecutableFile(path) else { + guard fileSystem.isExecutableFile(path) else { throw InvalidToolchainDiagnostic( "could not find the `swiftc\(hostExecutableSuffix)` at expected path \(path)" ) @@ -248,7 +255,7 @@ public final class UserToolchain: Toolchain { let resolvedBinDirCompiler: AbsolutePath if let SWIFT_EXEC { resolvedBinDirCompiler = SWIFT_EXEC - } else if let binDirCompiler = try? UserToolchain.getTool("swiftc", binDirectories: binDirectories) { + } else if let binDirCompiler = try? UserToolchain.getTool("swiftc", binDirectories: binDirectories, fileSystem: fileSystem) { resolvedBinDirCompiler = binDirCompiler } else { // Try to lookup swift compiler on the system which is possible when @@ -256,13 +263,14 @@ public final class UserToolchain: Toolchain { resolvedBinDirCompiler = try UserToolchain.findTool( "swiftc", envSearchPaths: searchPaths, - useXcrun: useXcrun + useXcrun: useXcrun, + fileSystem: fileSystem ) } // The compiler for compilation tasks is SWIFT_EXEC or the bin dir compiler. // The compiler for manifest is either SWIFT_EXEC_MANIFEST or the bin dir compiler. - return (SWIFT_EXEC ?? resolvedBinDirCompiler, SWIFT_EXEC_MANIFEST ?? resolvedBinDirCompiler) + return (compile: SWIFT_EXEC ?? resolvedBinDirCompiler, manifest: SWIFT_EXEC_MANIFEST ?? resolvedBinDirCompiler) } /// Returns the path to clang compiler tool. @@ -283,15 +291,22 @@ public final class UserToolchain: Toolchain { } // Then, check the toolchain. - do { - if let toolPath = try? UserToolchain.getTool("clang", binDirectories: self.swiftSDK.toolset.rootPaths) { - self._clangCompiler = toolPath - return toolPath - } + if let toolPath = try? UserToolchain.getTool( + "clang", + binDirectories: self.swiftSDK.toolset.rootPaths, + fileSystem: self.fileSystem + ) { + self._clangCompiler = toolPath + return toolPath } // Otherwise, lookup it up on the system. - let toolPath = try UserToolchain.findTool("clang", envSearchPaths: self.envSearchPaths, useXcrun: useXcrun) + let toolPath = try UserToolchain.findTool( + "clang", + envSearchPaths: self.envSearchPaths, + useXcrun: useXcrun, + fileSystem: self.fileSystem + ) self._clangCompiler = toolPath return toolPath } @@ -309,21 +324,38 @@ public final class UserToolchain: Toolchain { /// Returns the path to lldb. public func getLLDB() throws -> AbsolutePath { // Look for LLDB next to the compiler first. - if let lldbPath = try? UserToolchain.getTool("lldb", binDirectories: [self.swiftCompilerPath.parentDirectory]) { + if let lldbPath = try? UserToolchain.getTool( + "lldb", + binDirectories: [self.swiftCompilerPath.parentDirectory], + fileSystem: self.fileSystem + ) { return lldbPath } // If that fails, fall back to xcrun, PATH, etc. - return try UserToolchain.findTool("lldb", envSearchPaths: self.envSearchPaths, useXcrun: useXcrun) + return try UserToolchain.findTool( + "lldb", + envSearchPaths: self.envSearchPaths, + useXcrun: useXcrun, + fileSystem: self.fileSystem + ) } /// Returns the path to llvm-cov tool. public func getLLVMCov() throws -> AbsolutePath { - try UserToolchain.getTool("llvm-cov", binDirectories: [self.swiftCompilerPath.parentDirectory]) + try UserToolchain.getTool( + "llvm-cov", + binDirectories: [self.swiftCompilerPath.parentDirectory], + fileSystem: self.fileSystem + ) } /// Returns the path to llvm-prof tool. public func getLLVMProf() throws -> AbsolutePath { - try UserToolchain.getTool("llvm-profdata", binDirectories: [self.swiftCompilerPath.parentDirectory]) + try UserToolchain.getTool( + "llvm-profdata", + binDirectories: [self.swiftCompilerPath.parentDirectory], + fileSystem: self.fileSystem + ) } public func getSwiftAPIDigester() throws -> AbsolutePath { @@ -334,7 +366,12 @@ public final class UserToolchain: Toolchain { ) { return envValue } - return try UserToolchain.getTool("swift-api-digester", binDirectories: [self.swiftCompilerPath.parentDirectory]) + return try UserToolchain.getTool( + "swift-api-digester", + binDirectories: [self.swiftCompilerPath.parentDirectory], + fileSystem: self.fileSystem + + ) } public func getSymbolGraphExtract() throws -> AbsolutePath { @@ -345,13 +382,18 @@ public final class UserToolchain: Toolchain { ) { return envValue } - return try UserToolchain.getTool("swift-symbolgraph-extract", binDirectories: [self.swiftCompilerPath.parentDirectory]) + return try UserToolchain.getTool( + "swift-symbolgraph-extract", + binDirectories: [self.swiftCompilerPath.parentDirectory], + fileSystem: self.fileSystem + ) } internal static func deriveSwiftCFlags( triple: Triple, swiftSDK: SwiftSDK, - environment: EnvironmentVariables + environment: EnvironmentVariables, + fileSystem: any FileSystem ) throws -> [String] { var swiftCompilerFlags = swiftSDK.toolset.knownTools[.swiftCompiler]?.extraCLIOptions ?? [] @@ -372,7 +414,7 @@ public final class UserToolchain: Toolchain { if let settings = WindowsSDKSettings( reading: sdkroot.appending("SDKSettings.plist"), observabilityScope: nil, - filesystem: localFileSystem + filesystem: fileSystem ) { switch settings.defaults.runtime { case .multithreadedDebugDLL: @@ -397,7 +439,7 @@ public final class UserToolchain: Toolchain { if let info = WindowsPlatformInfo( reading: platform.appending("Info.plist"), observabilityScope: nil, - filesystem: localFileSystem + filesystem: fileSystem ) { let installation: AbsolutePath = platform.appending("Developer") @@ -438,7 +480,7 @@ public final class UserToolchain: Toolchain { validating: "usr/lib/swift/windows/XCTest.lib", relativeTo: installation ) - if localFileSystem.exists(implib) { + if fileSystem.exists(implib) { xctest.append(contentsOf: ["-L", implib.parentDirectory.pathString]) } @@ -477,7 +519,8 @@ public final class UserToolchain: Toolchain { swiftSDK: destination, environment: environment, searchStrategy: searchStrategy, - customLibrariesLocation: customLibrariesLocation + customLibrariesLocation: customLibrariesLocation, + fileSystem: localFileSystem ) } @@ -487,7 +530,8 @@ public final class UserToolchain: Toolchain { searchStrategy: SearchStrategy = .default, customLibrariesLocation: ToolchainConfiguration.SwiftPMLibrariesLocation? = nil, customInstalledSwiftPMConfiguration: InstalledSwiftPMConfiguration? = nil, - customProvidedLibraries: [LibraryMetadata]? = nil + customProvidedLibraries: [LibraryMetadata]? = nil, + fileSystem: any FileSystem = localFileSystem ) throws { self.swiftSDK = swiftSDK self.environment = environment @@ -497,7 +541,7 @@ public final class UserToolchain: Toolchain { // Get the search paths from PATH. self.envSearchPaths = getEnvSearchPaths( pathString: environment.path, - currentWorkingDirectory: localFileSystem.currentWorkingDirectory + currentWorkingDirectory: fileSystem.currentWorkingDirectory ) self.useXcrun = true case .custom(let searchPaths, let useXcrun): @@ -509,7 +553,8 @@ public final class UserToolchain: Toolchain { binDirectories: swiftSDK.toolset.rootPaths, useXcrun: useXcrun, environment: environment, - searchPaths: envSearchPaths + searchPaths: envSearchPaths, + fileSystem: fileSystem ) self.swiftCompilerPath = swiftCompilers.compile self.architectures = swiftSDK.architectures @@ -517,7 +562,7 @@ public final class UserToolchain: Toolchain { #if canImport(Darwin) let toolchainPlistPath = self.swiftCompilerPath.parentDirectory.parentDirectory.parentDirectory .appending(component: "Info.plist") - if localFileSystem.exists(toolchainPlistPath), let toolchainPlist = try? NSDictionary( + if fileSystem.exists(toolchainPlistPath), let toolchainPlist = try? NSDictionary( contentsOf: URL(fileURLWithPath: toolchainPlistPath.pathString), error: () ), let overrideBuildSettings = toolchainPlist["OverrideBuildSettings"] as? NSDictionary, @@ -572,7 +617,9 @@ public final class UserToolchain: Toolchain { swiftCompilerFlags: try Self.deriveSwiftCFlags( triple: triple, swiftSDK: swiftSDK, - environment: environment), + environment: environment, + fileSystem: fileSystem + ), linkerFlags: swiftSDK.toolset.knownTools[.linker]?.extraCLIOptions ?? [], xcbuildFlags: swiftSDK.toolset.knownTools[.xcbuild]?.extraCLIOptions ?? []) @@ -585,7 +632,8 @@ public final class UserToolchain: Toolchain { useXcrun: useXcrun, environment: environment, searchPaths: envSearchPaths, - extraSwiftFlags: self.extraFlags.swiftCompilerFlags + extraSwiftFlags: self.extraFlags.swiftCompilerFlags, + fileSystem: fileSystem ) if let sdkDir = swiftSDK.pathsConfiguration.sdkRootPath { @@ -598,7 +646,7 @@ public final class UserToolchain: Toolchain { if let settings = WindowsSDKSettings( reading: root.appending("SDKSettings.plist"), observabilityScope: nil, - filesystem: localFileSystem + filesystem: fileSystem ) { switch settings.defaults.runtime { case .multithreadedDebugDLL: @@ -634,7 +682,8 @@ public final class UserToolchain: Toolchain { let swiftPMLibrariesLocation = try customLibrariesLocation ?? Self.deriveSwiftPMLibrariesLocation( swiftCompilerPath: swiftCompilerPath, swiftSDK: swiftSDK, - environment: environment + environment: environment, + fileSystem: fileSystem ) let xctestPath: AbsolutePath? @@ -644,7 +693,8 @@ public final class UserToolchain: Toolchain { xctestPath = try Self.deriveXCTestPath( swiftSDK: self.swiftSDK, triple: triple, - environment: environment + environment: environment, + fileSystem: fileSystem ) } @@ -657,12 +707,15 @@ public final class UserToolchain: Toolchain { sdkRootPath: self.swiftSDK.pathsConfiguration.sdkRootPath, xctestPath: xctestPath ) + + self.fileSystem = fileSystem } private static func deriveSwiftPMLibrariesLocation( swiftCompilerPath: AbsolutePath, swiftSDK: SwiftSDK, - environment: EnvironmentVariables + environment: EnvironmentVariables, + fileSystem: any FileSystem ) throws -> ToolchainConfiguration.SwiftPMLibrariesLocation? { // Look for an override in the env. if let pathEnvVariable = environment["SWIFTPM_CUSTOM_LIBS_DIR"] ?? environment["SWIFTPM_PD_LIBS"] { @@ -678,7 +731,7 @@ public final class UserToolchain: Toolchain { #endif let paths = pathEnvVariable.split(separator: separator).map(String.init) for pathString in paths { - if let path = try? AbsolutePath(validating: pathString), localFileSystem.exists(path) { + if let path = try? AbsolutePath(validating: pathString), fileSystem.exists(path) { // we found the custom one return .init(root: path) } @@ -697,7 +750,7 @@ public final class UserToolchain: Toolchain { for applicationPath in swiftSDK.toolset.rootPaths { // this is the normal case when using the toolchain let librariesPath = applicationPath.parentDirectory.appending(components: "lib", "swift", "pm") - if localFileSystem.exists(librariesPath) { + if fileSystem.exists(librariesPath) { return .init(root: librariesPath) } @@ -707,7 +760,7 @@ public final class UserToolchain: Toolchain { "PackageDescription.framework" ) let pluginFrameworksPath = applicationPath.appending(components: "PackageFrameworks", "PackagePlugin.framework") - if localFileSystem.exists(manifestFrameworksPath), localFileSystem.exists(pluginFrameworksPath) { + if fileSystem.exists(manifestFrameworksPath), fileSystem.exists(pluginFrameworksPath) { return .init( manifestLibraryPath: manifestFrameworksPath, pluginLibraryPath: pluginFrameworksPath @@ -752,7 +805,8 @@ public final class UserToolchain: Toolchain { private static func deriveXCTestPath( swiftSDK: SwiftSDK, triple: Triple, - environment: EnvironmentVariables + environment: EnvironmentVariables, + fileSystem: any FileSystem ) throws -> AbsolutePath? { if triple.isDarwin() { // XCTest is optional on macOS, for example when Xcode is not installed @@ -784,7 +838,7 @@ public final class UserToolchain: Toolchain { if let info = WindowsPlatformInfo( reading: platform.appending("Info.plist"), observabilityScope: nil, - filesystem: localFileSystem + filesystem: fileSystem ) { let xctest: AbsolutePath = platform.appending("Developer") @@ -804,7 +858,7 @@ public final class UserToolchain: Toolchain { let path: AbsolutePath = xctest.appending("usr") .appending("bin64") - if localFileSystem.exists(path) { + if fileSystem.exists(path) { return path } @@ -812,7 +866,7 @@ public final class UserToolchain: Toolchain { let path: AbsolutePath = xctest.appending("usr") .appending("bin32") - if localFileSystem.exists(path) { + if fileSystem.exists(path) { return path } @@ -820,7 +874,7 @@ public final class UserToolchain: Toolchain { let path: AbsolutePath = xctest.appending("usr") .appending("bin32a") - if localFileSystem.exists(path) { + if fileSystem.exists(path) { return path } @@ -828,7 +882,7 @@ public final class UserToolchain: Toolchain { let path: AbsolutePath = xctest.appending("usr") .appending("bin64a") - if localFileSystem.exists(path) { + if fileSystem.exists(path) { return path } diff --git a/Sources/SPMTestSupport/Toolchain.swift b/Sources/SPMTestSupport/Toolchain.swift index 35a1a2c3c11..ae2914432ad 100644 --- a/Sources/SPMTestSupport/Toolchain.swift +++ b/Sources/SPMTestSupport/Toolchain.swift @@ -49,7 +49,7 @@ extension SwiftSDK { extension UserToolchain { package static var `default`: Self { get throws { - return try .init(swiftSDK: SwiftSDK.default) + return try .init(swiftSDK: SwiftSDK.default, fileSystem: localFileSystem) } } } diff --git a/Sources/Workspace/Workspace.swift b/Sources/Workspace/Workspace.swift index e6016e3d554..2b12c4fe89d 100644 --- a/Sources/Workspace/Workspace.swift +++ b/Sources/Workspace/Workspace.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -426,7 +426,7 @@ public class Workspace { ) let currentToolsVersion = customToolsVersion ?? ToolsVersion.current - let hostToolchain = try customHostToolchain ?? UserToolchain(swiftSDK: .hostSwiftSDK()) + let hostToolchain = try customHostToolchain ?? UserToolchain(swiftSDK: .hostSwiftSDK(), fileSystem: fileSystem) var manifestLoader = customManifestLoader ?? ManifestLoader( toolchain: hostToolchain, cacheDir: location.sharedManifestsCacheDirectory, diff --git a/Tests/CommandsTests/SwiftCommandStateTests.swift b/Tests/CommandsTests/SwiftCommandStateTests.swift index bafa0b5f801..a87c031034a 100644 --- a/Tests/CommandsTests/SwiftCommandStateTests.swift +++ b/Tests/CommandsTests/SwiftCommandStateTests.swift @@ -26,7 +26,6 @@ import SPMTestSupport import XCTest import class TSCBasic.BufferedOutputByteStream -import class TSCBasic.InMemoryFileSystem import protocol TSCBasic.OutputByteStream import var TSCBasic.stderrStream @@ -322,12 +321,69 @@ final class SwiftCommandStateTests: CommandsTestCase { try XCTAssertMatch(plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [], [.anySequence, "-gnone", .anySequence]) } + + func testToolchainArgument() throws { + let fs = InMemoryFileSystem(emptyFiles: [ + "/Pkg/Sources/exe/main.swift", + "/path/to/toolchain/usr/bin/swiftc", + "/path/to/toolchain/usr/bin/llvm-ar", + ]) + + let customTargetToolchain = AbsolutePath("/path/to/toolchain") + try fs.createDirectory(customTargetToolchain, recursive: true) + + let swiftcPath = customTargetToolchain.appending(components: ["usr", "bin" , "swiftc"]) + let arPath = customTargetToolchain.appending(components: ["usr", "bin", "llvm-ar"]) + try fs.updatePermissions(swiftcPath, isExecutable: true) + try fs.updatePermissions(arPath, isExecutable: true) + + let observer = ObservabilitySystem.makeForTesting() + let graph = try loadModulesGraph( + fileSystem: fs, + manifests: [ + Manifest.createRootManifest( + displayName: "Pkg", + path: "/Pkg", + targets: [TargetDescription(name: "exe")] + ) + ], + observabilityScope: observer.topScope + ) + + let options = try GlobalOptions.parse( + [ + "--toolchain", customTargetToolchain.pathString, + "--triple", "x86_64-unknown-linux-gnu", + ] + ) + let swiftCommandState = try SwiftCommandState.makeMockState(options: options, fileSystem: fs) + XCTAssertEqual( + try swiftCommandState.getTargetToolchain().swiftCompilerPath, + swiftcPath + ) + XCTAssertEqual( + try swiftCommandState.getTargetToolchain().swiftSDK.toolset.knownTools[.swiftCompiler]?.path, + nil + ) + let plan = try BuildPlan( + destinationBuildParameters: swiftCommandState.productsBuildParameters, + toolsBuildParameters: swiftCommandState.toolsBuildParameters, + graph: graph, + fileSystem: fs, + observabilityScope: observer.topScope + ) + + let arguments = try plan.buildProducts.compactMap { $0 as? Build.ProductBuildDescription }.first?.linkArguments() ?? [] + + XCTAssertMatch(arguments, [.contains("/path/to/toolchain")]) + } } extension SwiftCommandState { static func makeMockState( outputStream: OutputByteStream = stderrStream, - options: GlobalOptions + options: GlobalOptions, + fileSystem: any FileSystem = localFileSystem ) throws -> SwiftCommandState { return try SwiftCommandState( outputStream: outputStream, @@ -346,6 +402,8 @@ extension SwiftCommandState { fileSystem: $0, observabilityScope: $1 ) - }) + }, + fileSystem: fileSystem + ) } } diff --git a/Tests/PackageModelTests/PackageModelTests.swift b/Tests/PackageModelTests/PackageModelTests.swift index 54c32fa276e..1a0dc648a94 100644 --- a/Tests/PackageModelTests/PackageModelTests.swift +++ b/Tests/PackageModelTests/PackageModelTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -17,7 +17,7 @@ import XCTest import struct TSCBasic.ByteString -class PackageModelTests: XCTestCase { +final class PackageModelTests: XCTestCase { func testProductTypeCodable() throws { struct Foo: Codable, Equatable { var type: ProductType @@ -58,8 +58,11 @@ class PackageModelTests: XCTestCase { func testAndroidCompilerFlags() throws { let triple = try Triple("x86_64-unknown-linux-android") + let fileSystem = InMemoryFileSystem() let sdkDir = AbsolutePath("/some/path/to/an/SDK.sdk") + try fileSystem.createDirectory(sdkDir) let toolchainPath = AbsolutePath("/some/path/to/a/toolchain.xctoolchain") + try fileSystem.createDirectory(toolchainPath) let swiftSDK = SwiftSDK( targetTriple: triple, @@ -68,10 +71,16 @@ class PackageModelTests: XCTestCase { ) XCTAssertEqual( - try UserToolchain.deriveSwiftCFlags(triple: triple, swiftSDK: swiftSDK, environment: .process()), + try UserToolchain.deriveSwiftCFlags( + triple: triple, + swiftSDK: swiftSDK, + environment: .process(), + fileSystem: fileSystem + ), [ // Needed when cross‐compiling for Android. 2020‐03‐01 - "-sdk", sdkDir.pathString, + "-sdk", + sdkDir.pathString, ] ) } @@ -120,7 +129,8 @@ class PackageModelTests: XCTestCase { try XCTAssertEqual( UserToolchain.determineLibrarian( triple: triple, binDirectories: [bin], useXcrun: false, environment: [:], searchPaths: [], - extraSwiftFlags: ["-Xswiftc", "-use-ld=lld"] + extraSwiftFlags: ["-Xswiftc", "-use-ld=lld"], + fileSystem: fs ), lld ) @@ -128,7 +138,8 @@ class PackageModelTests: XCTestCase { try XCTAssertEqual( UserToolchain.determineLibrarian( triple: triple, binDirectories: [bin], useXcrun: false, environment: [:], searchPaths: [], - extraSwiftFlags: ["-Xswiftc", "-use-ld=not-link"] + extraSwiftFlags: ["-Xswiftc", "-use-ld=not-link"], + fileSystem: fs ), not ) @@ -136,7 +147,8 @@ class PackageModelTests: XCTestCase { try XCTAssertThrowsError( UserToolchain.determineLibrarian( triple: triple, binDirectories: [bin], useXcrun: false, environment: [:], searchPaths: [], - extraSwiftFlags: [] + extraSwiftFlags: [], + fileSystem: fs ) ) } @@ -170,7 +182,8 @@ class PackageModelTests: XCTestCase { binDirectories: [toolchainBinDir], useXcrun: false, environment: [:], - searchPaths: binDirs + searchPaths: binDirs, + fileSystem: fs ) // The first swiftc in the search paths should be chosen. From 314fb0a2ae7f9c18a635305ad372715c5b70a12d Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Tue, 23 Apr 2024 12:36:12 +0100 Subject: [PATCH 2/4] Remove `TSCBasic.InMemoryFileSystem` dependency Since https://github.com/apple/swift-package-manager/pull/7483 this type is implemented in SwiftPM. --- Sources/Basics/SQLiteBackedCache.swift | 1 - .../Storage/SQLitePackageCollectionsStorage.swift | 3 +-- Sources/SPMTestSupport/InMemoryGitRepository.swift | 3 +-- Sources/SPMTestSupport/MockPackageGraphs.swift | 2 +- Sources/SPMTestSupport/MockWorkspace.swift | 4 +--- .../PackageContainer/RegistryPackageContainer.swift | 4 +--- Sources/Workspace/Workspace+Editing.swift | 4 ++-- Sources/Workspace/Workspace.swift | 1 - Tests/BasicsTests/Archiver/TarArchiverTests.swift | 3 +-- Tests/BasicsTests/Archiver/UniversalArchiverTests.swift | 3 +-- Tests/BasicsTests/Archiver/ZipArchiverTests.swift | 5 ++--- Tests/BasicsTests/FileSystem/FileSystemTests.swift | 5 +---- Tests/BasicsTests/SandboxTests.swift | 3 +-- Tests/BuildTests/BuildOperationTests.swift | 1 - Tests/BuildTests/BuildPlanTests.swift | 1 - Tests/BuildTests/CrossCompilationBuildPlanTests.swift | 2 +- Tests/BuildTests/LLBuildManifestBuilderTests.swift | 3 +-- Tests/BuildTests/ModuleAliasingBuildTests.swift | 4 +--- Tests/BuildTests/ProductBuildDescriptionTests.swift | 4 ++-- Tests/CommandsTests/MermaidPackageSerializerTests.swift | 2 +- Tests/CommandsTests/MultiRootSupportTests.swift | 5 +---- Tests/CommandsTests/PackageCommandTests.swift | 3 +-- Tests/LLBuildManifestTests/LLBuildManifestTests.swift | 5 ++--- .../PackageCollectionsSourcesStorageTest.swift | 4 +--- .../PackageIndexConfigurationTests.swift | 6 ++---- Tests/PackageCollectionsTests/Utility.swift | 4 +--- .../FilePackageFingerprintStorageTests.swift | 4 +--- .../PackageGraphPerfTests.swift | 4 +--- Tests/PackageGraphTests/ModulesGraphTests.swift | 3 +-- Tests/PackageGraphTests/PubgrubTests.swift | 4 +--- Tests/PackageLoadingTests/ManifestLoaderCacheTests.swift | 3 +-- Tests/PackageLoadingTests/ModuleMapGenerationTests.swift | 7 ++----- Tests/PackageLoadingTests/PDLoadingTests.swift | 4 +--- Tests/PackageLoadingTests/PD_4_0_LoadingTests.swift | 4 +--- Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift | 3 +-- Tests/PackageLoadingTests/PackageBuilderTests.swift | 4 +--- Tests/PackageLoadingTests/PkgConfigParserTests.swift | 3 +-- Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift | 6 ++---- Tests/PackageLoadingTests/ToolsVersionParserTests.swift | 7 ++----- Tests/PackageModelTests/SwiftSDKBundleTests.swift | 3 +-- Tests/PackageModelTests/SwiftSDKTests.swift | 4 +--- Tests/PackageModelTests/ToolsetTests.swift | 4 +--- Tests/PackageRegistryTests/RegistryClientTests.swift | 4 +--- .../RegistryDownloadsManagerTests.swift | 6 ++---- .../FilePackageSigningEntityStorageTests.swift | 2 -- .../SPMBuildCoreTests/ArtifactsArchiveMetadataTests.swift | 4 +--- Tests/SPMBuildCoreTests/PluginInvocationTests.swift | 4 +--- Tests/SPMBuildCoreTests/XCFrameworkMetadataTests.swift | 5 ++--- Tests/SourceControlTests/InMemoryGitRepositoryTests.swift | 6 ++---- Tests/SourceControlTests/RepositoryManagerTests.swift | 5 ++--- Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift | 1 - Tests/WorkspaceTests/AuthorizationProviderTests.swift | 4 +--- Tests/WorkspaceTests/MirrorsConfigurationTests.swift | 4 +--- Tests/WorkspaceTests/PinsStoreTests.swift | 4 +--- Tests/WorkspaceTests/RegistryPackageContainerTests.swift | 4 +--- .../SourceControlPackageContainerTests.swift | 4 +--- .../ToolsVersionSpecificationRewriterTests.swift | 6 ++---- Tests/WorkspaceTests/WorkspaceStateTests.swift | 4 +--- Tests/WorkspaceTests/WorkspaceTests.swift | 3 +-- Tests/XCBuildSupportTests/PIFBuilderTests.swift | 6 ++---- 60 files changed, 68 insertions(+), 160 deletions(-) diff --git a/Sources/Basics/SQLiteBackedCache.swift b/Sources/Basics/SQLiteBackedCache.swift index 373755bd39b..129b84e2f3d 100644 --- a/Sources/Basics/SQLiteBackedCache.swift +++ b/Sources/Basics/SQLiteBackedCache.swift @@ -13,7 +13,6 @@ import Foundation import protocol TSCBasic.Closable -import class TSCBasic.InMemoryFileSystem import var TSCBasic.localFileSystem /// SQLite backed persistent cache. diff --git a/Sources/PackageCollections/Storage/SQLitePackageCollectionsStorage.swift b/Sources/PackageCollections/Storage/SQLitePackageCollectionsStorage.swift index 071080b4c10..2acac6a2703 100644 --- a/Sources/PackageCollections/Storage/SQLitePackageCollectionsStorage.swift +++ b/Sources/PackageCollections/Storage/SQLitePackageCollectionsStorage.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2020-2024 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 @@ -20,7 +20,6 @@ import struct Foundation.URL import PackageModel import protocol TSCBasic.Closable -import class TSCBasic.InMemoryFileSystem final class SQLitePackageCollectionsStorage: PackageCollectionsStorage, Closable { private static let packageCollectionsTableName = "package_collections" diff --git a/Sources/SPMTestSupport/InMemoryGitRepository.swift b/Sources/SPMTestSupport/InMemoryGitRepository.swift index 550dd3ed298..d189621ba7a 100644 --- a/Sources/SPMTestSupport/InMemoryGitRepository.swift +++ b/Sources/SPMTestSupport/InMemoryGitRepository.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -18,7 +18,6 @@ import SourceControl import struct TSCBasic.ByteString import enum TSCBasic.FileMode import struct TSCBasic.FileSystemError -import class TSCBasic.InMemoryFileSystem /// The error encountered during in memory git repository operations. package enum InMemoryGitRepositoryError: Swift.Error { diff --git a/Sources/SPMTestSupport/MockPackageGraphs.swift b/Sources/SPMTestSupport/MockPackageGraphs.swift index 00e12f77c19..57de3e477e8 100644 --- a/Sources/SPMTestSupport/MockPackageGraphs.swift +++ b/Sources/SPMTestSupport/MockPackageGraphs.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// import struct Basics.AbsolutePath +import class Basics.InMemoryFileSystem import class Basics.ObservabilitySystem import class Basics.ObservabilityScope @@ -23,7 +24,6 @@ import class PackageModel.Manifest import struct PackageModel.ProductDescription import struct PackageModel.TargetDescription import protocol TSCBasic.FileSystem -import class TSCBasic.InMemoryFileSystem package typealias MockPackageGraph = ( graph: ModulesGraph, diff --git a/Sources/SPMTestSupport/MockWorkspace.swift b/Sources/SPMTestSupport/MockWorkspace.swift index 717fc4f50ee..454d70e9751 100644 --- a/Sources/SPMTestSupport/MockWorkspace.swift +++ b/Sources/SPMTestSupport/MockWorkspace.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -19,8 +19,6 @@ import SourceControl import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version package final class MockWorkspace { diff --git a/Sources/Workspace/PackageContainer/RegistryPackageContainer.swift b/Sources/Workspace/PackageContainer/RegistryPackageContainer.swift index fc5d451c8c4..7829941a185 100644 --- a/Sources/Workspace/PackageContainer/RegistryPackageContainer.swift +++ b/Sources/Workspace/PackageContainer/RegistryPackageContainer.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2021 Apple Inc. and the Swift project authors +// Copyright (c) 2021-2024 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 @@ -17,8 +17,6 @@ import PackageLoading import PackageModel import PackageRegistry -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version public class RegistryPackageContainer: PackageContainer { diff --git a/Sources/Workspace/Workspace+Editing.swift b/Sources/Workspace/Workspace+Editing.swift index c27afe324a6..a58d641befd 100644 --- a/Sources/Workspace/Workspace+Editing.swift +++ b/Sources/Workspace/Workspace+Editing.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -11,13 +11,13 @@ //===----------------------------------------------------------------------===// import struct Basics.AbsolutePath +import class Basics.InMemoryFileSystem import class Basics.ObservabilityScope import struct Basics.RelativePath import func Basics.temp_await import struct PackageGraph.PackageGraphRootInput import struct PackageModel.LibraryMetadata import struct SourceControl.Revision -import class TSCBasic.InMemoryFileSystem extension Workspace { /// Edit implementation. diff --git a/Sources/Workspace/Workspace.swift b/Sources/Workspace/Workspace.swift index 2b12c4fe89d..43e0b55991f 100644 --- a/Sources/Workspace/Workspace.swift +++ b/Sources/Workspace/Workspace.swift @@ -23,7 +23,6 @@ import SourceControl import func TSCBasic.findCycle import protocol TSCBasic.HashAlgorithm -import class TSCBasic.InMemoryFileSystem import struct TSCBasic.KeyedPair import struct TSCBasic.SHA256 import var TSCBasic.stderrStream diff --git a/Tests/BasicsTests/Archiver/TarArchiverTests.swift b/Tests/BasicsTests/Archiver/TarArchiverTests.swift index d4c3ca748ca..69fb182b142 100644 --- a/Tests/BasicsTests/Archiver/TarArchiverTests.swift +++ b/Tests/BasicsTests/Archiver/TarArchiverTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -15,7 +15,6 @@ import TSCclibc // for SPM_posix_spawn_file_actions_addchdir_np_supported import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem import struct TSCBasic.FileSystemError final class TarArchiverTests: XCTestCase { diff --git a/Tests/BasicsTests/Archiver/UniversalArchiverTests.swift b/Tests/BasicsTests/Archiver/UniversalArchiverTests.swift index 363b20f3537..3761bf9042b 100644 --- a/Tests/BasicsTests/Archiver/UniversalArchiverTests.swift +++ b/Tests/BasicsTests/Archiver/UniversalArchiverTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -15,7 +15,6 @@ import TSCclibc // for SPM_posix_spawn_file_actions_addchdir_np_supported import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem import struct TSCBasic.FileSystemError final class UniversalArchiverTests: XCTestCase { diff --git a/Tests/BasicsTests/Archiver/ZipArchiverTests.swift b/Tests/BasicsTests/Archiver/ZipArchiverTests.swift index d0441be4b56..95432765359 100644 --- a/Tests/BasicsTests/Archiver/ZipArchiverTests.swift +++ b/Tests/BasicsTests/Archiver/ZipArchiverTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2022 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -15,10 +15,9 @@ import SPMTestSupport import XCTest import TSCclibc // for SPM_posix_spawn_file_actions_addchdir_np_supported -import class TSCBasic.InMemoryFileSystem import struct TSCBasic.FileSystemError -class ZipArchiverTests: XCTestCase { +final class ZipArchiverTests: XCTestCase { func testZipArchiverSuccess() async throws { try await testWithTemporaryDirectory { tmpdir in let archiver = ZipArchiver(fileSystem: localFileSystem) diff --git a/Tests/BasicsTests/FileSystem/FileSystemTests.swift b/Tests/BasicsTests/FileSystem/FileSystemTests.swift index 8f32cbf92f5..32c6ddb121d 100644 --- a/Tests/BasicsTests/FileSystem/FileSystemTests.swift +++ b/Tests/BasicsTests/FileSystem/FileSystemTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2021 Apple Inc. and the Swift project authors +// Copyright (c) 2021-2024 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,13 +10,10 @@ // //===----------------------------------------------------------------------===// - @testable import Basics import TSCTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - final class FileSystemTests: XCTestCase { func testStripFirstLevelComponent() throws { let fileSystem = InMemoryFileSystem() diff --git a/Tests/BasicsTests/SandboxTests.swift b/Tests/BasicsTests/SandboxTests.swift index a0d15e47f02..88949820e58 100644 --- a/Tests/BasicsTests/SandboxTests.swift +++ b/Tests/BasicsTests/SandboxTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors +// Copyright (c) 2021-2024 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 @@ -18,7 +18,6 @@ import XCTest import Darwin #endif -import class TSCBasic.InMemoryFileSystem import class TSCBasic.Process import struct TSCBasic.ProcessResult diff --git a/Tests/BuildTests/BuildOperationTests.swift b/Tests/BuildTests/BuildOperationTests.swift index 21c40cafb5d..87fb72fe282 100644 --- a/Tests/BuildTests/BuildOperationTests.swift +++ b/Tests/BuildTests/BuildOperationTests.swift @@ -24,7 +24,6 @@ import SPMBuildCore import XCTest import class TSCBasic.BufferedOutputByteStream -import class TSCBasic.InMemoryFileSystem final class BuildOperationTests: XCTestCase { func testDetectUnexpressedDependencies() throws { diff --git a/Tests/BuildTests/BuildPlanTests.swift b/Tests/BuildTests/BuildPlanTests.swift index 4a8b5072387..e54928afe50 100644 --- a/Tests/BuildTests/BuildPlanTests.swift +++ b/Tests/BuildTests/BuildPlanTests.swift @@ -28,7 +28,6 @@ import Workspace import XCTest import struct TSCBasic.ByteString -import class TSCBasic.InMemoryFileSystem import enum TSCUtility.Diagnostics diff --git a/Tests/BuildTests/CrossCompilationBuildPlanTests.swift b/Tests/BuildTests/CrossCompilationBuildPlanTests.swift index 4ac13002143..ddea08694d1 100644 --- a/Tests/BuildTests/CrossCompilationBuildPlanTests.swift +++ b/Tests/BuildTests/CrossCompilationBuildPlanTests.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// import struct Basics.AbsolutePath +import class Basics.InMemoryFileSystem import class Basics.ObservabilitySystem import class Build.BuildPlan import class Build.ProductBuildDescription @@ -31,7 +32,6 @@ import func SPMTestSupport.trivialPackageGraph import struct SPMTestSupport.BuildPlanResult import func SPMTestSupport.XCTAssertMatch import func SPMTestSupport.XCTAssertNoDiagnostics -import class TSCBasic.InMemoryFileSystem import XCTest diff --git a/Tests/BuildTests/LLBuildManifestBuilderTests.swift b/Tests/BuildTests/LLBuildManifestBuilderTests.swift index 5ba597003d1..ffe0d979381 100644 --- a/Tests/BuildTests/LLBuildManifestBuilderTests.swift +++ b/Tests/BuildTests/LLBuildManifestBuilderTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2015-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2015-2024 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 @@ -22,7 +22,6 @@ import struct SPMBuildCore.BuildParameters import SPMTestSupport -import class TSCBasic.InMemoryFileSystem import XCTest final class LLBuildManifestBuilderTests: XCTestCase { diff --git a/Tests/BuildTests/ModuleAliasingBuildTests.swift b/Tests/BuildTests/ModuleAliasingBuildTests.swift index baa21707d21..6b7fdb6481b 100644 --- a/Tests/BuildTests/ModuleAliasingBuildTests.swift +++ b/Tests/BuildTests/ModuleAliasingBuildTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2022 Apple Inc. and the Swift project authors +// Copyright (c) 2022-2024 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 @@ -24,8 +24,6 @@ import SwiftDriver import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - final class ModuleAliasingBuildTests: XCTestCase { func testModuleAliasingEmptyAlias() throws { let fs = InMemoryFileSystem( diff --git a/Tests/BuildTests/ProductBuildDescriptionTests.swift b/Tests/BuildTests/ProductBuildDescriptionTests.swift index a314782fdae..708e40abee3 100644 --- a/Tests/BuildTests/ProductBuildDescriptionTests.swift +++ b/Tests/BuildTests/ProductBuildDescriptionTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -13,8 +13,8 @@ @testable import Build +import class Basics.InMemoryFileSystem import class Basics.ObservabilitySystem -import class TSCBasic.InMemoryFileSystem import class PackageModel.Manifest import struct PackageModel.TargetDescription diff --git a/Tests/CommandsTests/MermaidPackageSerializerTests.swift b/Tests/CommandsTests/MermaidPackageSerializerTests.swift index 2c5f88cd415..b16cecdff4e 100644 --- a/Tests/CommandsTests/MermaidPackageSerializerTests.swift +++ b/Tests/CommandsTests/MermaidPackageSerializerTests.swift @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +import class Basics.InMemoryFileSystem import class Basics.ObservabilitySystem @_spi(DontAdoptOutsideOfSwiftPMExposedForBenchmarksAndTestsOnly) @@ -18,7 +19,6 @@ import func PackageGraph.loadModulesGraph import class PackageModel.Manifest import struct PackageModel.ProductDescription import struct PackageModel.TargetDescription -import class TSCBasic.InMemoryFileSystem import func SPMTestSupport.XCTAssertNoDiagnostics @testable diff --git a/Tests/CommandsTests/MultiRootSupportTests.swift b/Tests/CommandsTests/MultiRootSupportTests.swift index 024bac2015c..88f4ac79b65 100644 --- a/Tests/CommandsTests/MultiRootSupportTests.swift +++ b/Tests/CommandsTests/MultiRootSupportTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2019 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -16,10 +16,7 @@ import SPMTestSupport import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - final class MultiRootSupportTests: CommandsTestCase { - func testWorkspaceLoader() throws { let fs = InMemoryFileSystem(emptyFiles: [ "/tmp/test/dep/Package.swift", diff --git a/Tests/CommandsTests/PackageCommandTests.swift b/Tests/CommandsTests/PackageCommandTests.swift index be29ac86dd5..d2c04a2a790 100644 --- a/Tests/CommandsTests/PackageCommandTests.swift +++ b/Tests/CommandsTests/PackageCommandTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2022 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -32,7 +32,6 @@ import XCTest import struct TSCBasic.ByteString import class TSCBasic.BufferedOutputByteStream -import class TSCBasic.InMemoryFileSystem import enum TSCBasic.JSON import class TSCBasic.Process diff --git a/Tests/LLBuildManifestTests/LLBuildManifestTests.swift b/Tests/LLBuildManifestTests/LLBuildManifestTests.swift index ffe03d6e8db..7174b3abdba 100644 --- a/Tests/LLBuildManifestTests/LLBuildManifestTests.swift +++ b/Tests/LLBuildManifestTests/LLBuildManifestTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -11,13 +11,12 @@ //===----------------------------------------------------------------------===// import struct Basics.AbsolutePath +import class Basics.InMemoryFileSystem import class Foundation.PropertyListDecoder @testable import LLBuildManifest import SPMTestSupport -import class TSCBasic.InMemoryFileSystem import XCTest - private let testEntitlement = "test-entitlement" final class LLBuildManifestTests: XCTestCase { diff --git a/Tests/PackageCollectionsTests/PackageCollectionsSourcesStorageTest.swift b/Tests/PackageCollectionsTests/PackageCollectionsSourcesStorageTest.swift index 43f32c69f14..4dac82e3f59 100644 --- a/Tests/PackageCollectionsTests/PackageCollectionsSourcesStorageTest.swift +++ b/Tests/PackageCollectionsTests/PackageCollectionsSourcesStorageTest.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2020 Apple Inc. and the Swift project authors +// Copyright (c) 2020-2024 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 @@ -15,8 +15,6 @@ import Basics import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - final class PackageCollectionsSourcesStorageTest: XCTestCase { func testHappyCase() async throws { let mockFileSystem = InMemoryFileSystem() diff --git a/Tests/PackageCollectionsTests/PackageIndexConfigurationTests.swift b/Tests/PackageCollectionsTests/PackageIndexConfigurationTests.swift index 869a48c14bc..63d659a941a 100644 --- a/Tests/PackageCollectionsTests/PackageIndexConfigurationTests.swift +++ b/Tests/PackageCollectionsTests/PackageIndexConfigurationTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2022 Apple Inc. and the Swift project authors +// Copyright (c) 2022-2024 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 @@ -13,9 +13,7 @@ import PackageCollections import XCTest -import class TSCBasic.InMemoryFileSystem - -class PackageIndexConfigurationTests: XCTestCase { +final class PackageIndexConfigurationTests: XCTestCase { func testSaveAndLoad() throws { let url = URL("https://package-index.test") let configuration = PackageIndexConfiguration(url: url) diff --git a/Tests/PackageCollectionsTests/Utility.swift b/Tests/PackageCollectionsTests/Utility.swift index 8aa17b9f5c4..c448766d510 100644 --- a/Tests/PackageCollectionsTests/Utility.swift +++ b/Tests/PackageCollectionsTests/Utility.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2020-2024 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 @@ -20,8 +20,6 @@ import PackageCollectionsSigning import PackageModel import SourceControl -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version func makeMockSources(count: Int = Int.random(in: 5 ... 10)) -> [PackageCollectionsModel.CollectionSource] { diff --git a/Tests/PackageFingerprintTests/FilePackageFingerprintStorageTests.swift b/Tests/PackageFingerprintTests/FilePackageFingerprintStorageTests.swift index 0f8cfd70c98..81e9148fdc1 100644 --- a/Tests/PackageFingerprintTests/FilePackageFingerprintStorageTests.swift +++ b/Tests/PackageFingerprintTests/FilePackageFingerprintStorageTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2021-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2021-2024 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 @@ -17,8 +17,6 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version final class FilePackageFingerprintStorageTests: XCTestCase { diff --git a/Tests/PackageGraphPerformanceTests/PackageGraphPerfTests.swift b/Tests/PackageGraphPerformanceTests/PackageGraphPerfTests.swift index 78b0298697e..7d669b730b4 100644 --- a/Tests/PackageGraphPerformanceTests/PackageGraphPerfTests.swift +++ b/Tests/PackageGraphPerformanceTests/PackageGraphPerfTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -21,8 +21,6 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - import class TSCTestSupport.XCTestCasePerf final class PackageGraphPerfTests: XCTestCasePerf { diff --git a/Tests/PackageGraphTests/ModulesGraphTests.swift b/Tests/PackageGraphTests/ModulesGraphTests.swift index 16c86130bbc..2fab928c472 100644 --- a/Tests/PackageGraphTests/ModulesGraphTests.swift +++ b/Tests/PackageGraphTests/ModulesGraphTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -20,7 +20,6 @@ import SPMTestSupport import XCTest import struct TSCBasic.ByteString -import class TSCBasic.InMemoryFileSystem final class ModulesGraphTests: XCTestCase { func testBasic() throws { diff --git a/Tests/PackageGraphTests/PubgrubTests.swift b/Tests/PackageGraphTests/PubgrubTests.swift index 7684413fa48..5cb2f180168 100644 --- a/Tests/PackageGraphTests/PubgrubTests.swift +++ b/Tests/PackageGraphTests/PubgrubTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -19,8 +19,6 @@ import SourceControl import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version // There's some useful helper utilities defined below for easier testing: diff --git a/Tests/PackageLoadingTests/ManifestLoaderCacheTests.swift b/Tests/PackageLoadingTests/ManifestLoaderCacheTests.swift index 72ad202d200..6a2fafac2df 100644 --- a/Tests/PackageLoadingTests/ManifestLoaderCacheTests.swift +++ b/Tests/PackageLoadingTests/ManifestLoaderCacheTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2020-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2020-2024 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 @@ -16,7 +16,6 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem import enum TSCBasic.ProcessEnv import func TSCTestSupport.withCustomEnv diff --git a/Tests/PackageLoadingTests/ModuleMapGenerationTests.swift b/Tests/PackageLoadingTests/ModuleMapGenerationTests.swift index 80834a55e78..a33a891dec9 100644 --- a/Tests/PackageLoadingTests/ModuleMapGenerationTests.swift +++ b/Tests/PackageLoadingTests/ModuleMapGenerationTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2020 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -16,10 +16,7 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - -class ModuleMapGeneration: XCTestCase { - +final class ModuleMapGeneration: XCTestCase { func testModuleNameHeaderInInclude() throws { let root: AbsolutePath = .root diff --git a/Tests/PackageLoadingTests/PDLoadingTests.swift b/Tests/PackageLoadingTests/PDLoadingTests.swift index aa2bfd7af44..fd6fba7ad8c 100644 --- a/Tests/PackageLoadingTests/PDLoadingTests.swift +++ b/Tests/PackageLoadingTests/PDLoadingTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -16,8 +16,6 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - class PackageDescriptionLoadingTests: XCTestCase, ManifestLoaderDelegate { lazy var manifestLoader = ManifestLoader(toolchain: try! UserToolchain.default, delegate: self) var parsedManifest = ThreadSafeBox() diff --git a/Tests/PackageLoadingTests/PD_4_0_LoadingTests.swift b/Tests/PackageLoadingTests/PD_4_0_LoadingTests.swift index 365985a8618..4c7d6f0b1a4 100644 --- a/Tests/PackageLoadingTests/PD_4_0_LoadingTests.swift +++ b/Tests/PackageLoadingTests/PD_4_0_LoadingTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2017-2020 Apple Inc. and the Swift project authors +// Copyright (c) 2017-2024 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 @@ -16,8 +16,6 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - final class PackageDescription4_0LoadingTests: PackageDescriptionLoadingTests { override var toolsVersion: ToolsVersion { .v4 diff --git a/Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift b/Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift index d460fb6be9a..dc7c96278cc 100644 --- a/Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift +++ b/Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -17,7 +17,6 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem import enum TSCBasic.PathValidationError import func TSCTestSupport.withCustomEnv diff --git a/Tests/PackageLoadingTests/PackageBuilderTests.swift b/Tests/PackageLoadingTests/PackageBuilderTests.swift index 4b24f5779bf..7d3d994ba90 100644 --- a/Tests/PackageLoadingTests/PackageBuilderTests.swift +++ b/Tests/PackageLoadingTests/PackageBuilderTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -16,8 +16,6 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - /// Tests for the handling of source layout conventions. final class PackageBuilderTests: XCTestCase { func testDotFilesAreIgnored() throws { diff --git a/Tests/PackageLoadingTests/PkgConfigParserTests.swift b/Tests/PackageLoadingTests/PkgConfigParserTests.swift index 110bf941ff7..5e75340a75b 100644 --- a/Tests/PackageLoadingTests/PkgConfigParserTests.swift +++ b/Tests/PackageLoadingTests/PkgConfigParserTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -16,7 +16,6 @@ import SPMTestSupport import XCTest import struct TSCBasic.ByteString -import class TSCBasic.InMemoryFileSystem import func TSCTestSupport.withCustomEnv diff --git a/Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift b/Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift index fb026155d11..7b4c21a99c7 100644 --- a/Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift +++ b/Tests/PackageLoadingTests/TargetSourcesBuilderTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2019 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -17,9 +17,7 @@ import PackageLoading import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - -class TargetSourcesBuilderTests: XCTestCase { +final class TargetSourcesBuilderTests: XCTestCase { func testBasicFileContentsComputation() throws { let target = try TargetDescription( name: "Foo", diff --git a/Tests/PackageLoadingTests/ToolsVersionParserTests.swift b/Tests/PackageLoadingTests/ToolsVersionParserTests.swift index 486828a7254..78b1cf135fa 100644 --- a/Tests/PackageLoadingTests/ToolsVersionParserTests.swift +++ b/Tests/PackageLoadingTests/ToolsVersionParserTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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,16 +10,13 @@ // //===----------------------------------------------------------------------===// - import Basics import PackageModel import PackageLoading import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - -class ToolsVersionParserTests: XCTestCase { +final class ToolsVersionParserTests: XCTestCase { func parse(_ content: String, _ body: ((ToolsVersion) -> Void)? = nil) throws { let toolsVersion = try ToolsVersionParser.parse(utf8String: content) body?(toolsVersion) diff --git a/Tests/PackageModelTests/SwiftSDKBundleTests.swift b/Tests/PackageModelTests/SwiftSDKBundleTests.swift index 0491ba1e344..1b988062576 100644 --- a/Tests/PackageModelTests/SwiftSDKBundleTests.swift +++ b/Tests/PackageModelTests/SwiftSDKBundleTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2023 Apple Inc. and the Swift project authors +// Copyright (c) 2023-2024 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 @@ -17,7 +17,6 @@ import XCTest import struct TSCBasic.ByteString import protocol TSCBasic.FileSystem -import class TSCBasic.InMemoryFileSystem private let testArtifactID = "test-artifact" diff --git a/Tests/PackageModelTests/SwiftSDKTests.swift b/Tests/PackageModelTests/SwiftSDKTests.swift index a5b27fdfba6..db629e3ec10 100644 --- a/Tests/PackageModelTests/SwiftSDKTests.swift +++ b/Tests/PackageModelTests/SwiftSDKTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2022 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -15,8 +15,6 @@ @testable import SPMBuildCore import XCTest -import class TSCBasic.InMemoryFileSystem - private let bundleRootPath = try! AbsolutePath(validating: "/tmp/cross-toolchain") private let toolchainBinDir = RelativePath("swift.xctoolchain/usr/bin") private let sdkRootDir = RelativePath("ubuntu-jammy.sdk") diff --git a/Tests/PackageModelTests/ToolsetTests.swift b/Tests/PackageModelTests/ToolsetTests.swift index 4755c03e3fa..33151f969a1 100644 --- a/Tests/PackageModelTests/ToolsetTests.swift +++ b/Tests/PackageModelTests/ToolsetTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2023 Apple Inc. and the Swift project authors +// Copyright (c) 2023-2024 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 @@ -15,8 +15,6 @@ import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - private let usrBinTools = Dictionary(uniqueKeysWithValues: Toolset.KnownTool.allCases.map { ($0, try! AbsolutePath(validating: "/usr/bin/\($0.rawValue)")) }) diff --git a/Tests/PackageRegistryTests/RegistryClientTests.swift b/Tests/PackageRegistryTests/RegistryClientTests.swift index db027bb4a00..ec6e805905f 100644 --- a/Tests/PackageRegistryTests/RegistryClientTests.swift +++ b/Tests/PackageRegistryTests/RegistryClientTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2021-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2021-2024 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 @@ -21,8 +21,6 @@ import SPMTestSupport import XCTest import protocol TSCBasic.HashAlgorithm -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version final class RegistryClientTests: XCTestCase { diff --git a/Tests/PackageRegistryTests/RegistryDownloadsManagerTests.swift b/Tests/PackageRegistryTests/RegistryDownloadsManagerTests.swift index 75919374b76..33301c6fb74 100644 --- a/Tests/PackageRegistryTests/RegistryDownloadsManagerTests.swift +++ b/Tests/PackageRegistryTests/RegistryDownloadsManagerTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2022-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2022-2024 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 @@ -17,11 +17,9 @@ import PackageLoading import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version -class RegistryDownloadsManagerTests: XCTestCase { +final class RegistryDownloadsManagerTests: XCTestCase { func testNoCache() async throws { let observability = ObservabilitySystem.makeForTesting() let fs = InMemoryFileSystem() diff --git a/Tests/PackageSigningTests/FilePackageSigningEntityStorageTests.swift b/Tests/PackageSigningTests/FilePackageSigningEntityStorageTests.swift index b5805f2e23a..8c2acce7f90 100644 --- a/Tests/PackageSigningTests/FilePackageSigningEntityStorageTests.swift +++ b/Tests/PackageSigningTests/FilePackageSigningEntityStorageTests.swift @@ -18,8 +18,6 @@ import PackageModel import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version final class FilePackageSigningEntityStorageTests: XCTestCase { diff --git a/Tests/SPMBuildCoreTests/ArtifactsArchiveMetadataTests.swift b/Tests/SPMBuildCoreTests/ArtifactsArchiveMetadataTests.swift index 2ab3ce8cdb4..2cd4a25cac5 100644 --- a/Tests/SPMBuildCoreTests/ArtifactsArchiveMetadataTests.swift +++ b/Tests/SPMBuildCoreTests/ArtifactsArchiveMetadataTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -14,8 +14,6 @@ import Basics import PackageModel import XCTest -import class TSCBasic.InMemoryFileSystem - final class ArtifactsArchiveMetadataTests: XCTestCase { func testParseMetadata() throws { let fileSystem = InMemoryFileSystem() diff --git a/Tests/SPMBuildCoreTests/PluginInvocationTests.swift b/Tests/SPMBuildCoreTests/PluginInvocationTests.swift index a0deb0d6652..1185f2d1cef 100644 --- a/Tests/SPMBuildCoreTests/PluginInvocationTests.swift +++ b/Tests/SPMBuildCoreTests/PluginInvocationTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors +// Copyright (c) 2021-2024 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 @@ -22,8 +22,6 @@ import SPMTestSupport import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.SerializedDiagnostics class PluginInvocationTests: XCTestCase { diff --git a/Tests/SPMBuildCoreTests/XCFrameworkMetadataTests.swift b/Tests/SPMBuildCoreTests/XCFrameworkMetadataTests.swift index 1aa7f427d0e..dca0f7c81ac 100644 --- a/Tests/SPMBuildCoreTests/XCFrameworkMetadataTests.swift +++ b/Tests/SPMBuildCoreTests/XCFrameworkMetadataTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2021 Apple Inc. and the Swift project authors +// Copyright (c) 2021-2024 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,11 +10,10 @@ // //===----------------------------------------------------------------------===// +import class Basics.InMemoryFileSystem import SPMBuildCore import XCTest -import class TSCBasic.InMemoryFileSystem - final class XCFrameworkMetadataTests: XCTestCase { func testParseFramework() throws { let fileSystem = InMemoryFileSystem(files: [ diff --git a/Tests/SourceControlTests/InMemoryGitRepositoryTests.swift b/Tests/SourceControlTests/InMemoryGitRepositoryTests.swift index 8b643ec8a4f..3a6b2a5e6f3 100644 --- a/Tests/SourceControlTests/InMemoryGitRepositoryTests.swift +++ b/Tests/SourceControlTests/InMemoryGitRepositoryTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -15,9 +15,7 @@ import SourceControl import SPMTestSupport import XCTest -import class TSCBasic.InMemoryFileSystem - -class InMemoryGitRepositoryTests: XCTestCase { +final class InMemoryGitRepositoryTests: XCTestCase { func testBasics() throws { let fs = InMemoryFileSystem() let repo = InMemoryGitRepository(path: .root, fs: fs) diff --git a/Tests/SourceControlTests/RepositoryManagerTests.swift b/Tests/SourceControlTests/RepositoryManagerTests.swift index 87bd1fc7fdd..8c0c29429ee 100644 --- a/Tests/SourceControlTests/RepositoryManagerTests.swift +++ b/Tests/SourceControlTests/RepositoryManagerTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -16,10 +16,9 @@ import SPMTestSupport @testable import SourceControl import XCTest -import class TSCBasic.InMemoryFileSystem import enum TSCBasic.ProcessEnv -class RepositoryManagerTests: XCTestCase { +final class RepositoryManagerTests: XCTestCase { func testBasics() async throws { let fs = localFileSystem let observability = ObservabilitySystem.makeForTesting() diff --git a/Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift b/Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift index 0ef54fbc308..3705da93f48 100644 --- a/Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift +++ b/Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift @@ -19,7 +19,6 @@ import PackageGraph import PackageModel import SourceKitLSPAPI import SPMTestSupport -import TSCBasic import XCTest class SourceKitLSPAPITests: XCTestCase { diff --git a/Tests/WorkspaceTests/AuthorizationProviderTests.swift b/Tests/WorkspaceTests/AuthorizationProviderTests.swift index 07c9116bed8..0efaec63341 100644 --- a/Tests/WorkspaceTests/AuthorizationProviderTests.swift +++ b/Tests/WorkspaceTests/AuthorizationProviderTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors +// Copyright (c) 2020-2024 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 @@ -15,8 +15,6 @@ import SPMTestSupport import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - final class AuthorizationProviderTests: XCTestCase { func testNetrcAuthorizationProviders() throws { let observability = ObservabilitySystem.makeForTesting() diff --git a/Tests/WorkspaceTests/MirrorsConfigurationTests.swift b/Tests/WorkspaceTests/MirrorsConfigurationTests.swift index 84a1fec495d..c8baf6d54c9 100644 --- a/Tests/WorkspaceTests/MirrorsConfigurationTests.swift +++ b/Tests/WorkspaceTests/MirrorsConfigurationTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2020 Apple Inc. and the Swift project authors +// Copyright (c) 2020-2024 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 @@ -15,8 +15,6 @@ import SPMTestSupport import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - final class MirrorsConfigurationTests: XCTestCase { func testLoadingSchema1() throws { let fs = InMemoryFileSystem() diff --git a/Tests/WorkspaceTests/PinsStoreTests.swift b/Tests/WorkspaceTests/PinsStoreTests.swift index e32c14aa77a..41d41c76740 100644 --- a/Tests/WorkspaceTests/PinsStoreTests.swift +++ b/Tests/WorkspaceTests/PinsStoreTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -18,8 +18,6 @@ import SourceControl import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version final class PinsStoreTests: XCTestCase { diff --git a/Tests/WorkspaceTests/RegistryPackageContainerTests.swift b/Tests/WorkspaceTests/RegistryPackageContainerTests.swift index ea669b6cff5..37d7cfa2e3e 100644 --- a/Tests/WorkspaceTests/RegistryPackageContainerTests.swift +++ b/Tests/WorkspaceTests/RegistryPackageContainerTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -20,8 +20,6 @@ import SPMTestSupport @testable import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - import struct TSCUtility.Version class RegistryPackageContainerTests: XCTestCase { diff --git a/Tests/WorkspaceTests/SourceControlPackageContainerTests.swift b/Tests/WorkspaceTests/SourceControlPackageContainerTests.swift index 199b1041bb9..221948f5697 100644 --- a/Tests/WorkspaceTests/SourceControlPackageContainerTests.swift +++ b/Tests/WorkspaceTests/SourceControlPackageContainerTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2020 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -20,8 +20,6 @@ import SPMTestSupport @testable import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - import enum TSCUtility.Git import struct TSCUtility.Version diff --git a/Tests/WorkspaceTests/ToolsVersionSpecificationRewriterTests.swift b/Tests/WorkspaceTests/ToolsVersionSpecificationRewriterTests.swift index b3265ae2add..486951cbb26 100644 --- a/Tests/WorkspaceTests/ToolsVersionSpecificationRewriterTests.swift +++ b/Tests/WorkspaceTests/ToolsVersionSpecificationRewriterTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2020 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -19,10 +19,8 @@ import PackageModel @testable import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - /// Test cases for `rewriteToolsVersionSpecification(toDefaultManifestIn:specifying:fileSystem:)` -class ToolsVersionSpecificationRewriterTests: XCTestCase { +final class ToolsVersionSpecificationRewriterTests: XCTestCase { /// Tests `rewriteToolsVersionSpecification(toDefaultManifestIn:specifying:fileSystem:)`. func testNonVersionSpecificManifests() throws { diff --git a/Tests/WorkspaceTests/WorkspaceStateTests.swift b/Tests/WorkspaceTests/WorkspaceStateTests.swift index a0d6ca66370..bee32b97ed6 100644 --- a/Tests/WorkspaceTests/WorkspaceStateTests.swift +++ b/Tests/WorkspaceTests/WorkspaceStateTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2021 Apple Inc. and the Swift project authors +// Copyright (c) 2021-2024 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 @@ -14,8 +14,6 @@ import Basics @testable import Workspace import XCTest -import class TSCBasic.InMemoryFileSystem - final class WorkspaceStateTests: XCTestCase { func testV4Format() throws { let fs = InMemoryFileSystem() diff --git a/Tests/WorkspaceTests/WorkspaceTests.swift b/Tests/WorkspaceTests/WorkspaceTests.swift index 783329c01f1..029558069b2 100644 --- a/Tests/WorkspaceTests/WorkspaceTests.swift +++ b/Tests/WorkspaceTests/WorkspaceTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -24,7 +24,6 @@ import SPMTestSupport import XCTest import struct TSCBasic.ByteString -import class TSCBasic.InMemoryFileSystem import struct TSCUtility.Version diff --git a/Tests/XCBuildSupportTests/PIFBuilderTests.swift b/Tests/XCBuildSupportTests/PIFBuilderTests.swift index 65c2fe75065..41e87339bae 100644 --- a/Tests/XCBuildSupportTests/PIFBuilderTests.swift +++ b/Tests/XCBuildSupportTests/PIFBuilderTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2020 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -23,11 +23,9 @@ import SPMTestSupport @testable import XCBuildSupport import XCTest -import class TSCBasic.InMemoryFileSystem - import func TSCTestSupport.withCustomEnv -class PIFBuilderTests: XCTestCase { +final class PIFBuilderTests: XCTestCase { let inputsDir = AbsolutePath(#file).parentDirectory.appending(components: "Inputs") func testOrdering() throws { From 74217e3827ddcafe3c31f11c6552f572f740e4e7 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 20 Jun 2024 20:29:57 +0100 Subject: [PATCH 3/4] Fix copyright years --- Sources/SPMTestSupport/InMemoryGitRepository.swift | 2 +- Sources/SPMTestSupport/MockWorkspace.swift | 2 +- Tests/FunctionalTests/ModuleMapTests.swift | 5 ++--- .../FilePackageSigningEntityStorageTests.swift | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Sources/SPMTestSupport/InMemoryGitRepository.swift b/Sources/SPMTestSupport/InMemoryGitRepository.swift index a1eb9640d60..c7fc4c4abba 100644 --- a/Sources/SPMTestSupport/InMemoryGitRepository.swift +++ b/Sources/SPMTestSupport/InMemoryGitRepository.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors +// 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 diff --git a/Sources/SPMTestSupport/MockWorkspace.swift b/Sources/SPMTestSupport/MockWorkspace.swift index 207a4e36aef..4e53ec634e9 100644 --- a/Sources/SPMTestSupport/MockWorkspace.swift +++ b/Sources/SPMTestSupport/MockWorkspace.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2023 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 diff --git a/Tests/FunctionalTests/ModuleMapTests.swift b/Tests/FunctionalTests/ModuleMapTests.swift index 14e426b5b6e..f8da9e4aefc 100644 --- a/Tests/FunctionalTests/ModuleMapTests.swift +++ b/Tests/FunctionalTests/ModuleMapTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors +// Copyright (c) 2014-2024 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 @@ -17,8 +17,7 @@ import SPMTestSupport import Workspace import XCTest -class ModuleMapsTestCase: XCTestCase { - +final class ModuleMapsTestCase: XCTestCase { private func fixture(name: String, cModuleName: String, rootpkg: String, body: @escaping (AbsolutePath, [String]) throws -> Void) throws { try SPMTestSupport.fixture(name: name) { fixturePath in let input = fixturePath.appending(components: cModuleName, "C", "foo.c") diff --git a/Tests/PackageSigningTests/FilePackageSigningEntityStorageTests.swift b/Tests/PackageSigningTests/FilePackageSigningEntityStorageTests.swift index 8c2acce7f90..808a3ca6f88 100644 --- a/Tests/PackageSigningTests/FilePackageSigningEntityStorageTests.swift +++ b/Tests/PackageSigningTests/FilePackageSigningEntityStorageTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift open source project // -// Copyright (c) 2023 Apple Inc. and the Swift project authors +// Copyright (c) 2023-2024 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 From 809fd33e05fb658fdb5e2872f88e9103dab3dbb2 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 20 Jun 2024 20:42:09 +0100 Subject: [PATCH 4/4] Fix build issues in tests --- .../PackageGraphBenchmarks/PackageGraphBenchmarks.swift | 1 - .../PackageCollectionsTests/PackageIndexConfigurationTests.swift | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Benchmarks/Benchmarks/PackageGraphBenchmarks/PackageGraphBenchmarks.swift b/Benchmarks/Benchmarks/PackageGraphBenchmarks/PackageGraphBenchmarks.swift index bab1f4af582..09460dbd7e5 100644 --- a/Benchmarks/Benchmarks/PackageGraphBenchmarks/PackageGraphBenchmarks.swift +++ b/Benchmarks/Benchmarks/PackageGraphBenchmarks/PackageGraphBenchmarks.swift @@ -7,7 +7,6 @@ import PackageModel @_spi(DontAdoptOutsideOfSwiftPMExposedForBenchmarksAndTestsOnly) import func PackageGraph.loadModulesGraph -import class TSCBasic.InMemoryFileSystem import Workspace let benchmarks = { diff --git a/Tests/PackageCollectionsTests/PackageIndexConfigurationTests.swift b/Tests/PackageCollectionsTests/PackageIndexConfigurationTests.swift index 63d659a941a..56db6fead40 100644 --- a/Tests/PackageCollectionsTests/PackageIndexConfigurationTests.swift +++ b/Tests/PackageCollectionsTests/PackageIndexConfigurationTests.swift @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +import class Basics.InMemoryFileSystem import PackageCollections import XCTest