Skip to content

Commit d376a8b

Browse files
authored
Merge pull request #188 from Backbase/fix/dynamic-library-path-lookup
fix: inability to find 'Templates' folder when installing Variants with homebrew on Apple Silicon
2 parents 2ed45bb + 26c5a9a commit d376a8b

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

Sources/VariantsCore/Custom Types/TemplateDirectory.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,23 @@ struct TemplateDirectory {
1919
"./Templates"
2020
]
2121
) throws {
22-
let firstDirectory = directories
23-
.map(Path.init(stringLiteral:))
24-
.first(where: \.exists)
25-
26-
guard let path = firstDirectory else {
22+
23+
var templateDirectories = directories.map(Path.init(stringLiteral:))
24+
25+
if let variantsInstallationPath = try? Bash(
26+
"which",
27+
arguments: "variants"
28+
).capture() {
29+
templateDirectories.append(
30+
Path(variantsInstallationPath.replacingOccurrences(
31+
of: "/bin/variants",
32+
with: "/lib/variants/templates"
33+
))
34+
)
35+
}
36+
37+
let firstFoundDirectory = templateDirectories.first(where: \.exists)
38+
guard let path = firstFoundDirectory else {
2739
let dirs = directories.joined(separator: " or ")
2840
throw RuntimeError("Templates folder not found in \(dirs)")
2941
}

Sources/VariantsCore/Custom Types/UtilsDirectory.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@ struct UtilsDirectory {
1919
"./utils"
2020
]
2121
) throws {
22-
let firstDirectory = directories
23-
.map(Path.init(stringLiteral:))
24-
.first(where: \.exists)
25-
26-
guard let path = firstDirectory else {
22+
var utilsDirectories = directories.map(Path.init(stringLiteral:))
23+
24+
if let variantsInstallationPath = try? Bash(
25+
"which",
26+
arguments: "variants"
27+
).capture() {
28+
utilsDirectories.append(
29+
Path(variantsInstallationPath.replacingOccurrences(
30+
of: "/bin/variants",
31+
with: "/lib/variants/utils"
32+
))
33+
)
34+
}
35+
36+
let firstFoundDirectory = utilsDirectories.first(where: \.exists)
37+
guard let path = firstFoundDirectory else {
2738
let dirs = directories.joined(separator: " or ")
2839
throw RuntimeError("Utils folder not found in \(dirs)")
2940
}

0 commit comments

Comments
 (0)