Skip to content

Commit ca22dde

Browse files
Merge pull request #230 from eonil/master
Fix missing Homebrew prefix resolution. Use `brew --prefix` to derive `pkgConfigPath` if `brew` is installed.
2 parents 57d4407 + 0dd578d commit ca22dde

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: utils/make-pkgconfig.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ extension String: Error {
4646
}
4747

4848
func makeFile() throws {
49-
let pkgConfigPath = "/usr/local/lib/pkgconfig"
49+
let brewPrefix = {
50+
guard let brew = which("brew") else { return nil }
51+
return run(brew, args: ["--prefix"])
52+
}() ?? "/usr/local"
53+
54+
let pkgConfigPath = "\(brewPrefix)/lib/pkgconfig"
5055
let pkgConfigDir = URL(fileURLWithPath: pkgConfigPath)
5156

52-
// Make /usr/local/lib/pkgconfig if it doesn't already exist
57+
// Make <brew-prefix>/lib/pkgconfig if it doesn't already exist
5358
if !FileManager.default.fileExists(atPath: pkgConfigPath) {
5459
try FileManager.default.createDirectory(at: pkgConfigDir,
5560
withIntermediateDirectories: true)
5661
}
5762
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-
}
63+
let brewLLVMConfig = { which("\(brewPrefix)/opt/llvm/bin/llvm-config") }
6464

6565
/// Ensure we have llvm-config in the PATH
6666
guard let llvmConfig = which("llvm-config-11") ?? which("llvm-config") ?? brewLLVMConfig() else {

0 commit comments

Comments
 (0)