Skip to content

Commit c304c79

Browse files
committed
Fix missing Homebrew prefix resolution.
1 parent 57d4407 commit c304c79

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

utils/make-pkgconfig.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,21 @@ extension String: Error {
4646
}
4747

4848
func makeFile() throws {
49-
let pkgConfigPath = "/usr/local/lib/pkgconfig"
49+
guard let brew = which("brew") else { throw "Missing callable `brew` instance." }
50+
guard let brewPrefix = run(brew, args: ["--prefix"]) else { throw "Brew could not detect installation prefix location." }
51+
let pkgConfigPath = "\(brewPrefix)/lib/pkgconfig"
5052
let pkgConfigDir = URL(fileURLWithPath: pkgConfigPath)
5153

52-
// Make /usr/local/lib/pkgconfig if it doesn't already exist
54+
// Make <brew-prefix>/lib/pkgconfig if it doesn't already exist
5355
if !FileManager.default.fileExists(atPath: pkgConfigPath) {
5456
try FileManager.default.createDirectory(at: pkgConfigDir,
5557
withIntermediateDirectories: true)
5658
}
5759
let cllvmPath = pkgConfigDir.appendingPathComponent("cllvm.pc")
58-
59-
let brewLLVMConfig: () -> String? = {
60-
guard let brew = which("brew") else { return nil }
61-
guard let brewPrefix = run(brew, args: ["--prefix"]) else { return nil }
62-
return which(brewPrefix + "/opt/llvm/bin/llvm-config")
63-
}
60+
let brewLLVMConfig = which(brewPrefix + "/opt/llvm/bin/llvm-config")
6461

6562
/// Ensure we have llvm-config in the PATH
66-
guard let llvmConfig = which("llvm-config-11") ?? which("llvm-config") ?? brewLLVMConfig() else {
63+
guard let llvmConfig = which("llvm-config-11") ?? which("llvm-config") ?? brewLLVMConfig else {
6764
throw "Failed to find llvm-config. Ensure llvm-config is installed and " +
6865
"in your PATH"
6966
}

0 commit comments

Comments
 (0)