Skip to content

Commit 2015bb2

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 c6a437e commit 2015bb2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Sources/ISDBTibs/TibsToolchain.swift

Lines changed: 20 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 {
@@ -78,7 +81,11 @@ public final class TibsToolchain {
7881
let fsec = Float(usec) / 1_000_000
7982
fputs("warning: waiting \(fsec) second\(fsec == 1.0 ? "" : "s") to ensure file timestamp " +
8083
"differs; \(reason)\n", stderr)
84+
#if os(Windows)
85+
Sleep(usec / 1000)
86+
#else
8187
usleep(usec)
88+
#endif
8289
}
8390
}
8491
}
@@ -160,15 +167,28 @@ extension TibsToolchain {
160167
public func findTool(name: String) -> URL? {
161168
#if os(macOS)
162169
let cmd = ["/usr/bin/xcrun", "--find", name]
170+
#elseif os(Windows)
171+
var buf = [WCHAR](repeating: 0, count: Int(MAX_PATH))
172+
GetWindowsDirectoryW(&buf, DWORD(MAX_PATH))
173+
let foo = DWORD(0)
174+
var wherePath = String(decodingCString: &buf, as: UTF16.self)
175+
.appendingPathComponent("system32")
176+
.appendingPathComponent("where.exe")
177+
let cmd = [wherePath, name]
163178
#else
164179
let cmd = ["/usr/bin/which", name]
165180
#endif
166181

167182
guard var path = try? Process.tibs_checkNonZeroExit(arguments: cmd) else {
168183
return nil
169184
}
185+
#if os(Windows)
186+
let paths = path.split { $0.isNewline }
187+
path = String(paths[0]).trimmingCharacters(in: .whitespacesAndNewlines)
188+
#else
170189
if path.last == "\n" {
171190
path = String(path.dropLast())
172191
}
192+
#endif
173193
return URL(fileURLWithPath: path, isDirectory: false)
174194
}

0 commit comments

Comments
 (0)