Skip to content

Commit f550367

Browse files
committed
Use where.exe on Windows instead of which
Windows (without msys) doesn't have where, instead, use the native which to locate tools.
1 parent 13882c7 commit f550367

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Sources/ISDBTibs/TibsToolchain.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Foundation
14+
#if os(Windows)
15+
import WinSDK
16+
#endif
1417

1518
/// The set of commandline tools used to build a tibs project.
1619
public final class TibsToolchain {
@@ -86,7 +89,11 @@ public final class TibsToolchain {
8689
let fsec = Float(usec) / 1_000_000
8790
fputs("warning: waiting \(fsec) second\(fsec == 1.0 ? "" : "s") to ensure file timestamp " +
8891
"differs; \(reason)\n", stderr)
92+
#if os(Windows)
93+
Sleep(usec / 1000)
94+
#else
8995
usleep(usec)
96+
#endif
9097
}
9198
}
9299
}
@@ -168,15 +175,27 @@ extension TibsToolchain {
168175
public func findTool(name: String) -> URL? {
169176
#if os(macOS)
170177
let cmd = ["/usr/bin/xcrun", "--find", name]
178+
#elseif os(Windows)
179+
var buf = [WCHAR](repeating: 0, count: Int(MAX_PATH))
180+
GetWindowsDirectoryW(&buf, DWORD(MAX_PATH))
181+
var wherePath = String(decodingCString: &buf, as: UTF16.self)
182+
.appendingPathComponent("system32")
183+
.appendingPathComponent("where.exe")
184+
let cmd = [wherePath, name]
171185
#else
172186
let cmd = ["/usr/bin/which", name]
173187
#endif
174188

175189
guard var path = try? Process.tibs_checkNonZeroExit(arguments: cmd) else {
176190
return nil
177191
}
192+
#if os(Windows)
193+
let paths = path.split { $0.isNewline }
194+
path = String(paths[0]).trimmingCharacters(in: .whitespacesAndNewlines)
195+
#else
178196
if path.last == "\n" {
179197
path = String(path.dropLast())
180198
}
199+
#endif
181200
return URL(fileURLWithPath: path, isDirectory: false)
182201
}

0 commit comments

Comments
 (0)