Skip to content

Commit 6bf7e9a

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 c045a1f commit 6bf7e9a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Sources/ISDBTibs/TibsToolchain.swift

Lines changed: 21 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 {
@@ -99,7 +102,11 @@ public final class TibsToolchain {
99102
let fsec = Float(usec) / 1_000_000
100103
fputs("warning: waiting \(fsec) second\(fsec == 1.0 ? "" : "s") to ensure file timestamp " +
101104
"differs; \(reason)\n", stderr)
105+
#if os(Windows)
106+
Sleep(usec / 1000)
107+
#else
102108
usleep(usec)
109+
#endif
103110
}
104111
}
105112
}
@@ -183,6 +190,15 @@ public func findTool(name: String) -> URL? {
183190
#if os(macOS)
184191
p.launchPath = "/usr/bin/xcrun"
185192
p.arguments = ["--find", name]
193+
#elseif os(Windows)
194+
var buf = [WCHAR](repeating: 0, count: Int(MAX_PATH))
195+
GetWindowsDirectoryW(&buf, DWORD(MAX_PATH))
196+
let foo = DWORD(0)
197+
var wherePath = String(decodingCString: &buf, as: UTF16.self)
198+
.appendingPathComponent("system32")
199+
.appendingPathComponent("where.exe")
200+
p.launchPath = wherePath
201+
p.arguments = [name]
186202
#else
187203
p.launchPath = "/usr/bin/which"
188204
p.arguments = [name]
@@ -201,8 +217,13 @@ public func findTool(name: String) -> URL? {
201217
guard var path = String(data: data, encoding: .utf8) else {
202218
return nil
203219
}
220+
#if os(Windows)
221+
let paths = path.split { $0.isNewline }
222+
path = String(paths[0]).trimmingCharacters(in: .whitespacesAndNewlines)
223+
#else
204224
if path.last == "\n" {
205225
path = String(path.dropLast())
206226
}
227+
#endif
207228
return URL(fileURLWithPath: path)
208229
}

0 commit comments

Comments
 (0)