@@ -23,52 +23,6 @@ public enum ManifestParseError: Swift.Error, Equatable {
2323 case runtimeManifestErrors( [ String ] )
2424}
2525
26- /// Resources required for manifest loading.
27- ///
28- /// These requirements are abstracted out to make it easier to add support for
29- /// using the package manager with alternate toolchains in the future.
30- public protocol ManifestResourceProvider {
31- /// The path of the swift compiler.
32- var swiftCompiler : AbsolutePath { get }
33-
34- /// The path of the library resources.
35- var libDir : AbsolutePath { get }
36-
37- /// The path to SDK root.
38- ///
39- /// If provided, it will be passed to the swift interpreter.
40- var sdkRoot : AbsolutePath ? { get }
41-
42- /// The bin directory.
43- var binDir : AbsolutePath ? { get }
44-
45- /// Extra flags to pass the Swift compiler.
46- var swiftCompilerFlags : [ String ] { get }
47-
48- /// XCTest Location
49- var xctestLocation : AbsolutePath ? { get }
50- }
51-
52- /// Default implemention for the resource provider.
53- public extension ManifestResourceProvider {
54-
55- var sdkRoot : AbsolutePath ? {
56- return nil
57- }
58-
59- var binDir : AbsolutePath ? {
60- return nil
61- }
62-
63- var swiftCompilerFlags : [ String ] {
64- return [ ]
65- }
66-
67- var xctestLocation : AbsolutePath ? {
68- return nil
69- }
70- }
71-
7226/// Protocol for the manifest loader interface.
7327public protocol ManifestLoaderProtocol {
7428 /// Load the manifest for the package at `path`.
@@ -124,7 +78,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
12478 private static var _hostTriple = ThreadSafeBox < Triple > ( )
12579 private static var _packageDescriptionMinimumDeploymentTarget = ThreadSafeBox < String > ( )
12680
127- private let resources : ManifestResourceProvider
81+ private let toolchain : ToolchainConfiguration
12882 private let serializedDiagnostics : Bool
12983 private let isManifestSandboxEnabled : Bool
13084 private let delegate : ManifestLoaderDelegate ?
@@ -137,14 +91,14 @@ public final class ManifestLoader: ManifestLoaderProtocol {
13791 private let operationQueue : OperationQueue
13892
13993 public init (
140- manifestResources : ManifestResourceProvider ,
94+ toolchain : ToolchainConfiguration ,
14195 serializedDiagnostics: Bool = false ,
14296 isManifestSandboxEnabled: Bool = true ,
14397 cacheDir: AbsolutePath ? = nil ,
14498 delegate: ManifestLoaderDelegate ? = nil ,
14599 extraManifestFlags: [ String ] = [ ]
146100 ) {
147- self . resources = manifestResources
101+ self . toolchain = toolchain
148102 self . serializedDiagnostics = serializedDiagnostics
149103 self . isManifestSandboxEnabled = isManifestSandboxEnabled
150104 self . delegate = delegate
@@ -157,6 +111,26 @@ public final class ManifestLoader: ManifestLoaderProtocol {
157111 self . operationQueue. maxConcurrentOperationCount = Concurrency . maxOperations
158112 }
159113
114+ // deprecated 8/2021
115+ @available ( * , deprecated, message: " use non-deprecated constructor instead " )
116+ public convenience init (
117+ manifestResources: ToolchainConfiguration ,
118+ serializedDiagnostics: Bool = false ,
119+ isManifestSandboxEnabled: Bool = true ,
120+ cacheDir: AbsolutePath ? = nil ,
121+ delegate: ManifestLoaderDelegate ? = nil ,
122+ extraManifestFlags: [ String ] = [ ]
123+ ) {
124+ self . init (
125+ toolchain: manifestResources,
126+ serializedDiagnostics: serializedDiagnostics,
127+ isManifestSandboxEnabled: isManifestSandboxEnabled,
128+ cacheDir: cacheDir,
129+ delegate: delegate,
130+ extraManifestFlags: extraManifestFlags
131+ )
132+ }
133+
160134 /// Loads a root manifest from a path using the resources associated with a particular `swiftc` executable.
161135 ///
162136 /// - Parameters:
@@ -177,8 +151,8 @@ public final class ManifestLoader: ManifestLoaderProtocol {
177151 completion: @escaping ( Result < Manifest , Error > ) -> Void
178152 ) {
179153 do {
180- let resources = try UserManifestResources ( swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags)
181- let loader = ManifestLoader ( manifestResources : resources )
154+ let toolchain = try ToolchainConfiguration ( swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags)
155+ let loader = ManifestLoader ( toolchain : toolchain )
182156 let toolsVersion = try ToolsVersionLoader ( ) . load ( at: path, fileSystem: fileSystem)
183157 let packageLocation = fileSystem. isFile ( path) ? path. parentDirectory : path
184158 let packageIdentity = identityResolver. resolveIdentity ( for: packageLocation)
@@ -713,14 +687,14 @@ public final class ManifestLoader: ManifestLoaderProtocol {
713687 let moduleCachePath = ( ProcessEnv . vars [ " SWIFTPM_MODULECACHE_OVERRIDE " ] ?? ProcessEnv . vars [ " SWIFTPM_TESTS_MODULECACHE " ] ) . flatMap { AbsolutePath . init ( $0) }
714688
715689 var cmd : [ String ] = [ ]
716- cmd += [ resources . swiftCompiler. pathString]
690+ cmd += [ self . toolchain . swiftCompiler. pathString]
717691 cmd += verbosity. ccArgs
718692
719693 let macOSPackageDescriptionPath : AbsolutePath
720694 // If we got the binDir that means we could be developing SwiftPM in Xcode
721695 // which produces a framework for dynamic package products.
722696 let packageFrameworkPath = runtimePath. appending ( component: " PackageFrameworks " )
723- if resources . binDir != nil , localFileSystem. exists ( packageFrameworkPath) {
697+ if self . toolchain . binDir != nil , localFileSystem. exists ( packageFrameworkPath) {
724698 cmd += [
725699 " -F " , packageFrameworkPath. pathString,
726700 " -framework " , " PackageDescription " ,
@@ -746,7 +720,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
746720 // Use the same minimum deployment target as the PackageDescription library (with a fallback of 10.15).
747721#if os(macOS)
748722 let triple = Self . _hostTriple. memoize {
749- Triple . getHostTriple ( usingSwiftCompiler: resources . swiftCompiler)
723+ Triple . getHostTriple ( usingSwiftCompiler: self . toolchain . swiftCompiler)
750724 }
751725
752726 let version = try Self . _packageDescriptionMinimumDeploymentTarget. memoize {
@@ -756,7 +730,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
756730#endif
757731
758732 // Add any extra flags required as indicated by the ManifestLoader.
759- cmd += resources . swiftCompilerFlags
733+ cmd += self . toolchain . swiftCompilerFlags
760734
761735 cmd += self . interpreterFlags ( for: toolsVersion)
762736 if let moduleCachePath = moduleCachePath {
@@ -879,7 +853,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
879853 cmd += [ " -swift-version " , toolsVersion. swiftLanguageVersion. rawValue]
880854 cmd += [ " -I " , runtimePath. pathString]
881855 #if os(macOS)
882- if let sdkRoot = resources . sdkRoot ?? self . sdkRoot ( ) {
856+ if let sdkRoot = self . toolchain . sdkRoot ?? self . sdkRoot ( ) {
883857 cmd += [ " -sdk " , sdkRoot. pathString]
884858 }
885859 #endif
@@ -890,18 +864,18 @@ public final class ManifestLoader: ManifestLoaderProtocol {
890864 /// Returns the runtime path given the manifest version and path to libDir.
891865 private func runtimePath( for version: ToolsVersion ) -> AbsolutePath {
892866 // Bin dir will be set when developing swiftpm without building all of the runtimes.
893- if let binDir = resources . binDir {
867+ if let binDir = self . toolchain . binDir {
894868 return binDir
895869 }
896870
897871 // Otherwise we use the standard location of the manifest API in the toolchain, if it exists.
898- let manifestAPIDir = resources . libDir. appending ( component: " ManifestAPI " )
872+ let manifestAPIDir = self . toolchain . libDir. appending ( component: " ManifestAPI " )
899873 if localFileSystem. exists ( manifestAPIDir) {
900874 return manifestAPIDir
901875 }
902876
903877 // Otherwise, fall back on the old location (this would indicate that we're using an old toolchain).
904- return resources . libDir. appending ( version. runtimeSubpath)
878+ return self . toolchain . libDir. appending ( version. runtimeSubpath)
905879 }
906880
907881 /// Returns path to the manifest database inside the given cache directory.
0 commit comments