Skip to content

Commit 2514377

Browse files
committed
[Build] Cache result of SDK path lookup, on OS X.
- Good for a 35% speedup in SwiftPM null build of itself.
1 parent faf0d48 commit 2514377

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Sources/Build/misc.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ public protocol Toolchain {
2424
}
2525

2626
func platformFrameworksPath() throws -> String {
27-
guard let popened = try? POSIX.popen(["xcrun", "--sdk", "macosx", "--show-sdk-platform-path"]),
28-
let chuzzled = popened.chuzzle() else {
29-
throw Error.InvalidPlatformPath
27+
// Lazily compute the platform the first time it is needed.
28+
struct Static {
29+
static let value = { try? POSIX.popen(["xcrun", "--sdk", "macosx", "--show-sdk-platform-path"]) }()
30+
}
31+
guard let popened = Static.value, let chuzzled = popened.chuzzle() else {
32+
throw Error.InvalidPlatformPath
3033
}
3134
return Path.join(chuzzled, "Developer/Library/Frameworks")
3235
}

0 commit comments

Comments
 (0)