Skip to content

Commit 03cfd34

Browse files
committed
[Commands] Store path to clang compiler after lookup
<rdar://problem/42590491> SwiftPM shouldn't lookup clang on every getClangCompiler() invocation
1 parent 24bef33 commit 03cfd34

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/Commands/UserToolchain.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ private struct UserManifestResources: ManifestResourceProvider {
3030
}
3131

3232
// FIXME: This is messy and needs a redesign.
33-
public struct UserToolchain: Toolchain {
33+
public final class UserToolchain: Toolchain {
3434

3535
/// The manifest resource provider.
3636
public let manifestResources: ManifestResourceProvider
3737

3838
/// Path of the `swiftc` compiler.
3939
public let swiftCompiler: AbsolutePath
4040

41+
/// Storage for clang compiler path.
42+
private var _clangCompiler: AbsolutePath?
43+
4144
public let extraCCFlags: [String]
4245

4346
public let extraSwiftCFlags: [String]
@@ -128,6 +131,10 @@ public struct UserToolchain: Toolchain {
128131

129132
public func getClangCompiler() throws -> AbsolutePath {
130133

134+
if let clangCompiler = _clangCompiler {
135+
return clangCompiler
136+
}
137+
131138
let clangCompiler: AbsolutePath
132139

133140
// Find the Clang compiler, looking first in the environment.
@@ -146,6 +153,7 @@ public struct UserToolchain: Toolchain {
146153
guard localFileSystem.isExecutableFile(clangCompiler) else {
147154
throw Error.invalidToolchain(problem: "could not find `clang` at expected path \(clangCompiler.asString)")
148155
}
156+
_clangCompiler = clangCompiler
149157
return clangCompiler
150158
}
151159

0 commit comments

Comments
 (0)