@@ -45,11 +45,6 @@ public final class UserToolchain: Toolchain {
45
45
/// The manifest resource provider.
46
46
public let manifestResources : ManifestResourceProvider
47
47
48
- /// Cache for storing paths of tools after first lookup.
49
- ///
50
- /// Key -> name of the tool.
51
- private var toolsPathCache : [ String : AbsolutePath ]
52
-
53
48
/// Path of the `swiftc` compiler.
54
49
public let swiftCompiler : AbsolutePath
55
50
@@ -144,60 +139,51 @@ public final class UserToolchain: Toolchain {
144
139
/// Environment to use when looking up tools.
145
140
private let processEnvironment : [ String : String ]
146
141
147
- private func lookup( tool toolName: String ) throws -> AbsolutePath {
148
- // Check the cache.
149
- if let toolPath = toolsPathCache [ toolName] {
142
+ /// Returns the path to clang compiler tool.
143
+ public func getClangCompiler( ) throws -> AbsolutePath {
144
+ // Check if we already computed.
145
+ if let clang = _clangCompiler {
146
+ return clang
147
+ }
148
+
149
+ // Check in the environment variable first.
150
+ if let toolPath = UserToolchain . lookup ( variable: " CC " , searchPaths: envSearchPaths) {
151
+ _clangCompiler = toolPath
150
152
return toolPath
151
153
}
152
154
153
155
// Otherwise, lookup the tool on the system.
154
- let arguments = whichArgs + [ toolName ]
156
+ let arguments = whichArgs + [ " clang " ]
155
157
let foundPath = try Process . checkNonZeroExit ( arguments: arguments, environment: processEnvironment) . spm_chomp ( )
156
158
guard !foundPath. isEmpty else {
157
- throw InvalidToolchainDiagnostic ( " could not find \( toolName ) " )
159
+ throw InvalidToolchainDiagnostic ( " could not find clang " )
158
160
}
161
+ let toolPath = try AbsolutePath ( validating: foundPath)
159
162
160
- let toolPath = AbsolutePath ( foundPath)
161
-
162
- // Check that it's valid in the file system.
163
- guard localFileSystem. isExecutableFile ( toolPath) else {
164
- throw InvalidToolchainDiagnostic ( " could not find \( toolName) at expected path \( toolPath. asString) " )
165
- }
166
- toolsPathCache [ toolName] = toolPath
163
+ _clangCompiler = toolPath
167
164
return toolPath
168
165
}
169
-
170
- /// Returns the path to llvm-cov tool.
171
- public func getClangCompiler( ) throws -> AbsolutePath {
172
- let clangToolName = " clang "
173
- let toolPath : AbsolutePath
174
-
175
- // Check in the environment variable first.
176
- if let value = UserToolchain . lookup ( variable: " CC " , searchPaths: envSearchPaths) {
177
- toolPath = value
178
- guard localFileSystem. isExecutableFile ( toolPath) else {
179
- throw InvalidToolchainDiagnostic ( " could not find clang at expected path \( toolPath. asString) " )
180
- }
181
- toolsPathCache [ clangToolName] = toolPath
182
- return toolPath
183
- }
184
-
185
- // Otherwise, just do a regular lookup.
186
- return try lookup ( tool: clangToolName)
187
- }
166
+ private var _clangCompiler : AbsolutePath ?
188
167
189
168
/// Returns the path to llvm-cov tool.
190
169
public func getLLVMCov( ) throws -> AbsolutePath {
191
- return try lookup ( tool: " llvm-cov " )
170
+ let toolPath = destination. binDir. appending ( component: " llvm-cov " )
171
+ guard localFileSystem. isExecutableFile ( toolPath) else {
172
+ throw InvalidToolchainDiagnostic ( " could not find llvm-cov at expected path \( toolPath. asString) " )
173
+ }
174
+ return toolPath
192
175
}
193
176
194
177
/// Returns the path to llvm-prof tool.
195
178
public func getLLVMProf( ) throws -> AbsolutePath {
196
- return try lookup ( tool: " llvm-profdata " )
179
+ let toolPath = destination. binDir. appending ( component: " llvm-profdata " )
180
+ guard localFileSystem. isExecutableFile ( toolPath) else {
181
+ throw InvalidToolchainDiagnostic ( " could not find llvm-profdata at expected path \( toolPath. asString) " )
182
+ }
183
+ return toolPath
197
184
}
198
185
199
186
public init ( destination: Destination , environment: [ String : String ] = Process . env) throws {
200
- self . toolsPathCache = [ : ]
201
187
self . destination = destination
202
188
self . processEnvironment = environment
203
189
0 commit comments