diff --git a/Sources/Commands/SwiftTool.swift b/Sources/Commands/SwiftTool.swift index 3061a5bd101..c68b3de8e93 100644 --- a/Sources/Commands/SwiftTool.swift +++ b/Sources/Commands/SwiftTool.swift @@ -662,7 +662,7 @@ public class SwiftTool { } let delegate = ToolWorkspaceDelegate(self.outputStream, logLevel: self.logLevel, observabilityScope: self.observabilityScope) - let provider = GitRepositoryProvider(processSet: processSet) + let provider = GitRepositoryProvider(processSet: self.processSet) let sharedSecurityDirectory = try self.getSharedSecurityDirectory() let sharedCacheDirectory = try self.getSharedCacheDirectory() let sharedConfigurationDirectory = try self.getSharedConfigurationDirectory() @@ -677,16 +677,18 @@ public class SwiftTool { sharedCacheDirectory: sharedCacheDirectory, sharedConfigurationDirectory: sharedConfigurationDirectory ), - mirrors: self.getMirrorsConfig(sharedConfigurationDirectory: sharedConfigurationDirectory).mirrors, registries: try self.getRegistriesConfig(sharedConfigurationDirectory: sharedConfigurationDirectory).configuration, authorizationProvider: self.getAuthorizationProvider(), - customManifestLoader: self.getManifestLoader(), // FIXME: doe we really need to customize it? - customRepositoryProvider: provider, // FIXME: doe we really need to customize it? - additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes, - resolverUpdateEnabled: !options.skipDependencyUpdate, - resolverPrefetchingEnabled: options.shouldEnableResolverPrefetching, - resolverFingerprintCheckingMode: self.options.resolverFingerprintCheckingMode, - sharedRepositoriesCacheEnabled: self.options.useRepositoriesCache, + mirrors: self.getMirrorsConfig(sharedConfigurationDirectory: sharedConfigurationDirectory).mirrors, + resolutionConfiguration: ResolutionConfiguration( + updateEnabled: !options.skipDependencyUpdate, + prefetchingEnabled: options.shouldEnableResolverPrefetching, + additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes, + sharedRepositoriesCacheEnabled: self.options.useRepositoriesCache, + fingerprintCheckingMode: self.options.resolverFingerprintCheckingMode + ), + customManifestLoader: self.getManifestLoader(), // FIXME: ideally we would not customize the manifest loader + customRepositoryProvider: provider, // FIXME: ideally we would not customize the repository provider. its currently done for shutdown handling which can be better abstracted delegate: delegate ) _workspace = workspace diff --git a/Sources/SPMTestSupport/MockWorkspace.swift b/Sources/SPMTestSupport/MockWorkspace.swift index 6f16ba9190f..95cea4ab6e1 100644 --- a/Sources/SPMTestSupport/MockWorkspace.swift +++ b/Sources/SPMTestSupport/MockWorkspace.swift @@ -27,10 +27,10 @@ public final class MockWorkspace { public var registryClient: RegistryClient public let archiver: MockArchiver public let checksumAlgorithm: MockHashAlgorithm - public let fingerprintStorage: MockPackageFingerprintStorage let roots: [MockPackage] let packages: [MockPackage] public let mirrors: DependencyMirrors + public let fingerprints: MockPackageFingerprintStorage let identityResolver: IdentityResolver public var manifestLoader: MockManifestLoader public var repositoryProvider: InMemoryGitRepositoryProvider @@ -42,15 +42,15 @@ public final class MockWorkspace { public init( sandbox: AbsolutePath, fileSystem: InMemoryFileSystem, - mirrors: DependencyMirrors? = nil, roots: [MockPackage], packages: [MockPackage], toolsVersion: ToolsVersion = ToolsVersion.currentToolsVersion, - customHttpClient: HTTPClient? = .none, - customRegistryClient: RegistryClient? = .none, - customBinaryArchiver: MockArchiver? = .none, - customChecksumAlgorithm: MockHashAlgorithm? = .none, - customFingerprintStorage: MockPackageFingerprintStorage? = .none, + mirrors customMirrors: DependencyMirrors? = nil, + fingerprints customFingerprints: MockPackageFingerprintStorage? = .none, + httpClient customHttpClient: HTTPClient? = .none, + registryClient customRegistryClient: RegistryClient? = .none, + binaryArchiver customBinaryArchiver: MockArchiver? = .none, + checksumAlgorithm customChecksumAlgorithm: MockHashAlgorithm? = .none, resolverUpdateEnabled: Bool = true ) throws { let archiver = customBinaryArchiver ?? MockArchiver() @@ -61,8 +61,8 @@ public final class MockWorkspace { self.httpClient = httpClient self.archiver = archiver self.checksumAlgorithm = customChecksumAlgorithm ?? MockHashAlgorithm() - self.fingerprintStorage = customFingerprintStorage ?? MockPackageFingerprintStorage() - self.mirrors = mirrors ?? DependencyMirrors() + self.fingerprints = customFingerprints ?? MockPackageFingerprintStorage() + self.mirrors = customMirrors ?? DependencyMirrors() self.identityResolver = DefaultIdentityResolver(locationMapper: self.mirrors.effectiveURL(for:)) self.roots = roots self.packages = packages @@ -73,7 +73,7 @@ public final class MockWorkspace { identityResolver: self.identityResolver, checksumAlgorithm: self.checksumAlgorithm, filesystem: self.fileSystem, - fingerprintStorage: self.fingerprintStorage + fingerprintStorage: self.fingerprints ) self.registryClient = customRegistryClient ?? self.registry.registryClient self.toolsVersion = toolsVersion @@ -220,7 +220,7 @@ public final class MockWorkspace { return workspace } - let workspace = try Workspace( + let workspace = try Workspace._init( fileSystem: self.fileSystem, location: .init( workingDirectory: self.sandbox.appending(component: ".build"), @@ -230,7 +230,15 @@ public final class MockWorkspace { sharedCacheDirectory: self.fileSystem.swiftPMCacheDirectory, sharedConfigurationDirectory: self.fileSystem.swiftPMConfigDirectory ), + fingerprints: self.fingerprints, mirrors: self.mirrors, + resolutionConfiguration: ResolutionConfiguration( + updateEnabled: self.resolverUpdateEnabled, + prefetchingEnabled: true, + additionalFileRules: ResolutionConfiguration.default.additionalFileRules, + sharedRepositoriesCacheEnabled: ResolutionConfiguration.default.sharedRepositoriesCacheEnabled, + fingerprintCheckingMode: .strict + ), customToolsVersion: self.toolsVersion, customManifestLoader: self.manifestLoader, customRepositoryProvider: self.repositoryProvider, @@ -239,10 +247,6 @@ public final class MockWorkspace { customHTTPClient: self.httpClient, customArchiver: self.archiver, customChecksumAlgorithm: self.checksumAlgorithm, - customFingerprintStorage: self.fingerprintStorage, - resolverUpdateEnabled: self.resolverUpdateEnabled, - resolverPrefetchingEnabled: true, - resolverFingerprintCheckingMode: .strict, delegate: self.delegate ) diff --git a/Sources/Workspace/Workspace.swift b/Sources/Workspace/Workspace.swift index 0366522777f..19c5ca0c2ab 100644 --- a/Sources/Workspace/Workspace.swift +++ b/Sources/Workspace/Workspace.swift @@ -151,6 +151,49 @@ private struct WorkspaceDependencyResolverDelegate: DependencyResolverDelegate { func solved(result: [(package: PackageReference, binding: BoundVersion, products: ProductFilter)]) {} } +// FIXME: move out of here +public struct ResolutionConfiguration { + /// Enables the dependencies resolver automatic version updates. Enabled by default. When disabled the resolver relies only on the resolved version file. + public var updateEnabled: Bool + + /// Enables the dependencies resolver prefetching based on the resolved version file. Enabled by default. + public var prefetchingEnabled: Bool + + /// File rules to determine resource handling behavior. + public var additionalFileRules: [FileRuleDescription] + + /// Enables the shared repository cache. Enabled by default. + public var sharedRepositoriesCacheEnabled: Bool + + /// Fingerprint checking mode. Defaults to warning. + public var fingerprintCheckingMode: FingerprintCheckingMode + + public init( + updateEnabled: Bool, + prefetchingEnabled: Bool, + additionalFileRules: [FileRuleDescription], + sharedRepositoriesCacheEnabled: Bool, + fingerprintCheckingMode: FingerprintCheckingMode + ) { + self.updateEnabled = updateEnabled + self.prefetchingEnabled = prefetchingEnabled + self.additionalFileRules = additionalFileRules + self.sharedRepositoriesCacheEnabled = sharedRepositoriesCacheEnabled + self.fingerprintCheckingMode = fingerprintCheckingMode + } + + /// Default instance of ResolutionConfiguration + public static var `default`: Self { + .init( + updateEnabled: true, + prefetchingEnabled: true, + additionalFileRules: [], + sharedRepositoriesCacheEnabled: true, + fingerprintCheckingMode: .warn + ) + } +} + /// A workspace represents the state of a working project directory. /// /// The workspace is responsible for managing the persistent working state of a @@ -203,7 +246,7 @@ public class Workspace { /// The registry manager. // var for backwards compatibility with deprecated initializers, remove with them - fileprivate var registryClient: RegistryClient? + fileprivate var registryClient: RegistryClient /// The http client used for downloading binary artifacts. fileprivate let httpClient: HTTPClient @@ -216,19 +259,10 @@ public class Workspace { /// The algorithm used for generating file checksums. fileprivate let checksumAlgorithm: HashAlgorithm - /// The package fingerprint storage - fileprivate let fingerprintStorage: PackageFingerprintStorage? + /// The package fingerprints storage + fileprivate let fingerprints: PackageFingerprintStorage? - /// Enable prefetching containers in resolver. - fileprivate let resolverPrefetchingEnabled: Bool - - /// Update containers while fetching them. - fileprivate let resolverUpdateEnabled: Bool - - /// Fingerprint checking mode. - fileprivate let resolverFingerprintCheckingMode: FingerprintCheckingMode - - fileprivate let additionalFileRules: [FileRuleDescription] + fileprivate let resolutionConfiguration: ResolutionConfiguration // state @@ -237,36 +271,10 @@ public class Workspace { fileprivate var resolvedFileWatcher: ResolvedFileWatcher? - /// Create a new package workspace. - /// - /// This initializer is designed for use cases when the workspace needs to be highly customized such as testing. - /// In other cases, use the other, more straight forward, initializers - /// - /// This will automatically load the persisted state for the package, if - /// present. If the state isn't present then a default state will be - /// constructed. - /// - /// - Parameters: - /// - fileSystem: The file system to use. - /// - location: Workspace location configuration. - /// - mirrors: Dependencies mirrors. - /// - authorizationProvider: Provider of authentication information. - /// - customToolsVersion: A custom tools version. - /// - customManifestLoader: A custom manifest loader. - /// - customRepositoryManager: A custom repository manager. - /// - customRepositoryProvider: A custom repository provider. - /// - customIdentityResolver: A custom identity resolver. - /// - customHTTPClient: A custom http client. - /// - customArchiver: A custom archiver. - /// - customChecksumAlgorithm: A custom checksum algorithm. - /// - customFingerprintStorage: A custom fingerprint storage. - /// - additionalFileRules: File rules to determine resource handling behavior. - /// - resolverUpdateEnabled: Enables the dependencies resolver automatic version update check. Enabled by default. When disabled the resolver relies only on the resolved version file - /// - resolverPrefetchingEnabled: Enables the dependencies resolver prefetching based on the resolved version file. Enabled by default. - /// - resolverFingerprintCheckingMode: Fingerprint checking mode. Defaults to `.warn`. - /// - sharedRepositoriesCacheEnabled: Enables the shared repository cache. Enabled by default. - /// - delegate: Delegate for workspace events - public init( + // deprecate 12/21 + @_disfavoredOverload + @available(*, deprecated, message: "user alternative initializer") + public convenience init( fileSystem: FileSystem, location: Location, mirrors: DependencyMirrors? = .none, @@ -289,88 +297,91 @@ public class Workspace { sharedRepositoriesCacheEnabled: Bool? = .none, delegate: WorkspaceDelegate? = .none ) throws { + // defaults - let currentToolsVersion = customToolsVersion ?? ToolsVersion.currentToolsVersion - let toolsVersionLoader = ToolsVersionLoader() - let manifestLoader = try customManifestLoader ?? ManifestLoader( - toolchain: UserToolchain(destination: .hostDestination()).configuration, - cacheDir: location.sharedManifestsCacheDirectory + let resolutionConfiguration = ResolutionConfiguration( + updateEnabled: resolverUpdateEnabled ?? ResolutionConfiguration.default.updateEnabled, + prefetchingEnabled: resolverPrefetchingEnabled ?? ResolutionConfiguration.default.prefetchingEnabled, + additionalFileRules: additionalFileRules ?? ResolutionConfiguration.default.additionalFileRules, + sharedRepositoriesCacheEnabled: sharedRepositoriesCacheEnabled ?? ResolutionConfiguration.default.sharedRepositoriesCacheEnabled, + fingerprintCheckingMode: resolverFingerprintCheckingMode ) - let mirrors = mirrors ?? DependencyMirrors() - let identityResolver = customIdentityResolver ?? DefaultIdentityResolver(locationMapper: mirrors.effectiveURL(for:)) - let repositoryProvider = customRepositoryProvider ?? GitRepositoryProvider() - let sharedRepositoriesCacheEnabled = sharedRepositoriesCacheEnabled ?? true - let repositoryManager = customRepositoryManager ?? RepositoryManager( - fileSystem: fileSystem, - path: location.repositoriesDirectory, - provider: repositoryProvider, - delegate: delegate.map(WorkspaceRepositoryManagerDelegate.init(workspaceDelegate:)), - cachePath: sharedRepositoriesCacheEnabled ? location.sharedRepositoriesCacheDirectory : .none - ) - let fingerprintStorage = customFingerprintStorage ?? location.sharedFingerprintsDirectory.map { - FilePackageFingerprintStorage( - fileSystem: fileSystem, - directoryPath: $0 - ) - } - - let registryClient = customRegistryClient ?? registries.map { configuration in - RegistryClient( - configuration: configuration, - identityResolver: identityResolver, - fingerprintStorage: fingerprintStorage, - fingerprintCheckingMode: resolverFingerprintCheckingMode, - authorizationProvider: authorizationProvider?.httpAuthorizationHeader(for:) - ) - } - // FIXME: use workspace scope when migrating workspace to new observability API - let httpClient = customHTTPClient ?? HTTPClient() - let archiver = customArchiver ?? ZipArchiver() - - var checksumAlgorithm = customChecksumAlgorithm ?? SHA256() - #if canImport(CryptoKit) - if checksumAlgorithm is SHA256, #available(macOS 10.15, *) { - checksumAlgorithm = CryptoKitSHA256() - } - #endif - - let additionalFileRules = additionalFileRules ?? [] - let resolverUpdateEnabled = resolverUpdateEnabled ?? true - let resolverPrefetchingEnabled = resolverPrefetchingEnabled ?? false - - // initialize - self.fileSystem = fileSystem - self.location = location - self.delegate = delegate - self.mirrors = mirrors - self.authorizationProvider = authorizationProvider - self.manifestLoader = manifestLoader - self.currentToolsVersion = currentToolsVersion - self.toolsVersionLoader = toolsVersionLoader - self.httpClient = httpClient - self.archiver = archiver - self.repositoryManager = repositoryManager - self.registryClient = registryClient - self.identityResolver = identityResolver - self.checksumAlgorithm = checksumAlgorithm - self.fingerprintStorage = fingerprintStorage - - self.pinsStore = LoadableResult { - try PinsStore( - pinsFile: location.resolvedVersionsFile, - workingDirectory: location.workingDirectory, - fileSystem: fileSystem, - mirrors: mirrors - ) - } - - self.additionalFileRules = additionalFileRules - self.resolverUpdateEnabled = resolverUpdateEnabled - self.resolverPrefetchingEnabled = resolverPrefetchingEnabled - self.resolverFingerprintCheckingMode = resolverFingerprintCheckingMode + try self.init( + fileSystem: fileSystem, + location: location, + registries: registries, + authorizationProvider: authorizationProvider, + fingerprints: customFingerprintStorage, + mirrors: mirrors, + resolutionConfiguration: resolutionConfiguration, + customToolsVersion: customToolsVersion, + customManifestLoader: customManifestLoader, + customRepositoryManager: customRepositoryManager, + customRepositoryProvider: customRepositoryProvider, + customRegistryClient: customRegistryClient, + customIdentityResolver: customIdentityResolver, + customHTTPClient: customHTTPClient, + customArchiver: customArchiver, + customChecksumAlgorithm: customChecksumAlgorithm, + delegate: delegate + ) + } - self.state = WorkspaceState(dataPath: self.location.workingDirectory, fileSystem: fileSystem) + /// Create a new package workspace. + /// + /// This initializer is designed for use cases when the workspace needs to be highly customized such as testing. + /// In other cases, use the other, more straight forward, initializers + /// + /// This will automatically load the persisted state for the package, if + /// present. If the state isn't present then a default state will be + /// constructed. + /// + /// - Parameters: + /// - fileSystem: The file system to use. + /// - location: Workspace location configuration. + /// - registries: Configuration for registries + /// - authorizationProvider: Provider of authentication information for outbound network requests. + /// - fingerprints: Dependencies fingerprints. + /// - mirrors: Dependencies mirrors (overrides). + /// - resolutionConfiguration: Configuration to fine tune the dependency resolution behavior. + /// - customManifestLoader: A custom manifest loader. + /// - customRepositoryProvider: A custom repository provider. + /// - delegate: Delegate for workspace events + public convenience init( + fileSystem: FileSystem, + location: Location, + registries: RegistryConfiguration? = .none, + authorizationProvider: AuthorizationProvider? = .none, + fingerprints: PackageFingerprintStorage? = .none, + mirrors: DependencyMirrors? = .none, + resolutionConfiguration: ResolutionConfiguration? = .none, + // optional customization, primarily designed for testing + // FIXME: TBD what is actually needed here by libSwiftPM consumers + customManifestLoader: ManifestLoaderProtocol? = .none, + customRepositoryProvider: RepositoryProvider? = .none, + // delegate + delegate: WorkspaceDelegate? = .none + ) throws { + try self.init( + fileSystem: fileSystem, + location: location, + registries: registries, + authorizationProvider: authorizationProvider, + fingerprints: fingerprints, + mirrors: mirrors, + resolutionConfiguration: resolutionConfiguration, + customToolsVersion: .none, + customManifestLoader: customManifestLoader, + customRepositoryManager: .none, + customRepositoryProvider: customRepositoryProvider, + customRegistryClient: .none, + customIdentityResolver: .none, + customHTTPClient: .none, + customArchiver: .none, + customChecksumAlgorithm: .none, + delegate: delegate + ) } // deprecated 8/2021 @@ -522,6 +533,152 @@ public class Workspace { } return workspace } + + // public for testing (MockWorkspace) only + public static func _init( + // core + fileSystem: FileSystem, + location: Location, + registries: RegistryConfiguration? = .none, + authorizationProvider: AuthorizationProvider? = .none, + fingerprints: PackageFingerprintStorage? = .none, + mirrors: DependencyMirrors? = .none, + resolutionConfiguration: ResolutionConfiguration? = .none, + // optional customization, primarily designed for testing but also used in some cases by libSwiftPM consumers + customToolsVersion: ToolsVersion? = .none, + customManifestLoader: ManifestLoaderProtocol? = .none, + customRepositoryManager: RepositoryManager? = .none, + customRepositoryProvider: RepositoryProvider? = .none, + customRegistryClient: RegistryClient? = .none, + customIdentityResolver: IdentityResolver? = .none, + customHTTPClient: HTTPClient? = .none, + customArchiver: Archiver? = .none, + customChecksumAlgorithm: HashAlgorithm? = .none, + // delegate + delegate: WorkspaceDelegate? = .none + ) throws -> Self { + try .init( + fileSystem: fileSystem, + location: location, + registries: registries, + authorizationProvider: authorizationProvider, + fingerprints: fingerprints, + mirrors: mirrors, + resolutionConfiguration: resolutionConfiguration, + customToolsVersion: customToolsVersion, + customManifestLoader: customManifestLoader, + customRepositoryManager: customRepositoryManager, + customRepositoryProvider: customRepositoryProvider, + customRegistryClient: customRegistryClient, + customIdentityResolver: customIdentityResolver, + customHTTPClient: customHTTPClient, + customArchiver: customArchiver, + customChecksumAlgorithm: customChecksumAlgorithm, + delegate: delegate + ) + } + + // internal for testing + internal required init( + // core + fileSystem: FileSystem, + location: Location, + registries: RegistryConfiguration? = .none, + authorizationProvider: AuthorizationProvider? = .none, + fingerprints: PackageFingerprintStorage? = .none, + mirrors: DependencyMirrors? = .none, + resolutionConfiguration: ResolutionConfiguration? = .none, + // optional customization, primarily designed for testing but also used in some cases by libSwiftPM consumers + customToolsVersion: ToolsVersion? = .none, + customManifestLoader: ManifestLoaderProtocol? = .none, + customRepositoryManager: RepositoryManager? = .none, + customRepositoryProvider: RepositoryProvider? = .none, + customRegistryClient: RegistryClient? = .none, + customIdentityResolver: IdentityResolver? = .none, + customHTTPClient: HTTPClient? = .none, + customArchiver: Archiver? = .none, + customChecksumAlgorithm: HashAlgorithm? = .none, + //customFingerprintStorage: PackageFingerprintStorage? = .none, + // delegate + delegate: WorkspaceDelegate? = .none + ) throws { + // defaults + let currentToolsVersion = customToolsVersion ?? ToolsVersion.currentToolsVersion + let toolsVersionLoader = ToolsVersionLoader() + let manifestLoader = try customManifestLoader ?? ManifestLoader( + toolchain: UserToolchain(destination: .hostDestination()).configuration, + cacheDir: location.sharedManifestsCacheDirectory + ) + + let resolutionConfiguration = resolutionConfiguration ?? .default + let mirrors = mirrors ?? DependencyMirrors() + let identityResolver = customIdentityResolver ?? DefaultIdentityResolver(locationMapper: mirrors.effectiveURL(for:)) + let repositoryProvider = customRepositoryProvider ?? GitRepositoryProvider() + let repositoryManager = customRepositoryManager ?? RepositoryManager( + fileSystem: fileSystem, + path: location.repositoriesDirectory, + provider: repositoryProvider, + delegate: delegate.map(WorkspaceRepositoryManagerDelegate.init(workspaceDelegate:)), + cachePath: resolutionConfiguration.sharedRepositoriesCacheEnabled ? location.sharedRepositoriesCacheDirectory : .none + ) + + let fingerprints = fingerprints ?? location.sharedFingerprintsDirectory.map { + FilePackageFingerprintStorage( + fileSystem: fileSystem, + directoryPath: $0 + ) + } + + let registriesConfiguration = registries ?? RegistryConfiguration() + let registryClient = customRegistryClient ?? RegistryClient( + configuration: registriesConfiguration, + identityResolver: identityResolver, + fingerprintStorage: fingerprints, + fingerprintCheckingMode: resolutionConfiguration.fingerprintCheckingMode, + authorizationProvider: authorizationProvider?.httpAuthorizationHeader(for:) + ) + + // FIXME: use workspace scope when migrating workspace to new observability API + let httpClient = customHTTPClient ?? HTTPClient() + let archiver = customArchiver ?? ZipArchiver() + + var checksumAlgorithm = customChecksumAlgorithm ?? SHA256() + #if canImport(CryptoKit) + if checksumAlgorithm is SHA256, #available(macOS 10.15, *) { + checksumAlgorithm = CryptoKitSHA256() + } + #endif + + // initialize + self.fileSystem = fileSystem + self.location = location + self.delegate = delegate + self.mirrors = mirrors + self.authorizationProvider = authorizationProvider + self.manifestLoader = manifestLoader + self.currentToolsVersion = currentToolsVersion + self.toolsVersionLoader = toolsVersionLoader + self.httpClient = httpClient + self.archiver = archiver + self.repositoryManager = repositoryManager + self.registryClient = registryClient + self.identityResolver = identityResolver + self.checksumAlgorithm = checksumAlgorithm + self.fingerprints = fingerprints + + self.pinsStore = LoadableResult { + try PinsStore( + pinsFile: location.resolvedVersionsFile, + workingDirectory: location.workingDirectory, + fileSystem: fileSystem, + mirrors: mirrors + ) + } + + self.resolutionConfiguration = resolutionConfiguration + + self.state = WorkspaceState(dataPath: self.location.workingDirectory, fileSystem: fileSystem) + } } // MARK: - Public API @@ -927,7 +1084,7 @@ extension Workspace { return try PackageGraph.load( root: manifests.root, identityResolver: self.identityResolver, - additionalFileRules: additionalFileRules, + additionalFileRules: self.resolutionConfiguration.additionalFileRules, externalManifests: manifests.allDependencyManifests(), requiredDependencies: manifests.computePackages().required, unsafeAllowedPackages: manifests.unsafeAllowedPackages(), @@ -1128,9 +1285,6 @@ extension Workspace { // MARK: - Editing Functions extension Workspace { - - - /// Edit implementation. fileprivate func _edit( packageName: String, @@ -2944,8 +3098,8 @@ extension Workspace { return PubgrubDependencyResolver( provider: self, pinsMap: pinsMap, - updateEnabled: self.resolverUpdateEnabled, - prefetchingEnabled: self.resolverPrefetchingEnabled, + updateEnabled: self.resolutionConfiguration.updateEnabled, + prefetchingEnabled: self.resolutionConfiguration.prefetchingEnabled, observabilityScope: observabilityScope, delegate: delegate ) @@ -3075,8 +3229,8 @@ extension Workspace: PackageContainerProvider { manifestLoader: self.manifestLoader, toolsVersionLoader: self.toolsVersionLoader, currentToolsVersion: self.currentToolsVersion, - fingerprintStorage: self.fingerprintStorage, - fingerprintCheckingMode: self.resolverFingerprintCheckingMode, + fingerprintStorage: self.fingerprints, + fingerprintCheckingMode: self.resolutionConfiguration.fingerprintCheckingMode, observabilityScope: observabilityScope ) } @@ -3084,13 +3238,13 @@ extension Workspace: PackageContainerProvider { } // Resolve the container using the registry case .registry: - guard let registryClient = self.registryClient else { - throw StringError("registry not configured") - } + //guard let registryClient = self.registryClient else { + // throw StringError("registry not configured") + //} let container = RegistryPackageContainer( package: package, identityResolver: self.identityResolver, - registryClient: registryClient, + registryClient: self.registryClient, manifestLoader: self.manifestLoader, toolsVersionLoader: self.toolsVersionLoader, currentToolsVersion: self.currentToolsVersion, @@ -3333,9 +3487,9 @@ extension Workspace { progressHandler: ((_ bytesReceived: Int64, _ totalBytes: Int64?) -> Void)? = .none, observabilityScope: ObservabilityScope ) throws -> AbsolutePath { - guard let registryClient = self.registryClient else { - throw StringError("registry not configured") - } + //guard let registryClient = self.registryClient else { + // throw StringError("registry not configured") + //} guard case (let scope, let name)? = package.identity.scopeAndName else { throw StringError("invalid package identity") @@ -3347,7 +3501,7 @@ extension Workspace { } try temp_await { - registryClient.downloadSourceArchive( + self.registryClient.downloadSourceArchive( package: package.identity, version: version, fileSystem: self.fileSystem, diff --git a/Tests/WorkspaceTests/WorkspaceTests.swift b/Tests/WorkspaceTests/WorkspaceTests.swift index 32bc117b1b7..2614acf1404 100644 --- a/Tests/WorkspaceTests/WorkspaceTests.swift +++ b/Tests/WorkspaceTests/WorkspaceTests.swift @@ -3518,7 +3518,6 @@ final class WorkspaceTests: XCTestCase { let workspace = try MockWorkspace( sandbox: sandbox, fileSystem: fs, - mirrors: mirrors, roots: [ MockPackage( name: "Foo", @@ -3579,7 +3578,8 @@ final class WorkspaceTests: XCTestCase { ], versions: ["1.0.0", "1.5.0"] ), - ] + ], + mirrors: mirrors ) let deps: [MockDependency] = [ @@ -4455,7 +4455,7 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ) ], - customBinaryArchiver: archiver + binaryArchiver: archiver ) // Create dummy xcframework/artifactbundle zip files @@ -4665,8 +4665,8 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ) ], - customHttpClient: httpClient, - customBinaryArchiver: archiver + httpClient: httpClient, + binaryArchiver: archiver ) // Create dummy xcframework directories and zip files @@ -4838,7 +4838,7 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ), ], - customBinaryArchiver: archiver + binaryArchiver: archiver ) // Create dummy zip files @@ -4898,7 +4898,7 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ), ], - customBinaryArchiver: archiver + binaryArchiver: archiver ) workspace.checkPackageGraphFailure(roots: ["Foo"]) { diagnostics in @@ -4973,7 +4973,7 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ) ], - customBinaryArchiver: archiver + binaryArchiver: archiver ) // Create dummy zip files @@ -5059,7 +5059,7 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ) ], - customBinaryArchiver: archiver + binaryArchiver: archiver ) // Pin A to 1.0.0, Checkout B to 1.0.0 @@ -5295,8 +5295,8 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ), ], - customHttpClient: httpClient, - customBinaryArchiver: archiver + httpClient: httpClient, + binaryArchiver: archiver ) try workspace.checkPackageGraph(roots: ["Foo"]) { graph, diagnostics in @@ -5501,8 +5501,8 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ), ], - customHttpClient: httpClient, - customBinaryArchiver: archiver + httpClient: httpClient, + binaryArchiver: archiver ) let a4FrameworkPath = workspace.packagesDir.appending(components: "A", "XCFrameworks", "A4.xcframework") @@ -5736,8 +5736,8 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ) ], - customHttpClient: httpClient, - customBinaryArchiver: archiver + httpClient: httpClient, + binaryArchiver: archiver ) try workspace.checkPackageGraph(roots: ["Foo"]) { graph, diagnostics in @@ -5870,8 +5870,8 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ), ], - customHttpClient: httpClient, - customBinaryArchiver: archiver + httpClient: httpClient, + binaryArchiver: archiver ) workspace.checkPackageGraphFailure(roots: ["Foo"]) { diagnostics in @@ -5919,7 +5919,7 @@ final class WorkspaceTests: XCTestCase { versions: ["0.9.0", "1.0.0"] ), ], - customHttpClient: httpClient + httpClient: httpClient ) // Pin A to 1.0.0, Checkout A to 1.0.0 @@ -6040,8 +6040,8 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ) ], - customHttpClient: httpClient, - customBinaryArchiver: archiver + httpClient: httpClient, + binaryArchiver: archiver ) try workspace.checkPackageGraph(roots: ["Foo"]) { graph, diagnostics in @@ -6189,8 +6189,8 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ) ], - customHttpClient: httpClient, - customBinaryArchiver: archiver + httpClient: httpClient, + binaryArchiver: archiver ) try workspace.checkPackageGraph(roots: ["Foo"]) { graph, diagnostics in @@ -6387,9 +6387,9 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ), ], - customHttpClient: httpClient, - customBinaryArchiver: archiver, - customChecksumAlgorithm: checksumAlgorithm + httpClient: httpClient, + binaryArchiver: archiver, + checksumAlgorithm: checksumAlgorithm ) try workspace.checkPackageGraph(roots: ["Foo"]) { graph, diagnostics in @@ -6487,7 +6487,7 @@ final class WorkspaceTests: XCTestCase { versions: ["0.9.0", "1.0.0"] ), ], - customHttpClient: httpClient + httpClient: httpClient ) workspace.checkPackageGraphFailure(roots: ["Foo"]) { diagnostics in @@ -6560,7 +6560,7 @@ final class WorkspaceTests: XCTestCase { versions: ["0.9.0", "1.0.0"] ), ], - customHttpClient: httpClient + httpClient: httpClient ) workspace.checkPackageGraphFailure(roots: ["Foo"]) { diagnostics in @@ -6739,8 +6739,8 @@ final class WorkspaceTests: XCTestCase { versions: ["0.9.0", "1.0.0"] ), ], - customHttpClient: httpClient, - customBinaryArchiver: archiver + httpClient: httpClient, + binaryArchiver: archiver ) workspace.checkPackageGraphFailure(roots: ["Foo"]) { diagnostics in @@ -6818,7 +6818,7 @@ final class WorkspaceTests: XCTestCase { versions: ["0.9.0", "1.0.0"] ), ], - customHttpClient: httpClient + httpClient: httpClient ) workspace.checkPackageGraphFailure(roots: ["Foo"]) { diagnostics in @@ -6894,7 +6894,7 @@ final class WorkspaceTests: XCTestCase { versions: ["0.9.0", "1.0.0"] ), ], - customHttpClient: httpClient + httpClient: httpClient ) workspace.checkPackageGraphFailure(roots: ["Foo"]) { diagnostics in @@ -8945,7 +8945,7 @@ final class WorkspaceTests: XCTestCase { versions: ["1.0.0"] ) ], - customRegistryClient: registryClient + registryClient: registryClient ) workspace.checkPackageGraphFailure(roots: ["MyPackage"]) { diagnostics in