diff --git a/Sources/SPMTestSupport/InMemoryGitRepository.swift b/Sources/SPMTestSupport/InMemoryGitRepository.swift index 5d8ea5bc622..550dd3ed298 100644 --- a/Sources/SPMTestSupport/InMemoryGitRepository.swift +++ b/Sources/SPMTestSupport/InMemoryGitRepository.swift @@ -21,7 +21,7 @@ import struct TSCBasic.FileSystemError import class TSCBasic.InMemoryFileSystem /// The error encountered during in memory git repository operations. -public enum InMemoryGitRepositoryError: Swift.Error { +package enum InMemoryGitRepositoryError: Swift.Error { case unknownRevision case unknownTag case tagAlreadyPresent @@ -34,9 +34,9 @@ public enum InMemoryGitRepositoryError: Swift.Error { /// repository path, as well as on the file system interface of this class. /// Note: This class is intended to be used as testing infrastructure only. /// Note: This class is not thread safe yet. -public final class InMemoryGitRepository { +package final class InMemoryGitRepository { /// The revision identifier. - public typealias RevisionIdentifier = String + package typealias RevisionIdentifier = String /// A struct representing a revision state. Minimally it contains a hash identifier for the revision /// and the file system state. @@ -74,7 +74,7 @@ public final class InMemoryGitRepository { private let lock = NSLock() /// Create a new repository at the given path and filesystem. - public init(path: AbsolutePath, fs: InMemoryFileSystem) { + package init(path: AbsolutePath, fs: InMemoryFileSystem) { self.path = path self.fs = fs // Point head to a new revision state with empty hash to begin with. @@ -82,14 +82,14 @@ public final class InMemoryGitRepository { } /// The array of current tags in the repository. - public func getTags() throws -> [String] { + package func getTags() throws -> [String] { self.lock.withLock { Array(self.tagsMap.keys) } } /// The list of revisions in the repository. - public var revisions: [RevisionIdentifier] { + package var revisions: [RevisionIdentifier] { self.lock.withLock { Array(self.history.keys) } @@ -112,7 +112,7 @@ public final class InMemoryGitRepository { /// Commits the current state of the repository filesystem and returns the commit identifier. @discardableResult - public func commit(hash: String? = nil) throws -> String { + package func commit(hash: String? = nil) throws -> String { // Create a fake hash for this commit. let hash = hash ?? String((UUID().uuidString + UUID().uuidString).prefix(40)) self.lock.withLock { @@ -128,7 +128,7 @@ public final class InMemoryGitRepository { } /// Checks out the provided revision. - public func checkout(revision: RevisionIdentifier) throws { + package func checkout(revision: RevisionIdentifier) throws { guard let state = (self.lock.withLock { history[revision] }) else { throw InMemoryGitRepositoryError.unknownRevision } @@ -142,7 +142,7 @@ public final class InMemoryGitRepository { } /// Checks out a given tag. - public func checkout(tag: String) throws { + package func checkout(tag: String) throws { guard let hash = (self.lock.withLock { tagsMap[tag] }) else { throw InMemoryGitRepositoryError.unknownTag } @@ -191,7 +191,7 @@ public final class InMemoryGitRepository { } /// Tag the current HEAD with the given name. - public func tag(name: String) throws { + package func tag(name: String) throws { guard (self.lock.withLock { self.tagsMap[name] }) == nil else { throw InMemoryGitRepositoryError.tagAlreadyPresent } @@ -200,124 +200,124 @@ public final class InMemoryGitRepository { } } - public func hasUncommittedChanges() -> Bool { + package func hasUncommittedChanges() -> Bool { self.lock.withLock { isDirty } } - public func fetch() throws { + package func fetch() throws { // TODO. } } extension InMemoryGitRepository: FileSystem { - public func exists(_ path: TSCAbsolutePath, followSymlink: Bool) -> Bool { + package func exists(_ path: TSCAbsolutePath, followSymlink: Bool) -> Bool { self.lock.withLock { self.head.fileSystem.exists(path, followSymlink: followSymlink) } } - public func isDirectory(_ path: TSCAbsolutePath) -> Bool { + package func isDirectory(_ path: TSCAbsolutePath) -> Bool { self.lock.withLock { self.head.fileSystem.isDirectory(path) } } - public func isFile(_ path: TSCAbsolutePath) -> Bool { + package func isFile(_ path: TSCAbsolutePath) -> Bool { self.lock.withLock { self.head.fileSystem.isFile(path) } } - public func isSymlink(_ path: TSCAbsolutePath) -> Bool { + package func isSymlink(_ path: TSCAbsolutePath) -> Bool { self.lock.withLock { self.head.fileSystem.isSymlink(path) } } - public func isExecutableFile(_ path: TSCAbsolutePath) -> Bool { + package func isExecutableFile(_ path: TSCAbsolutePath) -> Bool { self.lock.withLock { self.head.fileSystem.isExecutableFile(path) } } - public func isReadable(_ path: TSCAbsolutePath) -> Bool { + package func isReadable(_ path: TSCAbsolutePath) -> Bool { return self.exists(path) } - public func isWritable(_ path: TSCAbsolutePath) -> Bool { + package func isWritable(_ path: TSCAbsolutePath) -> Bool { return false } - public var currentWorkingDirectory: TSCAbsolutePath? { + package var currentWorkingDirectory: TSCAbsolutePath? { return .root } - public func changeCurrentWorkingDirectory(to path: TSCAbsolutePath) throws { + package func changeCurrentWorkingDirectory(to path: TSCAbsolutePath) throws { throw FileSystemError(.unsupported, path) } - public var homeDirectory: TSCAbsolutePath { + package var homeDirectory: TSCAbsolutePath { fatalError("Unsupported") } - public var cachesDirectory: TSCAbsolutePath? { + package var cachesDirectory: TSCAbsolutePath? { fatalError("Unsupported") } - public var tempDirectory: TSCAbsolutePath { + package var tempDirectory: TSCAbsolutePath { fatalError("Unsupported") } - public func getDirectoryContents(_ path: TSCAbsolutePath) throws -> [String] { + package func getDirectoryContents(_ path: TSCAbsolutePath) throws -> [String] { try self.lock.withLock { try self.head.fileSystem.getDirectoryContents(path) } } - public func createDirectory(_ path: TSCAbsolutePath, recursive: Bool) throws { + package func createDirectory(_ path: TSCAbsolutePath, recursive: Bool) throws { try self.lock.withLock { try self.head.fileSystem.createDirectory(path, recursive: recursive) } } - public func createSymbolicLink(_ path: TSCAbsolutePath, pointingAt destination: TSCAbsolutePath, relative: Bool) throws { + package func createSymbolicLink(_ path: TSCAbsolutePath, pointingAt destination: TSCAbsolutePath, relative: Bool) throws { throw FileSystemError(.unsupported, path) } - public func readFileContents(_ path: TSCAbsolutePath) throws -> ByteString { + package func readFileContents(_ path: TSCAbsolutePath) throws -> ByteString { try self.lock.withLock { return try head.fileSystem.readFileContents(path) } } - public func writeFileContents(_ path: TSCAbsolutePath, bytes: ByteString) throws { + package func writeFileContents(_ path: TSCAbsolutePath, bytes: ByteString) throws { try self.lock.withLock { try self.head.fileSystem.writeFileContents(path, bytes: bytes) self.isDirty = true } } - public func removeFileTree(_ path: TSCAbsolutePath) throws { + package func removeFileTree(_ path: TSCAbsolutePath) throws { try self.lock.withLock { try self.head.fileSystem.removeFileTree(path) } } - public func chmod(_ mode: FileMode, path: TSCAbsolutePath, options: Set) throws { + package func chmod(_ mode: FileMode, path: TSCAbsolutePath, options: Set) throws { try self.lock.withLock { try self.head.fileSystem.chmod(mode, path: path, options: options) } } - public func copy(from sourcePath: TSCAbsolutePath, to destinationPath: TSCAbsolutePath) throws { + package func copy(from sourcePath: TSCAbsolutePath, to destinationPath: TSCAbsolutePath) throws { try self.lock.withLock { try self.head.fileSystem.copy(from: sourcePath, to: destinationPath) } } - public func move(from sourcePath: TSCAbsolutePath, to destinationPath: TSCAbsolutePath) throws { + package func move(from sourcePath: TSCAbsolutePath, to destinationPath: TSCAbsolutePath) throws { try self.lock.withLock { try self.head.fileSystem.move(from: sourcePath, to: destinationPath) } @@ -325,7 +325,7 @@ extension InMemoryGitRepository: FileSystem { } extension InMemoryGitRepository: Repository { - public func resolveRevision(tag: String) throws -> Revision { + package func resolveRevision(tag: String) throws -> Revision { try self.lock.withLock { guard let revision = self.tagsMap[tag] else { throw InternalError("unknown tag \(tag)") @@ -334,19 +334,19 @@ extension InMemoryGitRepository: Repository { } } - public func resolveRevision(identifier: String) throws -> Revision { + package func resolveRevision(identifier: String) throws -> Revision { self.lock.withLock { return Revision(identifier: self.tagsMap[identifier] ?? identifier) } } - public func exists(revision: Revision) -> Bool { + package func exists(revision: Revision) -> Bool { self.lock.withLock { return self.history[revision.identifier] != nil } } - public func openFileView(revision: Revision) throws -> FileSystem { + package func openFileView(revision: Revision) throws -> FileSystem { try self.lock.withLock { guard let entry = self.history[revision.identifier] else { throw InternalError("unknown revision \(revision)") @@ -355,70 +355,70 @@ extension InMemoryGitRepository: Repository { } } - public func openFileView(tag: String) throws -> FileSystem { + package func openFileView(tag: String) throws -> FileSystem { let revision = try self.resolveRevision(tag: tag) return try self.openFileView(revision: revision) } } extension InMemoryGitRepository: WorkingCheckout { - public func getCurrentRevision() throws -> Revision { + package func getCurrentRevision() throws -> Revision { self.lock.withLock { return Revision(identifier: self.head.hash) } } - public func checkout(revision: Revision) throws { + package func checkout(revision: Revision) throws { // will lock try checkout(revision: revision.identifier) } - public func hasUnpushedCommits() throws -> Bool { + package func hasUnpushedCommits() throws -> Bool { return false } - public func checkout(newBranch: String) throws { + package func checkout(newBranch: String) throws { self.lock.withLock { self.history[newBranch] = head } } - public func isAlternateObjectStoreValid(expected: AbsolutePath) -> Bool { + package func isAlternateObjectStoreValid(expected: AbsolutePath) -> Bool { return true } - public func areIgnored(_ paths: [AbsolutePath]) throws -> [Bool] { + package func areIgnored(_ paths: [AbsolutePath]) throws -> [Bool] { return [false] } } -// Public mutation of `InMemoryGitRepository` is protected with a lock. +// package mutation of `InMemoryGitRepository` is protected with a lock. extension InMemoryGitRepository: @unchecked Sendable {} /// This class implement provider for in memory git repository. -public final class InMemoryGitRepositoryProvider: RepositoryProvider { +package final class InMemoryGitRepositoryProvider: RepositoryProvider { /// Contains the repository added to this provider. - public var specifierMap = ThreadSafeKeyValueStore() + package var specifierMap = ThreadSafeKeyValueStore() /// Contains the repositories which are fetched using this provider. - public var fetchedMap = ThreadSafeKeyValueStore() + package var fetchedMap = ThreadSafeKeyValueStore() /// Contains the repositories which are checked out using this provider. - public var checkoutsMap = ThreadSafeKeyValueStore() + package var checkoutsMap = ThreadSafeKeyValueStore() /// Create a new provider. - public init() { + package init() { } /// Add a repository to this provider. Only the repositories added with this interface can be operated on /// with this provider. - public func add(specifier: RepositorySpecifier, repository: InMemoryGitRepository) { + package func add(specifier: RepositorySpecifier, repository: InMemoryGitRepository) { // Save the repository in specifier map. specifierMap[specifier] = repository } /// This method returns the stored reference to the git repository which was fetched or checked out. - public func openRepo(at path: AbsolutePath) throws -> InMemoryGitRepository { + package func openRepo(at path: AbsolutePath) throws -> InMemoryGitRepository { if let fetch = fetchedMap[path] { return fetch } @@ -431,7 +431,7 @@ public final class InMemoryGitRepositoryProvider: RepositoryProvider { // MARK: - RepositoryProvider conformance // Note: These methods use force unwrap (instead of throwing) to honor their preconditions. - public func fetch(repository: RepositorySpecifier, to path: AbsolutePath, progressHandler: FetchProgress.Handler? = nil) throws { + package func fetch(repository: RepositorySpecifier, to path: AbsolutePath, progressHandler: FetchProgress.Handler? = nil) throws { guard let repo = specifierMap[RepositorySpecifier(location: repository.location)] else { throw InternalError("unknown repo at \(repository.location)") } @@ -439,25 +439,25 @@ public final class InMemoryGitRepositoryProvider: RepositoryProvider { add(specifier: RepositorySpecifier(path: path), repository: repo) } - public func repositoryExists(at path: AbsolutePath) throws -> Bool { + package func repositoryExists(at path: AbsolutePath) throws -> Bool { return fetchedMap[path] != nil } - public func copy(from sourcePath: AbsolutePath, to destinationPath: AbsolutePath) throws { + package func copy(from sourcePath: AbsolutePath, to destinationPath: AbsolutePath) throws { guard let repo = fetchedMap[sourcePath] else { throw InternalError("unknown repo at \(sourcePath)") } fetchedMap[destinationPath] = try repo.copy() } - public func open(repository: RepositorySpecifier, at path: AbsolutePath) throws -> Repository { + package func open(repository: RepositorySpecifier, at path: AbsolutePath) throws -> Repository { guard let repository = self.fetchedMap[path] else { throw InternalError("unknown repository at \(path)") } return repository } - public func createWorkingCopy( + package func createWorkingCopy( repository: RepositorySpecifier, sourcePath: AbsolutePath, at destinationPath: AbsolutePath, @@ -471,26 +471,26 @@ public final class InMemoryGitRepositoryProvider: RepositoryProvider { return copy } - public func workingCopyExists(at path: AbsolutePath) throws -> Bool { + package func workingCopyExists(at path: AbsolutePath) throws -> Bool { return checkoutsMap.contains(path) } - public func openWorkingCopy(at path: AbsolutePath) throws -> WorkingCheckout { + package func openWorkingCopy(at path: AbsolutePath) throws -> WorkingCheckout { guard let checkout = checkoutsMap[path] else { throw InternalError("unknown checkout at \(path)") } return checkout } - public func isValidDirectory(_ directory: AbsolutePath) throws -> Bool { + package func isValidDirectory(_ directory: AbsolutePath) throws -> Bool { return true } - public func isValidDirectory(_ directory: AbsolutePath, for repository: RepositorySpecifier) throws -> Bool { + package func isValidDirectory(_ directory: AbsolutePath, for repository: RepositorySpecifier) throws -> Bool { return true } - public func cancel(deadline: DispatchTime) throws { + package func cancel(deadline: DispatchTime) throws { // noop } } diff --git a/Sources/SPMTestSupport/ManifestExtensions.swift b/Sources/SPMTestSupport/ManifestExtensions.swift index 30cbd5bc3a2..0d51ed6c9e7 100644 --- a/Sources/SPMTestSupport/ManifestExtensions.swift +++ b/Sources/SPMTestSupport/ManifestExtensions.swift @@ -17,7 +17,7 @@ import PackageModel import struct TSCUtility.Version extension Manifest { - public static func createRootManifest( + package static func createRootManifest( displayName: String, path: AbsolutePath = .root, defaultLocalization: String? = nil, @@ -53,7 +53,7 @@ extension Manifest { ) } - public static func createFileSystemManifest( + package static func createFileSystemManifest( displayName: String, path: AbsolutePath, defaultLocalization: String? = nil, @@ -89,7 +89,7 @@ extension Manifest { ) } - public static func createLocalSourceControlManifest( + package static func createLocalSourceControlManifest( displayName: String, path: AbsolutePath, defaultLocalization: String? = nil, @@ -125,7 +125,7 @@ extension Manifest { ) } - public static func createRemoteSourceControlManifest( + package static func createRemoteSourceControlManifest( displayName: String, url: SourceControlURL, path: AbsolutePath, @@ -162,7 +162,7 @@ extension Manifest { ) } - public static func createRegistryManifest( + package static func createRegistryManifest( displayName: String, identity: PackageIdentity, path: AbsolutePath = .root, @@ -199,7 +199,7 @@ extension Manifest { ) } - public static func createManifest( + package static func createManifest( displayName: String, path: AbsolutePath = .root, packageKind: PackageReference.Kind, @@ -238,7 +238,7 @@ extension Manifest { ) } - public func with(location: String) -> Manifest { + package func with(location: String) -> Manifest { Manifest( displayName: self.displayName, path: self.path, diff --git a/Sources/SPMTestSupport/MockArchiver.swift b/Sources/SPMTestSupport/MockArchiver.swift index cf1a84434df..209bf9bab00 100644 --- a/Sources/SPMTestSupport/MockArchiver.swift +++ b/Sources/SPMTestSupport/MockArchiver.swift @@ -28,20 +28,20 @@ package class MockArchiver: Archiver { package typealias ValidationHandler = (MockArchiver, AbsolutePath, (Result) -> Void) throws -> Void package struct Extraction: Equatable { - public let archivePath: AbsolutePath - public let destinationPath: AbsolutePath + package let archivePath: AbsolutePath + package let destinationPath: AbsolutePath - public init(archivePath: AbsolutePath, destinationPath: AbsolutePath) { + package init(archivePath: AbsolutePath, destinationPath: AbsolutePath) { self.archivePath = archivePath self.destinationPath = destinationPath } } package struct Compression: Equatable { - public let directory: AbsolutePath - public let destinationPath: AbsolutePath + package let directory: AbsolutePath + package let destinationPath: AbsolutePath - public init(directory: AbsolutePath, destinationPath: AbsolutePath) { + package init(directory: AbsolutePath, destinationPath: AbsolutePath) { self.directory = directory self.destinationPath = destinationPath } diff --git a/Sources/SPMTestSupport/MockBuildTestHelper.swift b/Sources/SPMTestSupport/MockBuildTestHelper.swift index 2aeb77764ff..38629590d6c 100644 --- a/Sources/SPMTestSupport/MockBuildTestHelper.swift +++ b/Sources/SPMTestSupport/MockBuildTestHelper.swift @@ -20,31 +20,31 @@ import SPMBuildCore import TSCUtility import XCTest -public struct MockToolchain: PackageModel.Toolchain { +package struct MockToolchain: PackageModel.Toolchain { #if os(Windows) - public let librarianPath = AbsolutePath("/fake/path/to/link.exe") + package let librarianPath = AbsolutePath("/fake/path/to/link.exe") #elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS) - public let librarianPath = AbsolutePath("/fake/path/to/libtool") + package let librarianPath = AbsolutePath("/fake/path/to/libtool") #else - public let librarianPath = AbsolutePath("/fake/path/to/llvm-ar") + package let librarianPath = AbsolutePath("/fake/path/to/llvm-ar") #endif - public let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc") - public let includeSearchPaths = [AbsolutePath]() - public let librarySearchPaths = [AbsolutePath]() - public let swiftResourcesPath: AbsolutePath? = nil - public let swiftStaticResourcesPath: AbsolutePath? = nil - public let isSwiftDevelopmentToolchain = false - public let sdkRootPath: AbsolutePath? = nil - public let swiftPluginServerPath: AbsolutePath? = nil - public let extraFlags = PackageModel.BuildFlags() - public let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration.default - public let providedLibraries = [LibraryMetadata]() - - public func getClangCompiler() throws -> AbsolutePath { + package let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc") + package let includeSearchPaths = [AbsolutePath]() + package let librarySearchPaths = [AbsolutePath]() + package let swiftResourcesPath: AbsolutePath? = nil + package let swiftStaticResourcesPath: AbsolutePath? = nil + package let isSwiftDevelopmentToolchain = false + package let sdkRootPath: AbsolutePath? = nil + package let swiftPluginServerPath: AbsolutePath? = nil + package let extraFlags = PackageModel.BuildFlags() + package let installedSwiftPMConfiguration = InstalledSwiftPMConfiguration.default + package let providedLibraries = [LibraryMetadata]() + + package func getClangCompiler() throws -> AbsolutePath { "/fake/path/to/clang" } - public func _isClangCompilerVendorApple() throws -> Bool? { + package func _isClangCompilerVendorApple() throws -> Bool? { #if os(macOS) return true #else @@ -52,27 +52,27 @@ public struct MockToolchain: PackageModel.Toolchain { #endif } - public init() {} + package init() {} } extension Basics.Triple { - public static let x86_64MacOS = try! Self("x86_64-apple-macosx") - public static let x86_64Linux = try! Self("x86_64-unknown-linux-gnu") - public static let arm64Linux = try! Self("aarch64-unknown-linux-gnu") - public static let arm64Android = try! Self("aarch64-unknown-linux-android") - public static let windows = try! Self("x86_64-unknown-windows-msvc") - public static let wasi = try! Self("wasm32-unknown-wasi") - public static let arm64iOS = try! Self("arm64-apple-ios") + package static let x86_64MacOS = try! Self("x86_64-apple-macosx") + package static let x86_64Linux = try! Self("x86_64-unknown-linux-gnu") + package static let arm64Linux = try! Self("aarch64-unknown-linux-gnu") + package static let arm64Android = try! Self("aarch64-unknown-linux-android") + package static let windows = try! Self("x86_64-unknown-windows-msvc") + package static let wasi = try! Self("wasm32-unknown-wasi") + package static let arm64iOS = try! Self("arm64-apple-ios") } -public let hostTriple = try! UserToolchain.default.targetTriple +package let hostTriple = try! UserToolchain.default.targetTriple #if os(macOS) -public let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVersion: "10.13") +package let defaultTargetTriple: String = hostTriple.tripleString(forPlatformVersion: "10.13") #else -public let defaultTargetTriple: String = hostTriple.tripleString +package let defaultTargetTriple: String = hostTriple.tripleString #endif -public func mockBuildParameters( +package func mockBuildParameters( buildPath: AbsolutePath = "/path/to/build", config: BuildConfiguration = .debug, toolchain: PackageModel.Toolchain = MockToolchain(), @@ -114,7 +114,7 @@ public func mockBuildParameters( ) } -public func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters { +package func mockBuildParameters(environment: BuildEnvironment) -> BuildParameters { let triple: Basics.Triple switch environment.platform { case .macOS: @@ -136,12 +136,12 @@ enum BuildError: Swift.Error { case error(String) } -public struct BuildPlanResult { - public let plan: Build.BuildPlan - public let targetMap: [String: TargetBuildDescription] - public let productMap: [String: Build.ProductBuildDescription] +package struct BuildPlanResult { + package let plan: Build.BuildPlan + package let targetMap: [String: TargetBuildDescription] + package let productMap: [String: Build.ProductBuildDescription] - public init(plan: Build.BuildPlan) throws { + package init(plan: Build.BuildPlan) throws { self.plan = plan self.productMap = try Dictionary( throwingUniqueKeysWithValues: plan.buildProducts @@ -161,22 +161,22 @@ public struct BuildPlanResult { ) } - public func checkTargetsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) { + package func checkTargetsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(self.plan.targetMap.count, count, file: file, line: line) } - public func checkProductsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) { + package func checkProductsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(self.plan.productMap.count, count, file: file, line: line) } - public func target(for name: String) throws -> TargetBuildDescription { + package func target(for name: String) throws -> TargetBuildDescription { guard let target = targetMap[name] else { throw BuildError.error("Target \(name) not found.") } return target } - public func buildProduct(for name: String) throws -> Build.ProductBuildDescription { + package func buildProduct(for name: String) throws -> Build.ProductBuildDescription { guard let product = productMap[name] else { // Display the thrown error on macOS throw BuildError.error("Product \(name) not found.") @@ -186,7 +186,7 @@ public struct BuildPlanResult { } extension TargetBuildDescription { - public func swiftTarget() throws -> SwiftTargetBuildDescription { + package func swiftTarget() throws -> SwiftTargetBuildDescription { switch self { case .swift(let target): return target @@ -195,7 +195,7 @@ extension TargetBuildDescription { } } - public func clangTarget() throws -> ClangTargetBuildDescription { + package func clangTarget() throws -> ClangTargetBuildDescription { switch self { case .clang(let target): return target diff --git a/Sources/SPMTestSupport/MockDependency.swift b/Sources/SPMTestSupport/MockDependency.swift index 5d519724217..321f54214a9 100644 --- a/Sources/SPMTestSupport/MockDependency.swift +++ b/Sources/SPMTestSupport/MockDependency.swift @@ -15,13 +15,13 @@ import Foundation import PackageLoading import PackageModel -public typealias SourceControlRequirement = PackageDependency.SourceControl.Requirement -public typealias RegistryRequirement = PackageDependency.Registry.Requirement +package typealias SourceControlRequirement = PackageDependency.SourceControl.Requirement +package typealias RegistryRequirement = PackageDependency.Registry.Requirement -public struct MockDependency { - public let deprecatedName: String? - public let location: Location - public let products: ProductFilter +package struct MockDependency { + package let deprecatedName: String? + package let location: Location + package let products: ProductFilter init(deprecatedName: String? = nil, location: Location, products: ProductFilter = .everything) { self.deprecatedName = deprecatedName @@ -29,7 +29,7 @@ public struct MockDependency { self.products = products } - public func convert(baseURL: AbsolutePath, identityResolver: IdentityResolver) throws -> PackageDependency { + package func convert(baseURL: AbsolutePath, identityResolver: IdentityResolver) throws -> PackageDependency { switch self.location { case .fileSystem(let path): let absolutePath = baseURL.appending(path) @@ -119,39 +119,39 @@ public struct MockDependency { } - public static func fileSystem(path: String, products: ProductFilter = .everything) -> MockDependency { + package static func fileSystem(path: String, products: ProductFilter = .everything) -> MockDependency { try! MockDependency(location: .fileSystem(path: RelativePath(validating: path)), products: products) } - public static func sourceControl(path: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { + package static func sourceControl(path: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { try! .sourceControl(path: RelativePath(validating: path), requirement: requirement, products: products) } - public static func sourceControl(path: RelativePath, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { + package static func sourceControl(path: RelativePath, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { MockDependency(location: .localSourceControl(path: path, requirement: requirement), products: products) } - public static func sourceControlWithDeprecatedName(name: String, path: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { + package static func sourceControlWithDeprecatedName(name: String, path: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { try! MockDependency(deprecatedName: name, location: .localSourceControl(path: RelativePath(validating: path), requirement: requirement), products: products) } - public static func sourceControl(url: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { + package static func sourceControl(url: String, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { .sourceControl(url: SourceControlURL(url), requirement: requirement, products: products) } - public static func sourceControl(url: SourceControlURL, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { + package static func sourceControl(url: SourceControlURL, requirement: SourceControlRequirement, products: ProductFilter = .everything) -> MockDependency { MockDependency(location: .remoteSourceControl(url: url, requirement: requirement), products: products) } - public static func registry(identity: String, requirement: RegistryRequirement, products: ProductFilter = .everything) -> MockDependency { + package static func registry(identity: String, requirement: RegistryRequirement, products: ProductFilter = .everything) -> MockDependency { .registry(identity: .plain(identity), requirement: requirement) } - public static func registry(identity: PackageIdentity, requirement: RegistryRequirement, products: ProductFilter = .everything) -> MockDependency { + package static func registry(identity: PackageIdentity, requirement: RegistryRequirement, products: ProductFilter = .everything) -> MockDependency { MockDependency(location: .registry(identity: identity, requirement: requirement), products: products) } - public enum Location { + package enum Location { case fileSystem(path: RelativePath) case localSourceControl(path: RelativePath, requirement: SourceControlRequirement) case remoteSourceControl(url: SourceControlURL, requirement: SourceControlRequirement) diff --git a/Sources/SPMTestSupport/MockDependencyGraph.swift b/Sources/SPMTestSupport/MockDependencyGraph.swift index 6a17968ab0b..5b2c8488654 100644 --- a/Sources/SPMTestSupport/MockDependencyGraph.swift +++ b/Sources/SPMTestSupport/MockDependencyGraph.swift @@ -16,20 +16,20 @@ import PackageModel import struct TSCUtility.Version -public struct MockDependencyGraph { - public let name: String - public let constraints: [MockPackageContainer.Constraint] - public let containers: [MockPackageContainer] - public let result: [PackageReference: Version] +package struct MockDependencyGraph { + package let name: String + package let constraints: [MockPackageContainer.Constraint] + package let containers: [MockPackageContainer] + package let result: [PackageReference: Version] - public init(name: String, constraints: [MockPackageContainer.Constraint], containers: [MockPackageContainer], result: [PackageReference : Version]) { + package init(name: String, constraints: [MockPackageContainer.Constraint], containers: [MockPackageContainer], result: [PackageReference : Version]) { self.name = name self.constraints = constraints self.containers = containers self.result = result } - public func checkResult( + package func checkResult( _ output: [(container: PackageReference, version: Version)], file: StaticString = #file, line: UInt = #line diff --git a/Sources/SPMTestSupport/MockHTTPClient.swift b/Sources/SPMTestSupport/MockHTTPClient.swift index c680bcc2612..87474faf0dc 100644 --- a/Sources/SPMTestSupport/MockHTTPClient.swift +++ b/Sources/SPMTestSupport/MockHTTPClient.swift @@ -13,7 +13,7 @@ import Basics extension LegacyHTTPClient { - public static func mock(fileSystem: FileSystem) -> LegacyHTTPClient { + package static func mock(fileSystem: FileSystem) -> LegacyHTTPClient { let handler: LegacyHTTPClient.Handler = { request, _, completion in switch request.kind { case.generic: diff --git a/Sources/SPMTestSupport/MockHashAlgorithm.swift b/Sources/SPMTestSupport/MockHashAlgorithm.swift index 4d8c88e4e81..374e4c77874 100644 --- a/Sources/SPMTestSupport/MockHashAlgorithm.swift +++ b/Sources/SPMTestSupport/MockHashAlgorithm.swift @@ -15,17 +15,17 @@ import Basics import struct TSCBasic.ByteString import protocol TSCBasic.HashAlgorithm -public final class MockHashAlgorithm { - public typealias Handler = @Sendable (ByteString) -> ByteString +package final class MockHashAlgorithm { + package typealias Handler = @Sendable (ByteString) -> ByteString - public let hashes = ThreadSafeArrayStore() + package let hashes = ThreadSafeArrayStore() private let handler: Handler? - public init(handler: Handler? = nil) { + package init(handler: Handler? = nil) { self.handler = handler } - public func hash(_ hash: ByteString) -> ByteString { + package func hash(_ hash: ByteString) -> ByteString { if let handler = self.handler { return handler(hash) } else { diff --git a/Sources/SPMTestSupport/MockManifestLoader.swift b/Sources/SPMTestSupport/MockManifestLoader.swift index 8775dedbfa5..fc1f345ed64 100644 --- a/Sources/SPMTestSupport/MockManifestLoader.swift +++ b/Sources/SPMTestSupport/MockManifestLoader.swift @@ -21,7 +21,7 @@ import func XCTest.XCTFail import enum TSCBasic.ProcessEnv import struct TSCUtility.Version -public enum MockManifestLoaderError: Swift.Error { +package enum MockManifestLoaderError: Swift.Error { case unknownRequest(String) } @@ -34,24 +34,24 @@ public enum MockManifestLoaderError: Swift.Error { /// /// This implementation will throw an error if a request to load an unknown /// manifest is made. -public final class MockManifestLoader: ManifestLoaderProtocol { - public struct Key: Hashable { - public let url: String - public let version: Version? +package final class MockManifestLoader: ManifestLoaderProtocol { + package struct Key: Hashable { + package let url: String + package let version: Version? - public init(url: String, version: Version? = nil) { + package init(url: String, version: Version? = nil) { self.url = url self.version = version } } - public let manifests: ThreadSafeKeyValueStore + package let manifests: ThreadSafeKeyValueStore - public init(manifests: [Key: Manifest]) { + package init(manifests: [Key: Manifest]) { self.manifests = ThreadSafeKeyValueStore(manifests) } - public func load( + package func load( manifestPath: AbsolutePath, manifestToolsVersion: ToolsVersion, packageIdentity: PackageIdentity, @@ -76,12 +76,12 @@ public final class MockManifestLoader: ManifestLoaderProtocol { } } - public func resetCache(observabilityScope: ObservabilityScope) {} - public func purgeCache(observabilityScope: ObservabilityScope) {} + package func resetCache(observabilityScope: ObservabilityScope) {} + package func purgeCache(observabilityScope: ObservabilityScope) {} } extension ManifestLoader { - public func load( + package func load( manifestPath: AbsolutePath, packageKind: PackageReference.Kind, toolsVersion manifestToolsVersion: ToolsVersion, @@ -128,7 +128,7 @@ extension ManifestLoader { } extension ManifestLoader { - public func load( + package func load( packagePath: AbsolutePath, packageKind: PackageReference.Kind, currentToolsVersion: ToolsVersion, @@ -180,7 +180,7 @@ extension ManifestLoader { /// between threads. This means that when this method is called simultaneously /// from different threads, the environment will neither be setup nor restored /// correctly. -public func withCustomEnv(_ env: [String: String], body: () async throws -> Void) async throws { +package func withCustomEnv(_ env: [String: String], body: () async throws -> Void) async throws { let state = env.map { ($0, $1) } let restore = { for (key, value) in state { diff --git a/Sources/SPMTestSupport/MockPackage.swift b/Sources/SPMTestSupport/MockPackage.swift index d692b883930..ed56edcb2a7 100644 --- a/Sources/SPMTestSupport/MockPackage.swift +++ b/Sources/SPMTestSupport/MockPackage.swift @@ -14,20 +14,20 @@ import Basics import Foundation import PackageModel -public struct MockPackage { - public let name: String - public let platforms: [PlatformDescription] - public let location: Location - public let targets: [MockTarget] - public let products: [MockProduct] - public let dependencies: [MockDependency] - public let versions: [String?] +package struct MockPackage { + package let name: String + package let platforms: [PlatformDescription] + package let location: Location + package let targets: [MockTarget] + package let products: [MockProduct] + package let dependencies: [MockDependency] + package let versions: [String?] /// Provides revision identifier for the given version. A random identifier might be assigned if this is nil. - public let revisionProvider: ((String) -> String)? + package let revisionProvider: ((String) -> String)? // FIXME: This should be per-version. - public let toolsVersion: ToolsVersion? + package let toolsVersion: ToolsVersion? - public init( + package init( name: String, platforms: [PlatformDescription] = [], path: String? = nil, @@ -50,7 +50,7 @@ public struct MockPackage { self.toolsVersion = toolsVersion } - public init( + package init( name: String, platforms: [PlatformDescription] = [], url: String, @@ -72,7 +72,7 @@ public struct MockPackage { self.toolsVersion = toolsVersion } - public init( + package init( name: String, platforms: [PlatformDescription] = [], identity: String, @@ -100,7 +100,7 @@ public struct MockPackage { self.toolsVersion = toolsVersion } - public static func genericPackage(named name: String) throws -> MockPackage { + package static func genericPackage(named name: String) throws -> MockPackage { return MockPackage( name: name, targets: [ @@ -113,7 +113,7 @@ public struct MockPackage { ) } - public enum Location { + package enum Location { case fileSystem(path: RelativePath) case sourceControl(url: SourceControlURL) case registry(identity: PackageIdentity, alternativeURLs: [URL]?, metadata: RegistryReleaseMetadata?) diff --git a/Sources/SPMTestSupport/MockPackageContainer.swift b/Sources/SPMTestSupport/MockPackageContainer.swift index 730ddffe12b..0dc608943fc 100644 --- a/Sources/SPMTestSupport/MockPackageContainer.swift +++ b/Sources/SPMTestSupport/MockPackageContainer.swift @@ -19,12 +19,12 @@ import XCTest import struct TSCUtility.Version -public class MockPackageContainer: CustomPackageContainer { - public typealias Constraint = PackageContainerConstraint +package class MockPackageContainer: CustomPackageContainer { + package typealias Constraint = PackageContainerConstraint - public typealias Dependency = (container: PackageReference, requirement: PackageRequirement) + package typealias Dependency = (container: PackageReference, requirement: PackageRequirement) - public let package: PackageReference + package let package: PackageReference let dependencies: [String: [Dependency]] let filteredMode: Bool @@ -32,26 +32,26 @@ public class MockPackageContainer: CustomPackageContainer { let fileSystem: FileSystem? let customRetrievalPath: AbsolutePath? - public var unversionedDeps: [MockPackageContainer.Constraint] = [] + package var unversionedDeps: [MockPackageContainer.Constraint] = [] /// Contains the versions for which the dependencies were requested by resolver using getDependencies(). - public var requestedVersions: Set = [] + package var requestedVersions: Set = [] - public let _versions: [Version] - public func toolsVersionsAppropriateVersionsDescending() throws -> [Version] { + package let _versions: [Version] + package func toolsVersionsAppropriateVersionsDescending() throws -> [Version] { return try self.versionsDescending() } - public func versionsAscending() throws -> [Version] { + package func versionsAscending() throws -> [Version] { return _versions } - public func getDependencies(at version: Version, productFilter: ProductFilter) -> [MockPackageContainer.Constraint] { + package func getDependencies(at version: Version, productFilter: ProductFilter) -> [MockPackageContainer.Constraint] { requestedVersions.insert(version) return getDependencies(at: version.description, productFilter: productFilter) } - public func getDependencies(at revision: String, productFilter: ProductFilter) -> [MockPackageContainer.Constraint] { + package func getDependencies(at revision: String, productFilter: ProductFilter) -> [MockPackageContainer.Constraint] { let dependencies: [Dependency] if filteredMode { dependencies = filteredDependencies[productFilter]! @@ -64,27 +64,27 @@ public class MockPackageContainer: CustomPackageContainer { } } - public func getUnversionedDependencies(productFilter: ProductFilter) -> [MockPackageContainer.Constraint] { + package func getUnversionedDependencies(productFilter: ProductFilter) -> [MockPackageContainer.Constraint] { return unversionedDeps } - public func loadPackageReference(at boundVersion: BoundVersion) throws -> PackageReference { + package func loadPackageReference(at boundVersion: BoundVersion) throws -> PackageReference { return self.package } - public func isToolsVersionCompatible(at version: Version) -> Bool { + package func isToolsVersionCompatible(at version: Version) -> Bool { return true } - public func toolsVersion(for version: Version) throws -> ToolsVersion { + package func toolsVersion(for version: Version) throws -> ToolsVersion { return ToolsVersion.current } - public var isRemoteContainer: Bool? { + package var isRemoteContainer: Bool? { return true } - public func retrieve(at version: Version, progressHandler: ((Int64, Int64?) -> Void)?, observabilityScope: ObservabilityScope) throws -> AbsolutePath { + package func retrieve(at version: Version, progressHandler: ((Int64, Int64?) -> Void)?, observabilityScope: ObservabilityScope) throws -> AbsolutePath { if let customRetrievalPath { return customRetrievalPath } else { @@ -92,11 +92,11 @@ public class MockPackageContainer: CustomPackageContainer { } } - public func getFileSystem() throws -> FileSystem? { + package func getFileSystem() throws -> FileSystem? { return fileSystem } - public convenience init( + package convenience init( name: String, dependenciesByVersion: [Version: [(container: String, versionRequirement: VersionSetSpecifier)]] ) throws { @@ -113,7 +113,7 @@ public class MockPackageContainer: CustomPackageContainer { self.init(package: ref, dependencies: dependencies) } - public init( + package init( package: PackageReference, dependencies: [String: [Dependency]] = [:], fileSystem: FileSystem? = nil, @@ -129,7 +129,7 @@ public class MockPackageContainer: CustomPackageContainer { self.customRetrievalPath = customRetrievalPath } - public init( + package init( name: String, dependenciesByProductFilter: [ProductFilter: [(container: String, versionRequirement: VersionSetSpecifier)]] ) throws { @@ -154,16 +154,16 @@ public class MockPackageContainer: CustomPackageContainer { } } -public struct MockPackageContainerProvider: PackageContainerProvider { - public let containers: [MockPackageContainer] - public let containersByIdentifier: [PackageReference: MockPackageContainer] +package struct MockPackageContainerProvider: PackageContainerProvider { + package let containers: [MockPackageContainer] + package let containersByIdentifier: [PackageReference: MockPackageContainer] - public init(containers: [MockPackageContainer]) { + package init(containers: [MockPackageContainer]) { self.containers = containers self.containersByIdentifier = Dictionary(uniqueKeysWithValues: containers.map { ($0.package, $0) }) } - public func getContainer( + package func getContainer( for package: PackageReference, updateStrategy: ContainerUpdateStrategy, observabilityScope: ObservabilityScope, diff --git a/Sources/SPMTestSupport/MockPackageFingerprintStorage.swift b/Sources/SPMTestSupport/MockPackageFingerprintStorage.swift index 2c331346ad5..fe08d4fc8d9 100644 --- a/Sources/SPMTestSupport/MockPackageFingerprintStorage.swift +++ b/Sources/SPMTestSupport/MockPackageFingerprintStorage.swift @@ -18,18 +18,18 @@ import PackageModel import struct TSCUtility.Version -public class MockPackageFingerprintStorage: PackageFingerprintStorage { +package class MockPackageFingerprintStorage: PackageFingerprintStorage { private var packageFingerprints: [PackageIdentity: [Version: [Fingerprint .Kind: [Fingerprint.ContentType: Fingerprint]]]] private let lock = NSLock() - public init(_ packageFingerprints: [PackageIdentity: [Version: [Fingerprint + package init(_ packageFingerprints: [PackageIdentity: [Version: [Fingerprint .Kind: [Fingerprint.ContentType: Fingerprint]]]] = [:]) { self.packageFingerprints = packageFingerprints } - public func get( + package func get( package: PackageIdentity, version: Version, observabilityScope: ObservabilityScope, @@ -47,7 +47,7 @@ public class MockPackageFingerprintStorage: PackageFingerprintStorage { } } - public func put( + package func put( package: PackageIdentity, version: Version, fingerprint: Fingerprint, @@ -86,7 +86,7 @@ public class MockPackageFingerprintStorage: PackageFingerprintStorage { } } - public func get( + package func get( package: PackageReference, version: Version, observabilityScope: ObservabilityScope, @@ -102,7 +102,7 @@ public class MockPackageFingerprintStorage: PackageFingerprintStorage { ) } - public func put( + package func put( package: PackageReference, version: Version, fingerprint: Fingerprint, diff --git a/Sources/SPMTestSupport/MockPackageGraphs.swift b/Sources/SPMTestSupport/MockPackageGraphs.swift index 4ab9c0cde98..3f7b77ec353 100644 --- a/Sources/SPMTestSupport/MockPackageGraphs.swift +++ b/Sources/SPMTestSupport/MockPackageGraphs.swift @@ -20,15 +20,13 @@ import struct PackageModel.TargetDescription import protocol TSCBasic.FileSystem import class TSCBasic.InMemoryFileSystem -@_spi(SwiftPMInternal) -public typealias MockPackageGraph = ( +package typealias MockPackageGraph = ( graph: ModulesGraph, fileSystem: any FileSystem, observabilityScope: ObservabilityScope ) -@_spi(SwiftPMInternal) -public func macrosPackageGraph() throws -> MockPackageGraph { +package func macrosPackageGraph() throws -> MockPackageGraph { let fs = InMemoryFileSystem(emptyFiles: "/swift-firmware/Sources/Core/source.swift", "/swift-firmware/Sources/HAL/source.swift", @@ -126,8 +124,7 @@ public func macrosPackageGraph() throws -> MockPackageGraph { return (graph, fs, observability.topScope) } -@_spi(SwiftPMInternal) -public func trivialPackageGraph(pkgRootPath: AbsolutePath) throws -> MockPackageGraph { +package func trivialPackageGraph(pkgRootPath: AbsolutePath) throws -> MockPackageGraph { let fs = InMemoryFileSystem( emptyFiles: "/Pkg/Sources/app/main.swift", @@ -157,8 +154,7 @@ public func trivialPackageGraph(pkgRootPath: AbsolutePath) throws -> MockPackage return (graph, fs, observability.topScope) } -@_spi(SwiftPMInternal) -public func embeddedCxxInteropPackageGraph(pkgRootPath: AbsolutePath) throws -> MockPackageGraph { +package func embeddedCxxInteropPackageGraph(pkgRootPath: AbsolutePath) throws -> MockPackageGraph { let fs = InMemoryFileSystem( emptyFiles: "/Pkg/Sources/app/main.swift", diff --git a/Sources/SPMTestSupport/MockPackageSigningEntityStorage.swift b/Sources/SPMTestSupport/MockPackageSigningEntityStorage.swift index c53aff4014a..727ff1bf67a 100644 --- a/Sources/SPMTestSupport/MockPackageSigningEntityStorage.swift +++ b/Sources/SPMTestSupport/MockPackageSigningEntityStorage.swift @@ -18,15 +18,15 @@ import PackageSigning import struct TSCUtility.Version -public class MockPackageSigningEntityStorage: PackageSigningEntityStorage { +package class MockPackageSigningEntityStorage: PackageSigningEntityStorage { private var packageSigners: [PackageIdentity: PackageSigners] private let lock = NSLock() - public init(_ packageSigners: [PackageIdentity: PackageSigners] = [:]) { + package init(_ packageSigners: [PackageIdentity: PackageSigners] = [:]) { self.packageSigners = packageSigners } - public func get( + package func get( package: PackageIdentity, observabilityScope: ObservabilityScope, callbackQueue: DispatchQueue @@ -42,7 +42,7 @@ public class MockPackageSigningEntityStorage: PackageSigningEntityStorage { } @available(*, noasync, message: "Use the async alternative") - public func get( + package func get( package: PackageIdentity, observabilityScope: ObservabilityScope, callbackQueue: DispatchQueue, @@ -59,7 +59,7 @@ public class MockPackageSigningEntityStorage: PackageSigningEntityStorage { } } - public func put( + package func put( package: PackageIdentity, version: Version, signingEntity: SigningEntity, @@ -100,7 +100,7 @@ public class MockPackageSigningEntityStorage: PackageSigningEntityStorage { } } - public func add( + package func add( package: PackageIdentity, version: Version, signingEntity: SigningEntity, @@ -126,7 +126,7 @@ public class MockPackageSigningEntityStorage: PackageSigningEntityStorage { } } - public func changeSigningEntityFromVersion( + package func changeSigningEntityFromVersion( package: PackageIdentity, version: Version, signingEntity: SigningEntity, @@ -157,7 +157,7 @@ public class MockPackageSigningEntityStorage: PackageSigningEntityStorage { } } - public func changeSigningEntityForAllVersions( + package func changeSigningEntityForAllVersions( package: PackageIdentity, version: Version, signingEntity: SigningEntity, diff --git a/Sources/SPMTestSupport/MockProduct.swift b/Sources/SPMTestSupport/MockProduct.swift index 8e7659e8d54..b35c4fa9e4f 100644 --- a/Sources/SPMTestSupport/MockProduct.swift +++ b/Sources/SPMTestSupport/MockProduct.swift @@ -10,11 +10,11 @@ // //===----------------------------------------------------------------------===// -public struct MockProduct { - public let name: String - public let targets: [String] +package struct MockProduct { + package let name: String + package let targets: [String] - public init(name: String, targets: [String]) { + package init(name: String, targets: [String]) { self.name = name self.targets = targets } diff --git a/Sources/SPMTestSupport/MockRegistry.swift b/Sources/SPMTestSupport/MockRegistry.swift index 04b622864e9..c361afccfe7 100644 --- a/Sources/SPMTestSupport/MockRegistry.swift +++ b/Sources/SPMTestSupport/MockRegistry.swift @@ -23,12 +23,12 @@ import protocol TSCBasic.HashAlgorithm import struct TSCUtility.Version -public class MockRegistry { +package class MockRegistry { private let baseURL: URL private let fileSystem: FileSystem private let identityResolver: IdentityResolver private let checksumAlgorithm: HashAlgorithm - public var registryClient: RegistryClient! + package var registryClient: RegistryClient! private let jsonEncoder: JSONEncoder private var packageVersions = [PackageIdentity: [String: InMemoryRegistryPackageSource]]() @@ -36,7 +36,7 @@ public class MockRegistry { private var sourceControlURLs = [URL: PackageIdentity]() private let packagesLock = NSLock() - public init( + package init( filesystem: FileSystem, identityResolver: IdentityResolver, checksumAlgorithm: HashAlgorithm, @@ -74,7 +74,7 @@ public class MockRegistry { ) } - public func addPackage( + package func addPackage( identity: PackageIdentity, versions: [Version], sourceControlURLs: [URL]? = .none, @@ -88,7 +88,7 @@ public class MockRegistry { ) } - public func addPackage( + package func addPackage( identity: PackageIdentity, versions: [String], sourceControlURLs: [URL]? = .none, @@ -356,16 +356,16 @@ public class MockRegistry { } } -public struct InMemoryRegistryPackageSource { +package struct InMemoryRegistryPackageSource { let fileSystem: FileSystem - public let path: AbsolutePath + package let path: AbsolutePath - public init(fileSystem: FileSystem, path: AbsolutePath, writeContent: Bool = true) { + package init(fileSystem: FileSystem, path: AbsolutePath, writeContent: Bool = true) { self.fileSystem = fileSystem self.path = path } - public func writePackageContent(targets: [String] = [], toolsVersion: ToolsVersion = .current) throws { + package func writePackageContent(targets: [String] = [], toolsVersion: ToolsVersion = .current) throws { try self.fileSystem.createDirectory(self.path, recursive: true) let sourcesDir = self.path.appending("Sources") for target in targets { @@ -377,7 +377,7 @@ public struct InMemoryRegistryPackageSource { try self.fileSystem.writeFileContents(manifestPath, string: "// swift-tools-version:\(toolsVersion)") } - public func listFiles(root: AbsolutePath? = .none) throws -> [AbsolutePath] { + package func listFiles(root: AbsolutePath? = .none) throws -> [AbsolutePath] { var files = [AbsolutePath]() let root = root ?? self.path let entries = try self.fileSystem.getDirectoryContents(root) @@ -455,7 +455,7 @@ private struct MockRegistryArchiver: Archiver { } extension RegistryConfiguration.Security { - public static let testDefault: RegistryConfiguration.Security = { + package static let testDefault: RegistryConfiguration.Security = { var signing = RegistryConfiguration.Security.Signing() signing.onUnsigned = .silentAllow signing.onUntrustedCertificate = .silentAllow diff --git a/Sources/SPMTestSupport/MockTarget.swift b/Sources/SPMTestSupport/MockTarget.swift index b2f065a81cb..2d9750d9d27 100644 --- a/Sources/SPMTestSupport/MockTarget.swift +++ b/Sources/SPMTestSupport/MockTarget.swift @@ -13,21 +13,21 @@ import PackageGraph import PackageModel -public struct MockTarget { - public enum `Type` { +package struct MockTarget { + package enum `Type` { case regular, test, binary } - public let name: String - public let dependencies: [TargetDescription.Dependency] - public let path: String? - public let url: String? - public let checksum: String? - public let packageAccess: Bool - public let settings: [TargetBuildSettingDescription.Setting] - public let type: Type + package let name: String + package let dependencies: [TargetDescription.Dependency] + package let path: String? + package let url: String? + package let checksum: String? + package let packageAccess: Bool + package let settings: [TargetBuildSettingDescription.Setting] + package let type: Type - public init( + package init( name: String, dependencies: [TargetDescription.Dependency] = [], type: Type = .regular, diff --git a/Sources/SPMTestSupport/MockWorkspace.swift b/Sources/SPMTestSupport/MockWorkspace.swift index 344034f4494..717fc4f50ee 100644 --- a/Sources/SPMTestSupport/MockWorkspace.swift +++ b/Sources/SPMTestSupport/MockWorkspace.swift @@ -23,7 +23,7 @@ import class TSCBasic.InMemoryFileSystem import struct TSCUtility.Version -public final class MockWorkspace { +package final class MockWorkspace { let sandbox: AbsolutePath let fileSystem: InMemoryFileSystem let roots: [MockPackage] @@ -32,20 +32,20 @@ public final class MockWorkspace { let fingerprints: MockPackageFingerprintStorage let signingEntities: MockPackageSigningEntityStorage let mirrors: DependencyMirrors - public var registryClient: RegistryClient + package var registryClient: RegistryClient let registry: MockRegistry let customBinaryArtifactsManager: Workspace.CustomBinaryArtifactsManager - public var checksumAlgorithm: MockHashAlgorithm - public private(set) var manifestLoader: MockManifestLoader - public let repositoryProvider: InMemoryGitRepositoryProvider + package var checksumAlgorithm: MockHashAlgorithm + package private(set) var manifestLoader: MockManifestLoader + package let repositoryProvider: InMemoryGitRepositoryProvider let identityResolver: IdentityResolver let customPackageContainerProvider: MockPackageContainerProvider? - public let delegate = MockWorkspaceDelegate() + package let delegate = MockWorkspaceDelegate() let skipDependenciesUpdates: Bool - public var sourceControlToRegistryDependencyTransformation: WorkspaceConfiguration.SourceControlToRegistryDependencyTransformation + package var sourceControlToRegistryDependencyTransformation: WorkspaceConfiguration.SourceControlToRegistryDependencyTransformation var defaultRegistry: Registry? - public init( + package init( sandbox: AbsolutePath, fileSystem: InMemoryFileSystem, roots: [MockPackage], @@ -96,23 +96,23 @@ public final class MockWorkspace { try self.create() } - public var rootsDir: AbsolutePath { + package var rootsDir: AbsolutePath { return self.sandbox.appending("roots") } - public var packagesDir: AbsolutePath { + package var packagesDir: AbsolutePath { return self.sandbox.appending("pkgs") } - public var artifactsDir: AbsolutePath { + package var artifactsDir: AbsolutePath { return self.sandbox.appending(components: ".build", "artifacts") } - public func pathToRoot(withName name: String) throws -> AbsolutePath { + package func pathToRoot(withName name: String) throws -> AbsolutePath { return try AbsolutePath(validating: name, relativeTo: self.rootsDir) } - public func pathToPackage(withName name: String) throws -> AbsolutePath { + package func pathToPackage(withName name: String) throws -> AbsolutePath { return try AbsolutePath(validating: name, relativeTo: self.packagesDir) } @@ -267,7 +267,7 @@ public final class MockWorkspace { self.manifestLoader = MockManifestLoader(manifests: manifests) } - public func getOrCreateWorkspace() throws -> Workspace { + package func getOrCreateWorkspace() throws -> Workspace { if let workspace = self._workspace { return workspace } @@ -317,7 +317,7 @@ public final class MockWorkspace { private var _workspace: Workspace? - public func closeWorkspace(resetState: Bool = true, resetResolvedFile: Bool = true) throws { + package func closeWorkspace(resetState: Bool = true, resetResolvedFile: Bool = true) throws { if resetState { try self._workspace?.resetState() } @@ -329,11 +329,11 @@ public final class MockWorkspace { self._workspace = nil } - public func rootPaths(for packages: [String]) throws -> [AbsolutePath] { + package func rootPaths(for packages: [String]) throws -> [AbsolutePath] { return try packages.map { try AbsolutePath(validating: $0, relativeTo: rootsDir) } } - public func checkEdit( + package func checkEdit( packageName: String, path: AbsolutePath? = nil, revision: Revision? = nil, @@ -354,7 +354,7 @@ public final class MockWorkspace { result(observability.diagnostics) } - public func checkUnedit( + package func checkUnedit( packageName: String, roots: [String], forceRemove: Bool = false, @@ -375,7 +375,7 @@ public final class MockWorkspace { result(observability.diagnostics) } - public func checkResolve(pkg: String, roots: [String], version: TSCUtility.Version, _ result: ([Basics.Diagnostic]) -> Void) { + package func checkResolve(pkg: String, roots: [String], version: TSCUtility.Version, _ result: ([Basics.Diagnostic]) -> Void) { let observability = ObservabilitySystem.makeForTesting() observability.topScope.trap { let rootInput = PackageGraphRootInput(packages: try rootPaths(for: roots)) @@ -385,7 +385,7 @@ public final class MockWorkspace { result(observability.diagnostics) } - public func checkClean(_ result: ([Basics.Diagnostic]) -> Void) { + package func checkClean(_ result: ([Basics.Diagnostic]) -> Void) { let observability = ObservabilitySystem.makeForTesting() observability.topScope.trap { let workspace = try self.getOrCreateWorkspace() @@ -394,7 +394,7 @@ public final class MockWorkspace { result(observability.diagnostics) } - public func checkReset(_ result: ([Basics.Diagnostic]) -> Void) { + package func checkReset(_ result: ([Basics.Diagnostic]) -> Void) { let observability = ObservabilitySystem.makeForTesting() observability.topScope.trap { let workspace = try self.getOrCreateWorkspace() @@ -403,7 +403,7 @@ public final class MockWorkspace { result(observability.diagnostics) } - public func checkUpdate( + package func checkUpdate( roots: [String] = [], deps: [MockDependency] = [], packages: [String] = [], @@ -423,7 +423,7 @@ public final class MockWorkspace { result(observability.diagnostics) } - public func checkUpdateDryRun( + package func checkUpdateDryRun( roots: [String] = [], deps: [MockDependency] = [], _ result: ([(PackageReference, Workspace.PackageStateChange)]?, [Basics.Diagnostic]) -> Void @@ -442,7 +442,7 @@ public final class MockWorkspace { result(changes, observability.diagnostics) } - public func checkPackageGraph( + package func checkPackageGraph( roots: [String] = [], deps: [MockDependency], _ result: (ModulesGraph, [Basics.Diagnostic]) -> Void @@ -451,7 +451,7 @@ public final class MockWorkspace { try self.checkPackageGraph(roots: roots, dependencies: dependencies, result) } - public func checkPackageGraph( + package func checkPackageGraph( roots: [String] = [], dependencies: [PackageDependency] = [], forceResolvedVersions: Bool = false, @@ -481,7 +481,7 @@ public final class MockWorkspace { } } - public func checkPackageGraphFailure( + package func checkPackageGraphFailure( roots: [String] = [], deps: [MockDependency], _ result: ([Basics.Diagnostic]) -> Void @@ -490,7 +490,7 @@ public final class MockWorkspace { self.checkPackageGraphFailure(roots: roots, dependencies: dependencies, result) } - public func checkPackageGraphFailure( + package func checkPackageGraphFailure( roots: [String] = [], dependencies: [PackageDependency] = [], forceResolvedVersions: Bool = false, @@ -513,12 +513,12 @@ public final class MockWorkspace { result(observability.diagnostics) } - public struct ResolutionPrecomputationResult { - public let result: Workspace.ResolutionPrecomputationResult - public let diagnostics: [Basics.Diagnostic] + package struct ResolutionPrecomputationResult { + package let result: Workspace.ResolutionPrecomputationResult + package let diagnostics: [Basics.Diagnostic] } - public func checkPrecomputeResolution() async throws -> ResolutionPrecomputationResult { + package func checkPrecomputeResolution() async throws -> ResolutionPrecomputationResult { let observability = ObservabilitySystem.makeForTesting() let workspace = try self.getOrCreateWorkspace() let pinsStore = try workspace.pinsStore.load() @@ -548,7 +548,7 @@ public final class MockWorkspace { return ResolutionPrecomputationResult(result: result, diagnostics: observability.diagnostics) } - public func set( + package func set( pins: [PackageReference: CheckoutState] = [:], managedDependencies: [AbsolutePath: Workspace.ManagedDependency] = [:], managedArtifacts: [Workspace.ManagedArtifact] = [] @@ -566,7 +566,7 @@ public final class MockWorkspace { try self.set(pins: pins, managedDependencies: managedDependencies, managedArtifacts: managedArtifacts) } - public func set( + package func set( pins: [PackageReference: PinsStore.PinState], managedDependencies: [AbsolutePath: Workspace.ManagedDependency] = [:], managedArtifacts: [Workspace.ManagedArtifact] = [] @@ -599,13 +599,13 @@ public final class MockWorkspace { try workspace.state.save() } - public func resetState() throws { + package func resetState() throws { let workspace = try self.getOrCreateWorkspace() try workspace.resetState() } - public enum State { - public enum CheckoutState { + package enum State { + package enum CheckoutState { case version(TSCUtility.Version) case revision(String) case branch(String) @@ -618,31 +618,31 @@ public final class MockWorkspace { case custom(TSCUtility.Version, AbsolutePath) } - public struct ManagedDependencyResult { - public let managedDependencies: Workspace.ManagedDependencies + package struct ManagedDependencyResult { + package let managedDependencies: Workspace.ManagedDependencies - public init(_ managedDependencies: Workspace.ManagedDependencies) { + package init(_ managedDependencies: Workspace.ManagedDependencies) { self.managedDependencies = managedDependencies } - public func check(notPresent name: String, file: StaticString = #file, line: UInt = #line) { + package func check(notPresent name: String, file: StaticString = #file, line: UInt = #line) { self.check(notPresent: .plain(name), file: file, line: line) } - public func check(notPresent dependencyId: PackageIdentity, file: StaticString = #file, line: UInt = #line) { + package func check(notPresent dependencyId: PackageIdentity, file: StaticString = #file, line: UInt = #line) { let dependency = self.managedDependencies[dependencyId] XCTAssertNil(dependency, "Unexpectedly found \(dependencyId) in managed dependencies", file: file, line: line) } - public func checkEmpty(file: StaticString = #file, line: UInt = #line) { + package func checkEmpty(file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(self.managedDependencies.count, 0, file: file, line: line) } - public func check(dependency name: String, at state: State, file: StaticString = #file, line: UInt = #line) { + package func check(dependency name: String, at state: State, file: StaticString = #file, line: UInt = #line) { self.check(dependency: .plain(name), at: state, file: file, line: line) } - public func check(dependency dependencyId: PackageIdentity, at state: State, file: StaticString = #file, line: UInt = #line) { + package func check(dependency dependencyId: PackageIdentity, at state: State, file: StaticString = #file, line: UInt = #line) { guard let dependency = managedDependencies[dependencyId] else { return XCTFail("\(dependencyId) does not exists", file: file, line: line) } @@ -683,18 +683,18 @@ public final class MockWorkspace { } } - public struct ManagedArtifactResult { - public let managedArtifacts: Workspace.ManagedArtifacts + package struct ManagedArtifactResult { + package let managedArtifacts: Workspace.ManagedArtifacts - public init(_ managedArtifacts: Workspace.ManagedArtifacts) { + package init(_ managedArtifacts: Workspace.ManagedArtifacts) { self.managedArtifacts = managedArtifacts } - public func checkNotPresent(packageName: String, targetName: String, file: StaticString = #file, line: UInt = #line) { + package func checkNotPresent(packageName: String, targetName: String, file: StaticString = #file, line: UInt = #line) { self.checkNotPresent(packageIdentity: .plain(packageName), targetName: targetName, file : file, line: line) } - public func checkNotPresent( + package func checkNotPresent( packageIdentity: PackageIdentity, targetName: String, file: StaticString = #file, @@ -704,15 +704,15 @@ public final class MockWorkspace { XCTAssert(artifact == nil, "Unexpectedly found \(packageIdentity).\(targetName) in managed artifacts", file: file, line: line) } - public func checkEmpty(file: StaticString = #file, line: UInt = #line) { + package func checkEmpty(file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(self.managedArtifacts.count, 0, file: file, line: line) } - public func check(packageName: String, targetName: String, source: Workspace.ManagedArtifact.Source, path: AbsolutePath, file: StaticString = #file, line: UInt = #line) { + package func check(packageName: String, targetName: String, source: Workspace.ManagedArtifact.Source, path: AbsolutePath, file: StaticString = #file, line: UInt = #line) { self.check(packageIdentity: .plain(packageName), targetName: targetName, source: source, path: path, file: file, line: line) } - public func check( + package func check( packageIdentity: PackageIdentity, targetName: String, source: Workspace.ManagedArtifact.Source, @@ -737,7 +737,7 @@ public final class MockWorkspace { } } - public func loadDependencyManifests( + package func loadDependencyManifests( roots: [String] = [], deps: [MockDependency] = [], _ result: (Workspace.DependencyManifests, [Basics.Diagnostic]) -> Void @@ -758,7 +758,7 @@ public final class MockWorkspace { result(manifests, observability.diagnostics) } - public func checkManagedDependencies(file: StaticString = #file, line: UInt = #line, _ result: (ManagedDependencyResult) throws -> Void) { + package func checkManagedDependencies(file: StaticString = #file, line: UInt = #line, _ result: (ManagedDependencyResult) throws -> Void) { do { let workspace = try self.getOrCreateWorkspace() try result(ManagedDependencyResult(workspace.state.dependencies)) @@ -767,7 +767,7 @@ public final class MockWorkspace { } } - public func checkManagedArtifacts(file: StaticString = #file, line: UInt = #line, _ result: (ManagedArtifactResult) throws -> Void) { + package func checkManagedArtifacts(file: StaticString = #file, line: UInt = #line, _ result: (ManagedArtifactResult) throws -> Void) { do { let workspace = try self.getOrCreateWorkspace() try result(ManagedArtifactResult(workspace.state.artifacts)) @@ -776,18 +776,18 @@ public final class MockWorkspace { } } - public struct ResolvedResult { - public let store: PinsStore + package struct ResolvedResult { + package let store: PinsStore - public init(_ store: PinsStore) { + package init(_ store: PinsStore) { self.store = store } - public func check(notPresent name: String, file: StaticString = #file, line: UInt = #line) { + package func check(notPresent name: String, file: StaticString = #file, line: UInt = #line) { XCTAssertFalse(self.store.pins.keys.contains(where: { $0.description == name }), "Unexpectedly found \(name) in Package.resolved", file: file, line: line) } - public func check(dependency package: String, at state: State, file: StaticString = #file, line: UInt = #line) { + package func check(dependency package: String, at state: State, file: StaticString = #file, line: UInt = #line) { guard let pin = store.pins.first(where: { $0.key.description == package })?.value else { XCTFail("Pin for \(package) not found", file: file, line: line) return @@ -814,7 +814,7 @@ public final class MockWorkspace { } } - public func check(dependency package: String, url: String, file: StaticString = #file, line: UInt = #line) { + package func check(dependency package: String, url: String, file: StaticString = #file, line: UInt = #line) { guard let pin = store.pins.first(where: { $0.key.description == package })?.value else { XCTFail("Pin for \(package) not found", file: file, line: line) return @@ -824,7 +824,7 @@ public final class MockWorkspace { } } - public func checkResolved(file: StaticString = #file, line: UInt = #line, _ result: (ResolvedResult) throws -> Void) { + package func checkResolved(file: StaticString = #file, line: UInt = #line, _ result: (ResolvedResult) throws -> Void) { do { let workspace = try self.getOrCreateWorkspace() try result(ResolvedResult(workspace.pinsStore.load())) @@ -834,66 +834,66 @@ public final class MockWorkspace { } } -public final class MockWorkspaceDelegate: WorkspaceDelegate { +package final class MockWorkspaceDelegate: WorkspaceDelegate { private let lock = NSLock() private var _events = [String]() private var _manifest: Manifest? private var _manifestLoadingDiagnostics: [Basics.Diagnostic]? - public init() {} + package init() {} - public func willUpdateRepository(package: PackageIdentity, repository url: String) { + package func willUpdateRepository(package: PackageIdentity, repository url: String) { self.append("updating repo: \(url)") } - public func didUpdateRepository(package: PackageIdentity, repository url: String, duration: DispatchTimeInterval) { + package func didUpdateRepository(package: PackageIdentity, repository url: String, duration: DispatchTimeInterval) { self.append("finished updating repo: \(url)") } - public func dependenciesUpToDate() { + package func dependenciesUpToDate() { self.append("Everything is already up-to-date") } - public func willFetchPackage(package: PackageIdentity, packageLocation: String?, fetchDetails: PackageFetchDetails) { + package func willFetchPackage(package: PackageIdentity, packageLocation: String?, fetchDetails: PackageFetchDetails) { self.append("fetching package: \(packageLocation ?? package.description)") } - public func fetchingPackage(package: PackageIdentity, packageLocation: String?, progress: Int64, total: Int64?) { + package func fetchingPackage(package: PackageIdentity, packageLocation: String?, progress: Int64, total: Int64?) { } - public func didFetchPackage(package: PackageIdentity, packageLocation: String?, result: Result, duration: DispatchTimeInterval) { + package func didFetchPackage(package: PackageIdentity, packageLocation: String?, result: Result, duration: DispatchTimeInterval) { self.append("finished fetching package: \(packageLocation ?? package.description)") } - public func willCreateWorkingCopy(package: PackageIdentity, repository url: String, at path: AbsolutePath) { + package func willCreateWorkingCopy(package: PackageIdentity, repository url: String, at path: AbsolutePath) { self.append("creating working copy for: \(url)") } - public func didCreateWorkingCopy(package: PackageIdentity, repository url: String, at path: AbsolutePath, duration: DispatchTimeInterval) { + package func didCreateWorkingCopy(package: PackageIdentity, repository url: String, at path: AbsolutePath, duration: DispatchTimeInterval) { self.append("finished creating working copy for: \(url)") } - public func willCheckOut(package: PackageIdentity, repository url: String, revision: String, at path: AbsolutePath) { + package func willCheckOut(package: PackageIdentity, repository url: String, revision: String, at path: AbsolutePath) { self.append("checking out repo: \(url)") } - public func didCheckOut(package: PackageIdentity, repository url: String, revision: String, at path: AbsolutePath, duration: DispatchTimeInterval) { + package func didCheckOut(package: PackageIdentity, repository url: String, revision: String, at path: AbsolutePath, duration: DispatchTimeInterval) { self.append("finished checking out repo: \(url)") } - public func removing(package: PackageIdentity, packageLocation: String?) { + package func removing(package: PackageIdentity, packageLocation: String?) { self.append("removing repo: \(packageLocation ?? package.description)") } - public func willResolveDependencies(reason: WorkspaceResolveReason) { + package func willResolveDependencies(reason: WorkspaceResolveReason) { self.append("will resolve dependencies") } - public func willLoadManifest(packageIdentity: PackageIdentity, packagePath: AbsolutePath, url: String, version: Version?, packageKind: PackageReference.Kind) { + package func willLoadManifest(packageIdentity: PackageIdentity, packagePath: AbsolutePath, url: String, version: Version?, packageKind: PackageReference.Kind) { self.append("will load manifest for \(packageKind.displayName) package: \(url) (identity: \(packageIdentity))") } - public func didLoadManifest(packageIdentity: PackageIdentity, packagePath: AbsolutePath, url: String, version: Version?, packageKind: PackageReference.Kind, manifest: Manifest?, diagnostics: [Basics.Diagnostic], duration: DispatchTimeInterval) { + package func didLoadManifest(packageIdentity: PackageIdentity, packagePath: AbsolutePath, url: String, version: Version?, packageKind: PackageReference.Kind, manifest: Manifest?, diagnostics: [Basics.Diagnostic], duration: DispatchTimeInterval) { self.append("did load manifest for \(packageKind.displayName) package: \(url) (identity: \(packageIdentity))") self.lock.withLock { self._manifest = manifest @@ -901,71 +901,71 @@ public final class MockWorkspaceDelegate: WorkspaceDelegate { } } - public func willComputeVersion(package: PackageIdentity, location: String) { + package func willComputeVersion(package: PackageIdentity, location: String) { // noop } - public func didComputeVersion(package: PackageIdentity, location: String, version: String, duration: DispatchTimeInterval) { + package func didComputeVersion(package: PackageIdentity, location: String, version: String, duration: DispatchTimeInterval) { // noop } - public func resolvedFileChanged() { + package func resolvedFileChanged() { // noop } - public func willDownloadBinaryArtifact(from url: String, fromCache: Bool) { + package func willDownloadBinaryArtifact(from url: String, fromCache: Bool) { self.append("downloading binary artifact package: \(url)") } - public func didDownloadBinaryArtifact(from url: String, result: Result<(path: AbsolutePath, fromCache: Bool), Error>, duration: DispatchTimeInterval) { + package func didDownloadBinaryArtifact(from url: String, result: Result<(path: AbsolutePath, fromCache: Bool), Error>, duration: DispatchTimeInterval) { self.append("finished downloading binary artifact package: \(url)") } - public func downloadingBinaryArtifact(from url: String, bytesDownloaded: Int64, totalBytesToDownload: Int64?) { + package func downloadingBinaryArtifact(from url: String, bytesDownloaded: Int64, totalBytesToDownload: Int64?) { // noop } - public func didDownloadAllBinaryArtifacts() { + package func didDownloadAllBinaryArtifacts() { // noop } - public func willUpdateDependencies() { + package func willUpdateDependencies() { // noop } - public func didUpdateDependencies(duration: DispatchTimeInterval) { + package func didUpdateDependencies(duration: DispatchTimeInterval) { // noop } - public func willResolveDependencies() { + package func willResolveDependencies() { // noop } - public func didResolveDependencies(duration: DispatchTimeInterval) { + package func didResolveDependencies(duration: DispatchTimeInterval) { // noop } - public func willLoadGraph() { + package func willLoadGraph() { // noop } - public func didLoadGraph(duration: DispatchTimeInterval) { + package func didLoadGraph(duration: DispatchTimeInterval) { // noop } - public func willCompileManifest(packageIdentity: PackageIdentity, packageLocation: String) { + package func willCompileManifest(packageIdentity: PackageIdentity, packageLocation: String) { // noop } - public func didCompileManifest(packageIdentity: PackageIdentity, packageLocation: String, duration: DispatchTimeInterval) { + package func didCompileManifest(packageIdentity: PackageIdentity, packageLocation: String, duration: DispatchTimeInterval) { // noop } - public func willEvaluateManifest(packageIdentity: PackageIdentity, packageLocation: String) { + package func willEvaluateManifest(packageIdentity: PackageIdentity, packageLocation: String) { // noop } - public func didEvaluateManifest(packageIdentity: PackageIdentity, packageLocation: String, duration: DispatchTimeInterval) { + package func didEvaluateManifest(packageIdentity: PackageIdentity, packageLocation: String, duration: DispatchTimeInterval) { // noop } @@ -975,25 +975,25 @@ public final class MockWorkspaceDelegate: WorkspaceDelegate { } } - public var events: [String] { + package var events: [String] { self.lock.withLock { self._events } } - public func clear() { + package func clear() { self.lock.withLock { self._events = [] } } - public var manifest: Manifest? { + package var manifest: Manifest? { self.lock.withLock { self._manifest } } - public var manifestLoadingDiagnostics: [Basics.Diagnostic]? { + package var manifestLoadingDiagnostics: [Basics.Diagnostic]? { self.lock.withLock { self._manifestLoadingDiagnostics } @@ -1001,7 +1001,7 @@ public final class MockWorkspaceDelegate: WorkspaceDelegate { } extension CheckoutState { - public var version: Version? { + package var version: Version? { get { switch self { case .revision: @@ -1014,7 +1014,7 @@ extension CheckoutState { } } - public var branch: String? { + package var branch: String? { get { switch self { case .revision: @@ -1061,11 +1061,11 @@ extension CheckoutState { } extension Array where Element == Basics.Diagnostic { - public var hasErrors: Bool { + package var hasErrors: Bool { self.contains(where: { $0.severity == .error }) } - public var hasWarnings: Bool { + package var hasWarnings: Bool { self.contains(where: { $0.severity == .warning }) } } diff --git a/Sources/SPMTestSupport/Observability.swift b/Sources/SPMTestSupport/Observability.swift index 198e5b898f2..f997150e61a 100644 --- a/Sources/SPMTestSupport/Observability.swift +++ b/Sources/SPMTestSupport/Observability.swift @@ -19,43 +19,43 @@ import struct TSCBasic.StringError import TSCTestSupport extension ObservabilitySystem { - public static func makeForTesting(verbose: Bool = true) -> TestingObservability { + package static func makeForTesting(verbose: Bool = true) -> TestingObservability { let collector = TestingObservability.Collector(verbose: verbose) let observabilitySystem = ObservabilitySystem(collector) return TestingObservability(collector: collector, topScope: observabilitySystem.topScope) } - public static var NOOP: ObservabilityScope { + package static var NOOP: ObservabilityScope { ObservabilitySystem { _, _ in }.topScope } } -public struct TestingObservability { +package struct TestingObservability { private let collector: Collector - public let topScope: ObservabilityScope + package let topScope: ObservabilityScope fileprivate init(collector: Collector, topScope: ObservabilityScope) { self.collector = collector self.topScope = topScope } - public var diagnostics: [Basics.Diagnostic] { + package var diagnostics: [Basics.Diagnostic] { self.collector.diagnostics.get() } - public var errors: [Basics.Diagnostic] { + package var errors: [Basics.Diagnostic] { self.diagnostics.filter { $0.severity == .error } } - public var warnings: [Basics.Diagnostic] { + package var warnings: [Basics.Diagnostic] { self.diagnostics.filter { $0.severity == .warning } } - public var hasErrorDiagnostics: Bool { + package var hasErrorDiagnostics: Bool { self.collector.hasErrors } - public var hasWarningDiagnostics: Bool { + package var hasWarningDiagnostics: Bool { self.collector.hasWarnings } @@ -93,7 +93,7 @@ public struct TestingObservability { } } -public func XCTAssertNoDiagnostics( +package func XCTAssertNoDiagnostics( _ diagnostics: [Basics.Diagnostic], problemsOnly: Bool = true, file: StaticString = #file, @@ -105,7 +105,7 @@ public func XCTAssertNoDiagnostics( XCTFail("Found unexpected diagnostics: \n\(description)", file: file, line: line) } -public func testDiagnostics( +package func testDiagnostics( _ diagnostics: [Basics.Diagnostic], problemsOnly: Bool = true, file: StaticString = #file, @@ -121,7 +121,7 @@ public func testDiagnostics( ) } -public func testDiagnostics( +package func testDiagnostics( _ diagnostics: [Basics.Diagnostic], minSeverity: Basics.Diagnostic.Severity, file: StaticString = #file, @@ -142,7 +142,7 @@ public func testDiagnostics( } } -public func testPartialDiagnostics( +package func testPartialDiagnostics( _ diagnostics: [Basics.Diagnostic], minSeverity: Basics.Diagnostic.Severity, file: StaticString = #file, @@ -160,7 +160,7 @@ public func testPartialDiagnostics( } /// Helper to check diagnostics in the engine. -public class DiagnosticsTestResult { +package class DiagnosticsTestResult { fileprivate var uncheckedDiagnostics: [Basics.Diagnostic] init(_ diagnostics: [Basics.Diagnostic]) { @@ -168,7 +168,7 @@ public class DiagnosticsTestResult { } @discardableResult - public func check( + package func check( diagnostic message: StringPattern, severity: Basics.Diagnostic.Severity, //metadata: ObservabilityMetadata? = .none, @@ -192,7 +192,7 @@ public class DiagnosticsTestResult { } @discardableResult - public func checkUnordered( + package func checkUnordered( diagnostic diagnosticPattern: StringPattern, severity: Basics.Diagnostic.Severity, //metadata: ObservabilityMetadata? = .none, diff --git a/Sources/SPMTestSupport/PIFTester.swift b/Sources/SPMTestSupport/PIFTester.swift index 85b64cbf6e5..b03b1a4e827 100644 --- a/Sources/SPMTestSupport/PIFTester.swift +++ b/Sources/SPMTestSupport/PIFTester.swift @@ -14,11 +14,11 @@ import Basics import XCBuildSupport import XCTest -public func PIFTester(_ pif: PIF.TopLevelObject, _ body: (PIFWorkspaceTester) throws -> Void) throws { +package func PIFTester(_ pif: PIF.TopLevelObject, _ body: (PIFWorkspaceTester) throws -> Void) throws { try body(PIFWorkspaceTester(workspace: pif.workspace)) } -public final class PIFWorkspaceTester { +package final class PIFWorkspaceTester { private let workspace: PIF.Workspace private let projectMap: [PIF.GUID: PIF.Project] private let targetMap: [PIF.GUID: PIF.BaseTarget] @@ -32,7 +32,7 @@ public final class PIFWorkspaceTester { targetMap = Dictionary(uniqueKeysWithValues: targetsByGUID) } - public func checkProject( + package func checkProject( _ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, @@ -46,16 +46,16 @@ public final class PIFWorkspaceTester { } } -public final class PIFProjectTester { +package final class PIFProjectTester { private let project: PIF.Project private let targetMap: [PIF.GUID: PIF.BaseTarget] private let fileMap: [PIF.GUID: String] - public var guid: PIF.GUID { project.guid } - public var path: AbsolutePath { project.path } - public var projectDirectory: AbsolutePath { project.projectDirectory } - public var name: String { project.name } - public var developmentRegion: String { project.developmentRegion } + package var guid: PIF.GUID { project.guid } + package var path: AbsolutePath { project.path } + package var projectDirectory: AbsolutePath { project.projectDirectory } + package var name: String { project.name } + package var developmentRegion: String { project.developmentRegion } fileprivate init(project: PIF.Project, targetMap: [PIF.GUID: PIF.BaseTarget]) throws { self.project = project @@ -68,7 +68,7 @@ public final class PIFProjectTester { ) } - public func checkTarget( + package func checkTarget( _ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, @@ -86,7 +86,7 @@ public final class PIFProjectTester { body?(PIFTargetTester(target: target, targetMap: targetMap, fileMap: fileMap)) } - public func checkNoTarget( + package func checkNoTarget( _ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, @@ -97,7 +97,7 @@ public final class PIFProjectTester { } } - public func checkAggregateTarget( + package func checkAggregateTarget( _ guid: PIF.GUID, file: StaticString = #file, line: UInt = #line, @@ -115,7 +115,7 @@ public final class PIFProjectTester { body?(PIFAggregateTargetTester(target: target, targetMap: targetMap, fileMap: fileMap)) } - public func checkBuildConfiguration( + package func checkBuildConfiguration( _ name: String, file: StaticString = #file, line: UInt = #line, @@ -129,24 +129,24 @@ public final class PIFProjectTester { body(PIFBuildConfigurationTester(buildConfiguration: configuration)) } - public func buildConfiguration(withName name: String) -> PIF.BuildConfiguration? { + package func buildConfiguration(withName name: String) -> PIF.BuildConfiguration? { return project.buildConfigurations.first { $0.name == name } } - public func baseTarget(withGUID guid: PIF.GUID) -> PIF.BaseTarget? { + package func baseTarget(withGUID guid: PIF.GUID) -> PIF.BaseTarget? { return project.targets.first { $0.guid == guid } } } -public class PIFBaseTargetTester { - public let baseTarget: PIF.BaseTarget +package class PIFBaseTargetTester { + package let baseTarget: PIF.BaseTarget - public var guid: PIF.GUID { baseTarget.guid } - public var name: String { baseTarget.name } - public let dependencies: Set - public let sources: Set - public let frameworks: Set - public let resources: Set + package var guid: PIF.GUID { baseTarget.guid } + package var name: String { baseTarget.name } + package let dependencies: Set + package let sources: Set + package let frameworks: Set + package let resources: Set fileprivate init(baseTarget: PIF.BaseTarget, targetMap: [PIF.GUID: PIF.BaseTarget], fileMap: [PIF.GUID: String]) { self.baseTarget = baseTarget @@ -181,7 +181,7 @@ public class PIFBaseTargetTester { }) } - public func checkBuildConfiguration( + package func checkBuildConfiguration( _ name: String, file: StaticString = #file, line: UInt = #line, @@ -194,11 +194,11 @@ public class PIFBaseTargetTester { body(PIFBuildConfigurationTester(buildConfiguration: configuration)) } - public func buildConfiguration(withName name: String) -> PIF.BuildConfiguration? { + package func buildConfiguration(withName name: String) -> PIF.BuildConfiguration? { return baseTarget.buildConfigurations.first { $0.name == name } } - public func checkImpartedBuildSettings( + package func checkImpartedBuildSettings( file: StaticString = #file, line: UInt = #line, _ body: (PIFBuildSettingsTester) -> Void @@ -209,7 +209,7 @@ public class PIFBaseTargetTester { body(buildSettingsTester) } - public func checkAllImpartedBuildSettings( + package func checkAllImpartedBuildSettings( file: StaticString = #file, line: UInt = #line, _ body: (PIFBuildSettingsTester) -> Void @@ -221,7 +221,7 @@ public class PIFBaseTargetTester { buildSettingsTester.checkUncheckedSettings(file: file, line: line) } - public func checkNoImpartedBuildSettings(file: StaticString = #file, line: UInt = #line) { + package func checkNoImpartedBuildSettings(file: StaticString = #file, line: UInt = #line) { let buildSettingsTester = PIFBuildSettingsTester( buildSettings: baseTarget.buildConfigurations.first!.impartedBuildProperties.buildSettings ) @@ -229,10 +229,10 @@ public class PIFBaseTargetTester { } } -public final class PIFTargetTester: PIFBaseTargetTester { +package final class PIFTargetTester: PIFBaseTargetTester { private let target: PIF.Target - public var productType: PIF.Target.ProductType { target.productType } - public var productName: String { target.productName } + package var productType: PIF.Target.ProductType { target.productType } + package var productName: String { target.productName } fileprivate init(target: PIF.Target, targetMap: [PIF.GUID: PIF.BaseTarget], fileMap: [PIF.GUID: String]) { self.target = target @@ -240,7 +240,7 @@ public final class PIFTargetTester: PIFBaseTargetTester { } } -public final class PIFAggregateTargetTester: PIFBaseTargetTester { +package final class PIFAggregateTargetTester: PIFBaseTargetTester { private let target: PIF.AggregateTarget fileprivate init(target: PIF.AggregateTarget, targetMap: [PIF.GUID: PIF.BaseTarget], fileMap: [PIF.GUID: String]) { @@ -249,41 +249,41 @@ public final class PIFAggregateTargetTester: PIFBaseTargetTester { } } -public final class PIFBuildConfigurationTester { +package final class PIFBuildConfigurationTester { private let buildConfiguration: PIF.BuildConfiguration - public var guid: PIF.GUID { buildConfiguration.guid } - public var name: String { buildConfiguration.name } + package var guid: PIF.GUID { buildConfiguration.guid } + package var name: String { buildConfiguration.name } fileprivate init(buildConfiguration: PIF.BuildConfiguration) { self.buildConfiguration = buildConfiguration } - public func checkBuildSettings(file: StaticString = #file, line: UInt = #line, _ body: (PIFBuildSettingsTester) -> Void) { + package func checkBuildSettings(file: StaticString = #file, line: UInt = #line, _ body: (PIFBuildSettingsTester) -> Void) { let buildSettingsTester = PIFBuildSettingsTester(buildSettings: buildConfiguration.buildSettings) body(buildSettingsTester) } - public func checkAllBuildSettings(file: StaticString = #file, line: UInt = #line, _ body: (PIFBuildSettingsTester) -> Void) { + package func checkAllBuildSettings(file: StaticString = #file, line: UInt = #line, _ body: (PIFBuildSettingsTester) -> Void) { let buildSettingsTester = PIFBuildSettingsTester(buildSettings: buildConfiguration.buildSettings) body(buildSettingsTester) buildSettingsTester.checkUncheckedSettings(file: file, line: line) } - public func checkNoBuildSettings(file: StaticString = #file, line: UInt = #line) { + package func checkNoBuildSettings(file: StaticString = #file, line: UInt = #line) { let buildSettingsTester = PIFBuildSettingsTester(buildSettings: buildConfiguration.buildSettings) buildSettingsTester.checkUncheckedSettings(file: file, line: line) } } -public final class PIFBuildSettingsTester { +package final class PIFBuildSettingsTester { private var buildSettings: PIF.BuildSettings fileprivate init(buildSettings: PIF.BuildSettings) { self.buildSettings = buildSettings } - public subscript(_ key: PIF.BuildSettings.SingleValueSetting) -> String? { + package subscript(_ key: PIF.BuildSettings.SingleValueSetting) -> String? { if let value = buildSettings[key] { buildSettings[key] = nil return value @@ -292,7 +292,7 @@ public final class PIFBuildSettingsTester { } } - public subscript(_ key: PIF.BuildSettings.SingleValueSetting, for platform: PIF.BuildSettings.Platform) -> String? { + package subscript(_ key: PIF.BuildSettings.SingleValueSetting, for platform: PIF.BuildSettings.Platform) -> String? { if let value = buildSettings[key, for: platform] { buildSettings[key, for: platform] = nil return value @@ -301,7 +301,7 @@ public final class PIFBuildSettingsTester { } } - public subscript(_ key: PIF.BuildSettings.MultipleValueSetting) -> [String]? { + package subscript(_ key: PIF.BuildSettings.MultipleValueSetting) -> [String]? { if let value = buildSettings[key] { buildSettings[key] = nil return value @@ -310,7 +310,7 @@ public final class PIFBuildSettingsTester { } } - public subscript(_ key: PIF.BuildSettings.MultipleValueSetting, for platform: PIF.BuildSettings.Platform) -> [String]? { + package subscript(_ key: PIF.BuildSettings.MultipleValueSetting, for platform: PIF.BuildSettings.Platform) -> [String]? { if let value = buildSettings[key, for: platform] { buildSettings[key, for: platform] = nil return value @@ -319,7 +319,7 @@ public final class PIFBuildSettingsTester { } } - public func checkUncheckedSettings(file: StaticString = #file, line: UInt = #line) { + package func checkUncheckedSettings(file: StaticString = #file, line: UInt = #line) { let uncheckedKeys = Array(buildSettings.singleValueSettings.keys.map { $0.rawValue }) + Array(buildSettings.multipleValueSettings.keys.map { $0.rawValue }) diff --git a/Sources/SPMTestSupport/PackageDependencyDescriptionExtensions.swift b/Sources/SPMTestSupport/PackageDependencyDescriptionExtensions.swift index 3a167448a6f..16c289dc583 100644 --- a/Sources/SPMTestSupport/PackageDependencyDescriptionExtensions.swift +++ b/Sources/SPMTestSupport/PackageDependencyDescriptionExtensions.swift @@ -16,7 +16,7 @@ import PackageModel import struct TSCUtility.Version -public extension PackageDependency { +package extension PackageDependency { static func fileSystem(identity: PackageIdentity? = nil, deprecatedName: String? = nil, path: AbsolutePath, @@ -70,19 +70,19 @@ public extension PackageDependency { // backwards compatibility with existing tests extension PackageDependency.SourceControl.Requirement { - public static func upToNextMajor(from version: Version) -> Self { + package static func upToNextMajor(from version: Version) -> Self { return .range(.upToNextMajor(from: version)) } - public static func upToNextMinor(from version: Version) -> Self { + package static func upToNextMinor(from version: Version) -> Self { return .range(.upToNextMinor(from: version)) } } extension PackageDependency.Registry.Requirement { - public static func upToNextMajor(from version: Version) -> Self { + package static func upToNextMajor(from version: Version) -> Self { return .range(.upToNextMajor(from: version)) } - public static func upToNextMinor(from version: Version) -> Self { + package static func upToNextMinor(from version: Version) -> Self { return .range(.upToNextMinor(from: version)) } } diff --git a/Sources/SPMTestSupport/PackageGraphTester.swift b/Sources/SPMTestSupport/PackageGraphTester.swift index 97aa593a971..7a40c5a6d3f 100644 --- a/Sources/SPMTestSupport/PackageGraphTester.swift +++ b/Sources/SPMTestSupport/PackageGraphTester.swift @@ -17,36 +17,36 @@ import struct Basics.IdentifiableSet import PackageModel import PackageGraph -public func PackageGraphTester(_ graph: ModulesGraph, _ result: (PackageGraphResult) -> Void) { +package func PackageGraphTester(_ graph: ModulesGraph, _ result: (PackageGraphResult) -> Void) { result(PackageGraphResult(graph)) } -public final class PackageGraphResult { - public let graph: ModulesGraph +package final class PackageGraphResult { + package let graph: ModulesGraph - public init(_ graph: ModulesGraph) { + package init(_ graph: ModulesGraph) { self.graph = graph } // TODO: deprecate / transition to PackageIdentity - public func check(roots: String..., file: StaticString = #file, line: UInt = #line) { + package func check(roots: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(graph.rootPackages.map{$0.manifest.displayName }.sorted(), roots.sorted(), file: file, line: line) } - public func check(roots: PackageIdentity..., file: StaticString = #file, line: UInt = #line) { + package func check(roots: PackageIdentity..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(graph.rootPackages.map{$0.identity }.sorted(), roots.sorted(), file: file, line: line) } // TODO: deprecate / transition to PackageIdentity - public func check(packages: String..., file: StaticString = #file, line: UInt = #line) { + package func check(packages: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(graph.packages.map {$0.manifest.displayName }.sorted(), packages.sorted(), file: file, line: line) } - public func check(packages: PackageIdentity..., file: StaticString = #file, line: UInt = #line) { + package func check(packages: PackageIdentity..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(graph.packages.map {$0.identity }.sorted(), packages.sorted(), file: file, line: line) } - public func check(targets: String..., file: StaticString = #file, line: UInt = #line) { + package func check(targets: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual( graph.allTargets .filter{ $0.type != .test } @@ -54,19 +54,19 @@ public final class PackageGraphResult { .sorted(), targets.sorted(), file: file, line: line) } - public func check(products: String..., file: StaticString = #file, line: UInt = #line) { + package func check(products: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(Set(graph.allProducts.map { $0.name }), Set(products), file: file, line: line) } - public func check(reachableTargets: String..., file: StaticString = #file, line: UInt = #line) { + package func check(reachableTargets: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(Set(graph.reachableTargets.map { $0.name }), Set(reachableTargets), file: file, line: line) } - public func check(reachableProducts: String..., file: StaticString = #file, line: UInt = #line) { + package func check(reachableProducts: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(Set(graph.reachableProducts.map { $0.name }), Set(reachableProducts), file: file, line: line) } - public func check( + package func check( reachableBuildTargets: String..., in environment: BuildEnvironment, file: StaticString = #file, @@ -76,7 +76,7 @@ public final class PackageGraphResult { XCTAssertEqual(targets, Set(reachableBuildTargets), file: file, line: line) } - public func check( + package func check( reachableBuildProducts: String..., in environment: BuildEnvironment, file: StaticString = #file, @@ -86,7 +86,7 @@ public final class PackageGraphResult { XCTAssertEqual(products, Set(reachableBuildProducts), file: file, line: line) } - public func checkTarget( + package func checkTarget( _ name: String, file: StaticString = #file, line: UInt = #line, @@ -98,7 +98,7 @@ public final class PackageGraphResult { body(ResolvedTargetResult(target)) } - public func checkProduct( + package func checkProduct( _ name: String, file: StaticString = #file, line: UInt = #line, @@ -110,7 +110,7 @@ public final class PackageGraphResult { body(ResolvedProductResult(target)) } - public func check(testModules: String..., file: StaticString = #file, line: UInt = #line) { + package func check(testModules: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual( graph.allTargets .filter{ $0.type == .test } @@ -118,15 +118,15 @@ public final class PackageGraphResult { .sorted(), testModules.sorted(), file: file, line: line) } - public func find(target: String) -> ResolvedTarget? { + package func find(target: String) -> ResolvedTarget? { return graph.allTargets.first(where: { $0.name == target }) } - public func find(product: String) -> ResolvedProduct? { + package func find(product: String) -> ResolvedProduct? { return graph.allProducts.first(where: { $0.name == product }) } - public func find(package: PackageIdentity) -> ResolvedPackage? { + package func find(package: PackageIdentity) -> ResolvedPackage? { return graph.packages.first(where: { $0.identity == package }) } @@ -148,18 +148,18 @@ public final class PackageGraphResult { } } -public final class ResolvedTargetResult { +package final class ResolvedTargetResult { private let target: ResolvedTarget init(_ target: ResolvedTarget) { self.target = target } - public func check(dependencies: String..., file: StaticString = #file, line: UInt = #line) { + package func check(dependencies: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(Set(dependencies), Set(target.dependencies.map({ $0.name })), file: file, line: line) } - public func checkDependency( + package func checkDependency( _ name: String, file: StaticString = #file, line: UInt = #line, @@ -171,16 +171,16 @@ public final class ResolvedTargetResult { body(ResolvedTargetDependencyResult(dependency)) } - public func check(type: Target.Kind, file: StaticString = #file, line: UInt = #line) { + package func check(type: Target.Kind, file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(type, target.type, file: file, line: line) } - public func checkDeclaredPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { + package func checkDeclaredPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { let targetPlatforms = Dictionary(uniqueKeysWithValues: target.supportedPlatforms.map({ ($0.platform.name, $0.version.versionString) })) XCTAssertEqual(platforms, targetPlatforms, file: file, line: line) } - public func checkDerivedPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { + package func checkDerivedPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { let derived = platforms.map { let platform = PlatformRegistry.default.platformByName[$0.key] ?? PackageModel.Platform .custom(name: $0.key, oldestSupportedVersion: $0.value) @@ -193,24 +193,24 @@ public final class ResolvedTargetResult { XCTAssertEqual(platforms, targetPlatforms, file: file, line: line) } - public func checkDerivedPlatformOptions(_ platform: PackageModel.Platform, options: [String], file: StaticString = #file, line: UInt = #line) { + package func checkDerivedPlatformOptions(_ platform: PackageModel.Platform, options: [String], file: StaticString = #file, line: UInt = #line) { let platform = target.getSupportedPlatform(for: platform, usingXCTest: target.type == .test) XCTAssertEqual(platform.options, options, file: file, line: line) } } -public final class ResolvedTargetDependencyResult { +package final class ResolvedTargetDependencyResult { private let dependency: ResolvedTarget.Dependency init(_ dependency: ResolvedTarget.Dependency) { self.dependency = dependency } - public func checkConditions(satisfy environment: BuildEnvironment, file: StaticString = #file, line: UInt = #line) { + package func checkConditions(satisfy environment: BuildEnvironment, file: StaticString = #file, line: UInt = #line) { XCTAssert(dependency.conditions.allSatisfy({ $0.satisfies(environment) }), file: file, line: line) } - public func checkConditions( + package func checkConditions( dontSatisfy environment: BuildEnvironment, file: StaticString = #file, line: UInt = #line @@ -219,27 +219,27 @@ public final class ResolvedTargetDependencyResult { } } -public final class ResolvedProductResult { +package final class ResolvedProductResult { private let product: ResolvedProduct init(_ product: ResolvedProduct) { self.product = product } - public func check(targets: String..., file: StaticString = #file, line: UInt = #line) { + package func check(targets: String..., file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(Set(targets), Set(product.targets.map({ $0.name })), file: file, line: line) } - public func check(type: ProductType, file: StaticString = #file, line: UInt = #line) { + package func check(type: ProductType, file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(type, product.type, file: file, line: line) } - public func checkDeclaredPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { + package func checkDeclaredPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { let targetPlatforms = Dictionary(uniqueKeysWithValues: product.supportedPlatforms.map({ ($0.platform.name, $0.version.versionString) })) XCTAssertEqual(platforms, targetPlatforms, file: file, line: line) } - public func checkDerivedPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { + package func checkDerivedPlatforms(_ platforms: [String: String], file: StaticString = #file, line: UInt = #line) { let derived = platforms.map { let platform = PlatformRegistry.default.platformByName[$0.key] ?? PackageModel.Platform.custom(name: $0.key, oldestSupportedVersion: $0.value) return product.getSupportedPlatform(for: platform, usingXCTest: product.isLinkingXCTest) @@ -248,14 +248,14 @@ public final class ResolvedProductResult { XCTAssertEqual(platforms, targetPlatforms, file: file, line: line) } - public func checkDerivedPlatformOptions(_ platform: PackageModel.Platform, options: [String], file: StaticString = #file, line: UInt = #line) { + package func checkDerivedPlatformOptions(_ platform: PackageModel.Platform, options: [String], file: StaticString = #file, line: UInt = #line) { let platform = product.getSupportedPlatform(for: platform, usingXCTest: product.isLinkingXCTest) XCTAssertEqual(platform.options, options, file: file, line: line) } } extension ResolvedTarget.Dependency { - public var name: String { + package var name: String { switch self { case .target(let target, _): return target.name diff --git a/Sources/SPMTestSupport/ResolvedTarget+Mock.swift b/Sources/SPMTestSupport/ResolvedTarget+Mock.swift index 0a95c7aa8e1..6f109474acf 100644 --- a/Sources/SPMTestSupport/ResolvedTarget+Mock.swift +++ b/Sources/SPMTestSupport/ResolvedTarget+Mock.swift @@ -14,7 +14,7 @@ import PackageGraph import PackageModel extension ResolvedTarget { - public static func mock( + package static func mock( packageIdentity: PackageIdentity, name: String, deps: ResolvedTarget..., diff --git a/Sources/SPMTestSupport/Resolver.swift b/Sources/SPMTestSupport/Resolver.swift index f86371ce196..1e1282b7552 100644 --- a/Sources/SPMTestSupport/Resolver.swift +++ b/Sources/SPMTestSupport/Resolver.swift @@ -13,7 +13,7 @@ import PackageGraph extension PubGrubDependencyResolver { - public func solve(constraints: [Constraint]) -> Result<[DependencyResolverBinding], Error> { + package func solve(constraints: [Constraint]) -> Result<[DependencyResolverBinding], Error> { return solve(constraints: constraints, availableLibraries: [], preferPrebuiltLibraries: false) } } diff --git a/Sources/SPMTestSupport/SwiftPMProduct.swift b/Sources/SPMTestSupport/SwiftPMProduct.swift index 4522060b83e..3338b295be0 100644 --- a/Sources/SPMTestSupport/SwiftPMProduct.swift +++ b/Sources/SPMTestSupport/SwiftPMProduct.swift @@ -19,7 +19,7 @@ import struct TSCBasic.ProcessResult /// Defines the executables used by SwiftPM. /// Contains path to the currently built executable and /// helper method to execute them. -public enum SwiftPM { +package enum SwiftPM { case Build case Package case Registry @@ -44,11 +44,11 @@ extension SwiftPM { } } - public var xctestBinaryPath: AbsolutePath { + package var xctestBinaryPath: AbsolutePath { Self.xctestBinaryPath(for: RelativePath("swift-package-manager")) } - public static func xctestBinaryPath(for executableName: RelativePath) -> AbsolutePath { + package static func xctestBinaryPath(for executableName: RelativePath) -> AbsolutePath { #if canImport(Darwin) for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { return try! AbsolutePath(AbsolutePath(validating: bundle.bundlePath).parentDirectory, executableName) @@ -71,7 +71,7 @@ extension SwiftPM { /// /// - Returns: The output of the process. @discardableResult - public func execute( + package func execute( _ args: [String] = [], packagePath: AbsolutePath? = nil, env: [String: String]? = nil @@ -135,7 +135,7 @@ extension SwiftPM { } extension SwiftPM { - public static func packagePath(for packageName: String, packageRoot: AbsolutePath) throws -> AbsolutePath { + package static func packagePath(for packageName: String, packageRoot: AbsolutePath) throws -> AbsolutePath { // FIXME: The directory paths are hard coded right now and should be replaced by --get-package-path // whenever we design that. https://bugs.swift.org/browse/SR-2753 let packagesPath = packageRoot.appending(components: ".build", "checkouts") @@ -148,12 +148,12 @@ extension SwiftPM { } } -public enum SwiftPMError: Error { +package enum SwiftPMError: Error { case packagePathNotFound case executionFailure(underlying: Error, stdout: String, stderr: String) } -public enum SwiftPMProductError: Swift.Error { +package enum SwiftPMProductError: Swift.Error { case packagePathNotFound case executionFailure(error: Swift.Error, output: String, stderr: String) } diff --git a/Sources/SPMTestSupport/Toolchain.swift b/Sources/SPMTestSupport/Toolchain.swift index ff7e403c6b9..35a1a2c3c11 100644 --- a/Sources/SPMTestSupport/Toolchain.swift +++ b/Sources/SPMTestSupport/Toolchain.swift @@ -38,7 +38,7 @@ private func resolveBinDir() throws -> AbsolutePath { } extension SwiftSDK { - public static var `default`: Self { + package static var `default`: Self { get throws { let binDir = try resolveBinDir() return try! SwiftSDK.hostSwiftSDK(binDir) @@ -47,7 +47,7 @@ extension SwiftSDK { } extension UserToolchain { - public static var `default`: Self { + package static var `default`: Self { get throws { return try .init(swiftSDK: SwiftSDK.default) } @@ -56,7 +56,7 @@ extension UserToolchain { extension UserToolchain { /// Helper function to determine if async await actually works in the current environment. - public func supportsSwiftConcurrency() -> Bool { + package func supportsSwiftConcurrency() -> Bool { #if os(macOS) if #available(macOS 12.0, *) { // On macOS 12 and later, concurrency is assumed to work. @@ -67,7 +67,7 @@ extension UserToolchain { do { try testWithTemporaryDirectory { tmpPath in let inputPath = tmpPath.appending("foo.swift") - try localFileSystem.writeFileContents(inputPath, string: "public func foo() async {}\nTask { await foo() }") + try localFileSystem.writeFileContents(inputPath, string: "package func foo() async {}\nTask { await foo() }") let outputPath = tmpPath.appending("foo") let toolchainPath = self.swiftCompilerPath.parentDirectory.parentDirectory let backDeploymentLibPath = toolchainPath.appending(components: "lib", "swift-5.5", "macosx") @@ -88,7 +88,7 @@ extension UserToolchain { } /// Helper function to determine whether serialized diagnostics work properly in the current environment. - public func supportsSerializedDiagnostics(otherSwiftFlags: [String] = []) -> Bool { + package func supportsSerializedDiagnostics(otherSwiftFlags: [String] = []) -> Bool { do { try testWithTemporaryDirectory { tmpPath in let inputPath = tmpPath.appending("best.swift") @@ -112,7 +112,7 @@ extension UserToolchain { } /// Helper function to determine whether we should run SDK-dependent tests. - public func supportsSDKDependentTests() -> Bool { + package func supportsSDKDependentTests() -> Bool { return ProcessInfo.processInfo.environment["SWIFTCI_DISABLE_SDK_DEPENDENT_TESTS"] == nil } } diff --git a/Sources/SPMTestSupport/XCTAssertHelpers.swift b/Sources/SPMTestSupport/XCTAssertHelpers.swift index c771481b072..67adb785fcb 100644 --- a/Sources/SPMTestSupport/XCTAssertHelpers.swift +++ b/Sources/SPMTestSupport/XCTAssertHelpers.swift @@ -26,31 +26,31 @@ import struct TSCUtility.Version @_exported import func TSCTestSupport.XCTAssertResultSuccess @_exported import func TSCTestSupport.XCTAssertThrows -public func XCTAssertFileExists(_ path: AbsolutePath, file: StaticString = #file, line: UInt = #line) { +package func XCTAssertFileExists(_ path: AbsolutePath, file: StaticString = #file, line: UInt = #line) { TSCTestSupport.XCTAssertFileExists(TSCAbsolutePath(path), file: file, line: line) } -public func XCTAssertDirectoryExists(_ path: AbsolutePath, file: StaticString = #file, line: UInt = #line) { +package func XCTAssertDirectoryExists(_ path: AbsolutePath, file: StaticString = #file, line: UInt = #line) { TSCTestSupport.XCTAssertDirectoryExists(TSCAbsolutePath(path), file: file, line: line) } -public func XCTAssertNoSuchPath(_ path: AbsolutePath, file: StaticString = #file, line: UInt = #line) { +package func XCTAssertNoSuchPath(_ path: AbsolutePath, file: StaticString = #file, line: UInt = #line) { TSCTestSupport.XCTAssertNoSuchPath(TSCAbsolutePath(path), file: file, line: line) } -public func XCTAssertEqual (_ lhs:(T,U), _ rhs:(T,U), file: StaticString = #file, line: UInt = #line) { +package func XCTAssertEqual (_ lhs:(T,U), _ rhs:(T,U), file: StaticString = #file, line: UInt = #line) { TSCTestSupport.XCTAssertEqual(lhs, rhs, file: file, line: line) } -public func XCTSkipIfCI(file: StaticString = #filePath, line: UInt = #line) throws { +package func XCTSkipIfCI(file: StaticString = #filePath, line: UInt = #line) throws { if let ci = ProcessInfo.processInfo.environment["CI"] as? NSString, ci.boolValue { throw XCTSkip("Skipping because the test is being run on CI", file: file, line: line) } } /// An `async`-friendly replacement for `XCTAssertThrowsError`. -public func XCTAssertAsyncThrowsError( +package func XCTAssertAsyncThrowsError( _ expression: @autoclosure () async throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, @@ -66,7 +66,7 @@ public func XCTAssertAsyncThrowsError( } -public func XCTAssertBuilds( +package func XCTAssertBuilds( _ path: AbsolutePath, configurations: Set = [.Debug, .Release], extraArgs: [String] = [], @@ -94,7 +94,7 @@ public func XCTAssertBuilds( } } -public func XCTAssertSwiftTest( +package func XCTAssertSwiftTest( _ path: AbsolutePath, configuration: Configuration = .Debug, extraArgs: [String] = [], @@ -121,7 +121,7 @@ public func XCTAssertSwiftTest( } @discardableResult -public func XCTAssertBuildFails( +package func XCTAssertBuildFails( _ path: AbsolutePath, Xcc: [String] = [], Xld: [String] = [], @@ -137,7 +137,7 @@ public func XCTAssertBuildFails( return failure } -public func XCTAssertEqual( +package func XCTAssertEqual( _ assignment: [(container: T, version: Version)], _ expected: [T: Version], file: StaticString = #file, @@ -150,7 +150,7 @@ public func XCTAssertEqual( XCTAssertEqual(actual, expected, file: file, line: line) } -public func XCTAssertAsyncTrue( +package func XCTAssertAsyncTrue( _ expression: @autoclosure () async throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, @@ -160,7 +160,7 @@ public func XCTAssertAsyncTrue( XCTAssertTrue(result, message(), file: file, line: line) } -public func XCTAssertAsyncFalse( +package func XCTAssertAsyncFalse( _ expression: @autoclosure () async throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, @@ -170,7 +170,7 @@ public func XCTAssertAsyncFalse( XCTAssertFalse(result, message(), file: file, line: line) } -public func XCTAssertThrowsCommandExecutionError( +package func XCTAssertThrowsCommandExecutionError( _ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, @@ -187,7 +187,7 @@ public func XCTAssertThrowsCommandExecutionError( } } -public func XCTAssertAsyncEqual( +package func XCTAssertAsyncEqual( _ expression1: @autoclosure () async throws -> T, _ expression2: @autoclosure () async throws -> T, _ message: @autoclosure () -> String = "", @@ -202,7 +202,7 @@ public func XCTAssertAsyncEqual( struct XCAsyncTestErrorWhileUnwrappingOptional: Error {} -public func XCTAsyncUnwrap( +package func XCTAsyncUnwrap( _ expression: @autoclosure () async throws -> T?, _ message: @autoclosure () -> String = "", file: StaticString = #filePath, @@ -216,8 +216,8 @@ public func XCTAsyncUnwrap( } -public struct CommandExecutionError: Error { - public let result: ProcessResult - public let stdout: String - public let stderr: String +package struct CommandExecutionError: Error { + package let result: ProcessResult + package let stdout: String + package let stderr: String } diff --git a/Sources/SPMTestSupport/misc.swift b/Sources/SPMTestSupport/misc.swift index f4d8e10dea1..8a36a09237d 100644 --- a/Sources/SPMTestSupport/misc.swift +++ b/Sources/SPMTestSupport/misc.swift @@ -34,7 +34,7 @@ import enum TSCUtility.Git @_exported import enum TSCTestSupport.StringPattern /// Test helper utility for executing a block with a temporary directory. -public func testWithTemporaryDirectory( +package func testWithTemporaryDirectory( function: StaticString = #function, body: (AbsolutePath) throws -> Void ) throws { @@ -49,7 +49,7 @@ public func testWithTemporaryDirectory( } @discardableResult -public func testWithTemporaryDirectory( +package func testWithTemporaryDirectory( function: StaticString = #function, body: (AbsolutePath) async throws -> Result ) async throws -> Result { @@ -74,7 +74,7 @@ public func testWithTemporaryDirectory( /// The temporary copy is deleted after the block returns. The fixture name may /// contain `/` characters, which are treated as path separators, exactly as if /// the name were a relative path. -@discardableResult public func fixture( +@discardableResult package func fixture( name: String, createGitRepo: Bool = true, file: StaticString = #file, @@ -112,7 +112,7 @@ public func testWithTemporaryDirectory( } } -@discardableResult public func fixture( +@discardableResult package func fixture( name: String, createGitRepo: Bool = true, file: StaticString = #file, @@ -197,7 +197,7 @@ fileprivate func setup(fixtureDir: AbsolutePath, in tmpDirPath: AbsolutePath, co /// Test-helper function that creates a new Git repository in a directory. The new repository will contain /// exactly one empty file unless `addFile` is `false`, and if a tag name is provided, a tag with that name will be /// created. -public func initGitRepo( +package func initGitRepo( _ dir: AbsolutePath, tag: String? = nil, addFile: Bool = true, @@ -207,7 +207,7 @@ public func initGitRepo( initGitRepo(dir, tags: tag.flatMap { [$0] } ?? [], addFile: addFile, file: file, line: line) } -public func initGitRepo( +package func initGitRepo( _ dir: AbsolutePath, tags: [String], addFile: Bool = true, @@ -237,7 +237,7 @@ public func initGitRepo( } @discardableResult -public func executeSwiftBuild( +package func executeSwiftBuild( _ packagePath: AbsolutePath, configuration: Configuration = .Debug, extraArgs: [String] = [], @@ -251,7 +251,7 @@ public func executeSwiftBuild( } @discardableResult -public func executeSwiftRun( +package func executeSwiftRun( _ packagePath: AbsolutePath, _ executable: String, configuration: Configuration = .Debug, @@ -267,7 +267,7 @@ public func executeSwiftRun( } @discardableResult -public func executeSwiftPackage( +package func executeSwiftPackage( _ packagePath: AbsolutePath, configuration: Configuration = .Debug, extraArgs: [String] = [], @@ -281,7 +281,7 @@ public func executeSwiftPackage( } @discardableResult -public func executeSwiftTest( +package func executeSwiftTest( _ packagePath: AbsolutePath, configuration: Configuration = .Debug, extraArgs: [String] = [], @@ -321,7 +321,7 @@ private func swiftArgs( renamed: "loadModulesGraph", message: "Renamed for consistency: the type of this functions return value is named `ModulesGraph`." ) -public func loadPackageGraph( +package func loadPackageGraph( identityResolver: IdentityResolver = DefaultIdentityResolver(), fileSystem: FileSystem, manifests: [Manifest], @@ -347,7 +347,7 @@ public func loadPackageGraph( ) } -public func loadModulesGraph( +package func loadModulesGraph( identityResolver: IdentityResolver = DefaultIdentityResolver(), fileSystem: FileSystem, manifests: [Manifest], @@ -393,22 +393,22 @@ public func loadModulesGraph( ) } -public let emptyZipFile = ByteString([0x80, 0x75, 0x05, 0x06] + [UInt8](repeating: 0x00, count: 18)) +package let emptyZipFile = ByteString([0x80, 0x75, 0x05, 0x06] + [UInt8](repeating: 0x00, count: 18)) extension FileSystem { @_disfavoredOverload - public func createEmptyFiles(at root: AbsolutePath, files: String...) { + package func createEmptyFiles(at root: AbsolutePath, files: String...) { self.createEmptyFiles(at: TSCAbsolutePath(root), files: files) } @_disfavoredOverload - public func createEmptyFiles(at root: AbsolutePath, files: [String]) { + package func createEmptyFiles(at root: AbsolutePath, files: [String]) { self.createEmptyFiles(at: TSCAbsolutePath(root), files: files) } } extension URL { - public init(_ value: StringLiteralType) { + package init(_ value: StringLiteralType) { self.init(string: value)! } } @@ -426,13 +426,13 @@ extension PackageIdentity { } extension PackageIdentity { - public static func registry(_ value: String) -> RegistryIdentity { + package static func registry(_ value: String) -> RegistryIdentity { Self.plain(value).registry! } } extension AbsolutePath { - public init(_ value: StringLiteralType) { + package init(_ value: StringLiteralType) { try! self.init(validating: value) } } @@ -444,14 +444,14 @@ extension AbsolutePath { } extension AbsolutePath { - public init(_ path: StringLiteralType, relativeTo basePath: AbsolutePath) { + package init(_ path: StringLiteralType, relativeTo basePath: AbsolutePath) { try! self.init(validating: path, relativeTo: basePath) } } extension RelativePath { @available(*, deprecated, message: "use direct string instead") - public init(static path: StaticString) { + package init(static path: StaticString) { let pathString = path.withUTF8Buffer { String(decoding: $0, as: UTF8.self) } @@ -460,7 +460,7 @@ extension RelativePath { } extension RelativePath { - public init(_ value: StringLiteralType) { + package init(_ value: StringLiteralType) { try! self.init(validating: value) } } @@ -472,7 +472,7 @@ extension RelativePath { } extension InitPackage { - public convenience init( + package convenience init( name: String, packageType: PackageType, supportedTestingLibraries: Set = [.xctest], diff --git a/Tests/PackageGraphPerformanceTests/DependencyResolverPerfTests.swift b/Tests/PackageGraphPerformanceTests/DependencyResolverPerfTests.swift index 124ddc706be..9d92488bbf3 100644 --- a/Tests/PackageGraphPerformanceTests/DependencyResolverPerfTests.swift +++ b/Tests/PackageGraphPerformanceTests/DependencyResolverPerfTests.swift @@ -95,7 +95,7 @@ class DependencyResolverRealWorldPerfTests: XCTestCasePerf { // MARK: - JSON -public extension MockDependencyGraph { +extension MockDependencyGraph { init(_ json: JSON) { guard case .dictionary(let dict) = json else { fatalError() } guard case .string(let name)? = dict["name"] else { fatalError() }