@@ -16,37 +16,56 @@ import TSCBasic
1616/// using the package manager with alternate toolchains in the future.
1717public struct ToolchainConfiguration {
1818 /// The path of the swift compiler.
19- public var swiftCompiler : AbsolutePath
19+ public var swiftCompilerPath : AbsolutePath
2020
2121 /// Extra arguments to pass the Swift compiler (defaults to the empty string).
2222 public var swiftCompilerFlags : [ String ]
2323
2424 /// Environment to pass to the Swift compiler (defaults to the inherited environment).
2525 public var swiftCompilerEnvironment : [ String : String ]
2626
27- /// The path of the library resources.
28- public var libDir : AbsolutePath
29-
30- /// The bin directory.
31- public var binDir : AbsolutePath ?
27+ /// SwiftPM library paths.
28+ public var swiftPMLibrariesLocation : SwiftPMLibrariesLocation
3229
3330 /// The path to SDK root.
3431 ///
3532 /// If provided, it will be passed to the swift interpreter.
36- public var sdkRoot : AbsolutePath ?
33+ public var sdkRootPath : AbsolutePath ?
3734
3835 /// XCTest Location
39- public var xctestLocation : AbsolutePath ?
36+ public var xctestPath : AbsolutePath ?
4037
4138 /// Creates the set of manifest resources associated with a `swiftc` executable.
4239 ///
4340 /// - Parameters:
44- /// - swiftCompiler: The absolute path of the associated `swiftc` executable.
45- /// - swiftCompilerFlags: Extra flags to pass the Swift compiler.: Extra flags to pass the Swift compiler.
46- /// - libDir: The path of the library resources.
47- /// - binDir: The bin directory.
48- /// - sdkRoot: The path to SDK root.
49- /// - xctestLocation: XCTest Location
41+ /// - swiftCompilerPath: The absolute path of the associated swift compiler executable (`swiftc`).
42+ /// - swiftCompilerFlags: Extra flags to pass to the Swift compiler.
43+ /// - swiftCompilerEnvironment: Environment variables to pass to the Swift compiler.
44+ /// - swiftPMLibrariesRootPath: Custom path for SwiftPM libraries. Computed based on the compiler path by default.
45+ /// - sdkRootPath: Optional path to SDK root.
46+ /// - xctestPath: Optional path to XCTest.
47+ public init (
48+ swiftCompilerPath: AbsolutePath ,
49+ swiftCompilerFlags: [ String ] = [ ] ,
50+ swiftCompilerEnvironment: [ String : String ] = ProcessEnv . vars,
51+ swiftPMLibrariesLocation: SwiftPMLibrariesLocation ? = nil ,
52+ sdkRootPath: AbsolutePath ? = nil ,
53+ xctestPath: AbsolutePath ? = nil
54+ ) {
55+ let swiftPMLibrariesLocation = swiftPMLibrariesLocation ?? {
56+ return . init( swiftCompilerPath: swiftCompilerPath)
57+ } ( )
58+
59+ self . swiftCompilerPath = swiftCompilerPath
60+ self . swiftCompilerFlags = swiftCompilerFlags
61+ self . swiftCompilerEnvironment = swiftCompilerEnvironment
62+ self . swiftPMLibrariesLocation = swiftPMLibrariesLocation
63+ self . sdkRootPath = sdkRootPath
64+ self . xctestPath = xctestPath
65+ }
66+
67+ // deprecated 8/2021
68+ @available ( * , deprecated, message: " use non-deprecated initializer instead " )
5069 public init (
5170 swiftCompiler: AbsolutePath ,
5271 swiftCompilerFlags: [ String ] = [ ] ,
@@ -56,16 +75,37 @@ public struct ToolchainConfiguration {
5675 sdkRoot: AbsolutePath ? = nil ,
5776 xctestLocation: AbsolutePath ? = nil
5877 ) {
59- self . swiftCompiler = swiftCompiler
60- self . swiftCompilerFlags = swiftCompilerFlags
61- self . swiftCompilerEnvironment = swiftCompilerEnvironment
62- self . libDir = libDir ?? Self . libDir ( forBinDir: swiftCompiler. parentDirectory)
63- self . binDir = binDir
64- self . sdkRoot = sdkRoot
65- self . xctestLocation = xctestLocation
78+ self . init (
79+ swiftCompilerPath: swiftCompiler,
80+ swiftCompilerFlags: swiftCompilerFlags,
81+ swiftCompilerEnvironment: swiftCompilerEnvironment,
82+ swiftPMLibrariesLocation: libDir. map { . init( root: $0) } ,
83+ sdkRootPath: sdkRoot,
84+ xctestPath: xctestLocation
85+ )
6686 }
87+ }
88+
89+ extension ToolchainConfiguration {
90+ public struct SwiftPMLibrariesLocation {
91+ public var manifestAPI : AbsolutePath
92+ public var pluginAPI : AbsolutePath
93+
94+ public init ( manifestAPI: AbsolutePath , pluginAPI: AbsolutePath ) {
95+ self . manifestAPI = manifestAPI
96+ self . pluginAPI = pluginAPI
97+ }
98+
99+ public init ( root: AbsolutePath ) {
100+ self . init (
101+ manifestAPI: root. appending ( component: " ManifestAPI " ) ,
102+ pluginAPI: root. appending ( component: " PluginAPI " )
103+ )
104+ }
67105
68- public static func libDir( forBinDir binDir: AbsolutePath ) -> AbsolutePath {
69- return binDir. parentDirectory. appending ( components: " lib " , " swift " , " pm " )
106+ public init ( swiftCompilerPath: AbsolutePath ) {
107+ let rootPath = swiftCompilerPath. parentDirectory. parentDirectory. appending ( components: " lib " , " swift " , " pm " )
108+ self . init ( root: rootPath)
109+ }
70110 }
71111}
0 commit comments