Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

highball tricks finds cabextract. The CLI's winetricks run set PATH to the engine and the system folders only, so every verb that shells out to cabextract (dotnet35, the core fonts) failed from the CLI while the same recipe step worked (found while answering db#941). The tool folders (the app's Resources/tools, or HIGHBALL_TOOLS) are now put in front by one helper both paths use. WinetricksWine tests pass (5). (#647)

Gauthier Piarrette7ecd0ef5b1f1
diff --git a/Sources/HighballKit/Recipe.swift b/Sources/HighballKit/Recipe.swift
index f554857..68f9c92 100644
--- a/Sources/HighballKit/Recipe.swift
+++ b/Sources/HighballKit/Recipe.swift
@@ -663,15 +663,8 @@ public struct RecipeRunner: Sendable {
env = joined
// The library paths reach winetricks' wine through a script, past bash (see WinetricksWine).
env = WinetricksWine.environment(env, wine: engine.wineBinary, script: try WinetricksWine.installScript(in: paths))
- // winetricks shells out to cabextract for Microsoft's cabinet installers (the core
- // fonts among them) and macOS does not ship it, so the app bundles one under
- // Resources/tools (highball#96). HIGHBALL_TOOLS names another directory, for the CLI.
- let tools = [ProcessInfo.processInfo.environment["HIGHBALL_TOOLS"].map { URL(fileURLWithPath: $0) },
- Bundle.main.resourceURL?.appending(path: "tools", directoryHint: .isDirectory)]
- .compactMap { $0 }.filter { FileManager.default.fileExists(atPath: $0.path) }
- if !tools.isEmpty {
- env["PATH"] = (tools.map(\.path) + [env["PATH"] ?? ProcessInfo.processInfo.environment["PATH"] ?? "/usr/bin:/bin"]).joined(separator: ":")
- }
+ // cabextract and the other tools winetricks shells out to (see WinetricksWine.pathWithTools).
+ env["PATH"] = WinetricksWine.pathWithTools(env["PATH"])
// Its own log, named like every other one in the folder. Without it the step was
// invisible: what winetricks said lived only in the error dialog's Details, so
// three reports of the core fonts failing came with a game's launch log attached
diff --git a/Sources/HighballKit/WinetricksWine.swift b/Sources/HighballKit/WinetricksWine.swift
index d036ff9..5d3978a 100644
--- a/Sources/HighballKit/WinetricksWine.swift
+++ b/Sources/HighballKit/WinetricksWine.swift
@@ -55,4 +55,17 @@ public enum WinetricksWine {
out["WINE"] = script.path
return out
}
+
+ /// `path` with Highball's tool folders in front. winetricks shells out to cabextract for
+ /// Microsoft's cabinet installers (the core fonts among them) and macOS does not ship it, so
+ /// the app bundles one under Resources/tools (highball#96). HIGHBALL_TOOLS names another
+ /// directory, for the CLI. Shared by recipes and `highball tricks`, whose PATH once lacked it
+ /// and failed every verb that needs cabextract (db#941).
+ public static func pathWithTools(_ path: String?) -> String? {
+ let tools = [ProcessInfo.processInfo.environment["HIGHBALL_TOOLS"].map { URL(fileURLWithPath: $0) },
+ Bundle.main.resourceURL?.appending(path: "tools", directoryHint: .isDirectory)]
+ .compactMap { $0 }.filter { FileManager.default.fileExists(atPath: $0.path) }
+ guard !tools.isEmpty else { return path }
+ return (tools.map(\.path) + [path ?? ProcessInfo.processInfo.environment["PATH"] ?? "/usr/bin:/bin"]).joined(separator: ":")
+ }
}
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index 632ca0f..174000d 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -540,7 +540,7 @@ struct Tricks: AsyncParsableCommand {
env["WINESERVER_BIN"] = eng.wineserverBinary.path
env["WINE_BINDIR"] = eng.wineBinary.deletingLastPathComponent().path
env["WINESERVER"] = eng.wineserverBinary.path
- env["PATH"] = "\(eng.engineDir.appending(path: "bin").path):/usr/bin:/bin:/usr/sbin:/sbin"
+ env["PATH"] = WinetricksWine.pathWithTools("\(eng.engineDir.appending(path: "bin").path):/usr/bin:/bin:/usr/sbin:/sbin")
// bash, as the recipe path runs it (winetricks' macOS guidance). bash drops the DYLD vars
// under SIP like sh does, so they reach wine through WinetricksWine's script.
env = WinetricksWine.environment(env, wine: eng.wineBinary, script: try WinetricksWine.installScript(in: HighballPaths()))
diff --git a/Tests/HighballKitTests/WinetricksWineTests.swift b/Tests/HighballKitTests/WinetricksWineTests.swift
index 764f943..3a2c930 100644
--- a/Tests/HighballKitTests/WinetricksWineTests.swift
+++ b/Tests/HighballKitTests/WinetricksWineTests.swift
@@ -45,6 +45,23 @@ final class WinetricksWineTests: XCTestCase {
XCTAssertEqual(out.trimmingCharacters(in: .whitespacesAndNewlines), "wine got: cmd.exe /c echo %AppData%")
}
+ /// `highball tricks` built its PATH from the engine and the system folders only, so a verb that
+ /// shells out to cabextract failed from the CLI while the same recipe step worked (db#941).
+ func testToolFoldersGoInFrontOfThePathBothCallersGive() throws {
+ let tools = FileManager.default.temporaryDirectory.appending(path: "hb-tools-\(UUID().uuidString)", directoryHint: .isDirectory)
+ try FileManager.default.createDirectory(at: tools, withIntermediateDirectories: true)
+ defer { try? FileManager.default.removeItem(at: tools); unsetenv("HIGHBALL_TOOLS") }
+ let engineBin = "/engines/e/engine/bin:/usr/bin:/bin"
+ unsetenv("HIGHBALL_TOOLS")
+ let without = WinetricksWine.pathWithTools(engineBin)
+ XCTAssertTrue(without?.hasSuffix(engineBin) == true)
+ setenv("HIGHBALL_TOOLS", tools.path, 1)
+ XCTAssertEqual(WinetricksWine.pathWithTools(engineBin)?.split(separator: ":").first.map(String.init), tools.path)
+ XCTAssertTrue(WinetricksWine.pathWithTools(engineBin)?.hasSuffix(engineBin) == true, "the engine's folders stay")
+ setenv("HIGHBALL_TOOLS", tools.appending(path: "missing").path, 1)
+ XCTAssertEqual(WinetricksWine.pathWithTools(engineBin), without, "a folder that is not there is not added")
+ }
+
private func run(_ args: [String], env: [String: String]) throws -> String {
let p = Process()
p.executableURL = URL(fileURLWithPath: "/bin/sh")