Skip to content

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

A failed first Windows setup leaves what Wine had in its log, and a damaged engine gets 'Install the engine again' instead of a Repair that repeats the failure

Gauthier Piarrette1975cc144968
diff --git a/Sources/HighballKit/BottleStore.swift b/Sources/HighballKit/BottleStore.swift
index aaf8cf6..288f83a 100644
--- a/Sources/HighballKit/BottleStore.swift
+++ b/Sources/HighballKit/BottleStore.swift
@@ -113,7 +113,16 @@ public struct BottleStore: Sendable {
// says ready over an environment that never booted).
guard result.exitStatus == 0 else {
try? runner.kill()
+ // The half-made environment is deleted below, so what Wine could and couldn't reach
+ // goes into the log first: the first-boot failures in highball#547 and #446 arrived
+ // as three lines and exit 53 with nothing to tell a damaged engine from a path Wine
+ // can't express. "could not load kernel32.dll" names no file the way import_dll lines
+ // do, so the engine's own builtins are checked here too, and a damaged engine gets
+ // the reinstall that fixes it (#118, #37) instead of a Repair that runs the same step.
+ let missing = EngineIntegrity.gone(fromEngineAt: engine.root, notFound: EngineIntegrity.builtins.sorted(), arch: engine.manifest.arch)
+ Self.appendLines(Self.setupDiagnostics(bottle: url, engine: engine, home: paths.home, missing: missing), to: result.log)
_ = try? discard(url, name: name)
+ if !missing.isEmpty { throw HighballError.engineDamaged(engine: engine.id, files: missing) }
throw HighballError.processFailed(command: "wineboot -u", status: result.exitStatus, output: "see \(result.log.path)")
}
if Task.isCancelled {
@@ -139,6 +148,38 @@ public struct BottleStore: Sendable {
return bottle
}
+ /// What a failed first boot leaves in its log before the environment is removed: where the
+ /// prefix's C: and Z: drives point, whether Highball's folder resolves elsewhere, a path Wine
+ /// can't express, the engine's missing builtins, the free space on that volume, and the names
+ /// (never the values) of WINE and DYLD variables the app inherited and passes on to Wine.
+ static func setupDiagnostics(bottle: URL, engine: InstalledEngine, home: URL, missing: [String],
+ environment: [String: String] = ProcessInfo.processInfo.environment) -> [String] {
+ let fm = FileManager.default
+ func target(_ drive: String) -> String {
+ let link = bottle.appending(path: "dosdevices/\(drive)").path
+ return (try? fm.destinationOfSymbolicLink(atPath: link)) ?? "missing"
+ }
+ var lines = ["# setup failed, what Wine had to work with:",
+ "# dosdevices c: -> \(target("c:")), z: -> \(target("z:"))"]
+ let resolved = home.resolvingSymlinksInPath().path
+ lines.append(resolved == home.path ? "# home \(home.path)" : "# home \(home.path), resolves to \(resolved)")
+ if let why = HighballPaths.windowsPathProblem(home) { lines.append("# path problem: \(why)") }
+ lines.append("# engine \(engine.id) builtins missing: \(missing.isEmpty ? "none" : missing.joined(separator: ", "))")
+ if let free = (try? home.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey]))?.volumeAvailableCapacityForImportantUsage {
+ lines.append("# free on that volume: \(free >> 30) GB")
+ }
+ let inherited = environment.keys.filter { $0.hasPrefix("WINE") || $0.hasPrefix("DYLD") }.sorted()
+ lines.append("# inherited WINE and DYLD variables: \(inherited.isEmpty ? "none" : inherited.joined(separator: ", "))")
+ return lines
+ }
+
+ static func appendLines(_ lines: [String], to log: URL) {
+ guard let handle = try? FileHandle(forWritingTo: log) else { return }
+ defer { try? handle.close() }
+ _ = try? handle.seekToEnd()
+ try? handle.write(contentsOf: Data((lines.joined(separator: "\n") + "\n").utf8))
+ }
+
/// True when the prefix's 32-bit half is missing, the state issue #37 users found only when an
/// installer died with "could not load kernel32.dll". Checked before every launch.
public static func needsPreflightRepair(_ bottle: Bottle) -> Bool {
diff --git a/Tests/HighballKitTests/HomeLocationTests.swift b/Tests/HighballKitTests/HomeLocationTests.swift
index 07d5c2a..b9d2336 100644
--- a/Tests/HighballKitTests/HomeLocationTests.swift
+++ b/Tests/HighballKitTests/HomeLocationTests.swift
@@ -71,6 +71,26 @@ final class HomeLocationTests: XCTestCase {
XCTAssertFalse(FileManager.default.fileExists(atPath: paths.bottle("Games").path), "nothing is made")
}
+ // A failed first boot deletes the half-made environment, so its log keeps what Wine had:
+ // drive links, the home and how it resolves, missing builtins, free space, and only the
+ // names of inherited WINE and DYLD variables (highball#547, #446).
+ func testSetupDiagnosticsNameWhatWineHad() throws {
+ let bottle = tmp.appending(path: "bottles/Games", directoryHint: .isDirectory)
+ try FileManager.default.createDirectory(at: bottle.appending(path: "dosdevices"), withIntermediateDirectories: true)
+ try FileManager.default.createSymbolicLink(atPath: bottle.appending(path: "dosdevices/z:").path, withDestinationPath: "/")
+ let json = #"{"id":"x64-a-r1","displayName":"e","arch":"x86_64","minMacOS":"14.0","components":{}}"#
+ let engine = InstalledEngine(manifest: try JSONDecoder().decode(EngineManifest.self, from: Data(json.utf8)),
+ root: tmp.appending(path: "engine"))
+ let lines = BottleStore.setupDiagnostics(bottle: bottle, engine: engine, home: tmp, missing: ["kernel32.dll"],
+ environment: ["WINEDEBUG": "+all", "DYLD_LIBRARY_PATH": "/secret", "HOME": "/Users/x"])
+ let text = lines.joined(separator: "\n")
+ XCTAssertTrue(text.contains("c: -> missing, z: -> /"), text)
+ XCTAssertTrue(text.contains("builtins missing: kernel32.dll"), text)
+ XCTAssertTrue(text.contains("DYLD_LIBRARY_PATH, WINEDEBUG"), text)
+ XCTAssertFalse(text.contains("/secret"), "variable values stay out of the log")
+ XCTAssertFalse(text.contains("HOME"), "only WINE and DYLD names are listed")
+ }
+
// The volume check asks the volume instead of trusting a name. The old check read
// volumeSupportsSymbolicLinks and refused exFAT by name, but macOS reports exFAT as supporting
// symbolic links and creates them, so it never fired and the promised refusal never happened