@@ -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
@@ -177,8 +131,8 @@ public final class ManifestLoader: ManifestLoaderProtocol {
177131 completion: @escaping ( Result < Manifest , Error > ) -> Void
178132 ) {
179133 do {
180- let resources = try UserManifestResources ( swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags)
181- let loader = ManifestLoader ( manifestResources : resources )
134+ let toolchain = try ToolchainConfiguration ( swiftCompiler: swiftCompiler, swiftCompilerFlags: swiftCompilerFlags)
135+ let loader = ManifestLoader ( toolchain : toolchain )
182136 let toolsVersion = try ToolsVersionLoader ( ) . load ( at: path, fileSystem: fileSystem)
183137 let packageLocation = fileSystem. isFile ( path) ? path. parentDirectory : path
184138 let packageIdentity = identityResolver. resolveIdentity ( for: packageLocation)
@@ -713,14 +667,14 @@ public final class ManifestLoader: ManifestLoaderProtocol {
713667 let moduleCachePath = ( ProcessEnv . vars [ " SWIFTPM_MODULECACHE_OVERRIDE " ] ?? ProcessEnv . vars [ " SWIFTPM_TESTS_MODULECACHE " ] ) . flatMap { AbsolutePath . init ( $0) }
714668
715669 var cmd : [ String ] = [ ]
716- cmd += [ resources . swiftCompiler. pathString]
670+ cmd += [ self . toolchain . swiftCompiler. pathString]
717671 cmd += verbosity. ccArgs
718672
719673 let macOSPackageDescriptionPath : AbsolutePath
720674 // If we got the binDir that means we could be developing SwiftPM in Xcode
721675 // which produces a framework for dynamic package products.
722676 let packageFrameworkPath = runtimePath. appending ( component: " PackageFrameworks " )
723- if resources . binDir != nil , localFileSystem. exists ( packageFrameworkPath) {
677+ if self . toolchain . binDir != nil , localFileSystem. exists ( packageFrameworkPath) {
724678 cmd += [
725679 " -F " , packageFrameworkPath. pathString,
726680 " -framework " , " PackageDescription " ,
@@ -746,7 +700,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
746700 // Use the same minimum deployment target as the PackageDescription library (with a fallback of 10.15).
747701#if os(macOS)
748702 let triple = Self . _hostTriple. memoize {
749- Triple . getHostTriple ( usingSwiftCompiler: resources . swiftCompiler)
703+ Triple . getHostTriple ( usingSwiftCompiler: self . toolchain . swiftCompiler)
750704 }
751705
752706 let version = try Self . _packageDescriptionMinimumDeploymentTarget. memoize {
@@ -756,7 +710,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
756710#endif
757711
758712 // Add any extra flags required as indicated by the ManifestLoader.
759- cmd += resources . swiftCompilerFlags
713+ cmd += self . toolchain . swiftCompilerFlags
760714
761715 cmd += self . interpreterFlags ( for: toolsVersion)
762716 if let moduleCachePath = moduleCachePath {
@@ -879,7 +833,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
879833 cmd += [ " -swift-version " , toolsVersion. swiftLanguageVersion. rawValue]
880834 cmd += [ " -I " , runtimePath. pathString]
881835 #if os(macOS)
882- if let sdkRoot = resources . sdkRoot ?? self . sdkRoot ( ) {
836+ if let sdkRoot = self . toolchain . sdkRoot ?? self . sdkRoot ( ) {
883837 cmd += [ " -sdk " , sdkRoot. pathString]
884838 }
885839 #endif
@@ -890,18 +844,18 @@ public final class ManifestLoader: ManifestLoaderProtocol {
890844 /// Returns the runtime path given the manifest version and path to libDir.
891845 private func runtimePath( for version: ToolsVersion ) -> AbsolutePath {
892846 // Bin dir will be set when developing swiftpm without building all of the runtimes.
893- if let binDir = resources . binDir {
847+ if let binDir = self . toolchain . binDir {
894848 return binDir
895849 }
896850
897851 // Otherwise we use the standard location of the manifest API in the toolchain, if it exists.
898- let manifestAPIDir = resources . libDir. appending ( component: " ManifestAPI " )
852+ let manifestAPIDir = self . toolchain . libDir. appending ( component: " ManifestAPI " )
899853 if localFileSystem. exists ( manifestAPIDir) {
900854 return manifestAPIDir
901855 }
902856
903857 // Otherwise, fall back on the old location (this would indicate that we're using an old toolchain).
904- return resources . libDir. appending ( version. runtimeSubpath)
858+ return self . toolchain . libDir. appending ( version. runtimeSubpath)
905859 }
906860
907861 /// Returns path to the manifest database inside the given cache directory.
0 commit comments