|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | import Foundation
|
| 14 | +#if os(Windows) |
| 15 | +import WinSDK |
| 16 | +#endif |
14 | 17 |
|
15 | 18 | /// The set of commandline tools used to build a tibs project.
|
16 | 19 | public final class TibsToolchain {
|
@@ -86,7 +89,11 @@ public final class TibsToolchain {
|
86 | 89 | let fsec = Float(usec) / 1_000_000
|
87 | 90 | fputs("warning: waiting \(fsec) second\(fsec == 1.0 ? "" : "s") to ensure file timestamp " +
|
88 | 91 | "differs; \(reason)\n", stderr)
|
| 92 | +#if os(Windows) |
| 93 | + Sleep(usec / 1000) |
| 94 | +#else |
89 | 95 | usleep(usec)
|
| 96 | +#endif |
90 | 97 | }
|
91 | 98 | }
|
92 | 99 | }
|
@@ -168,15 +175,23 @@ extension TibsToolchain {
|
168 | 175 | public func findTool(name: String) -> URL? {
|
169 | 176 | #if os(macOS)
|
170 | 177 | 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] |
171 | 185 | #else
|
172 | 186 | let cmd = ["/usr/bin/which", name]
|
173 | 187 | #endif
|
174 | 188 |
|
175 | 189 | guard var path = try? Process.tibs_checkNonZeroExit(arguments: cmd) else {
|
176 | 190 | return nil
|
177 | 191 | }
|
178 |
| - if path.last == "\n" { |
179 |
| - path = String(path.dropLast()) |
180 |
| - } |
| 192 | +#if os(Windows) |
| 193 | + path = String((path.split { $0.isNewline })[0]) |
| 194 | +#endif |
| 195 | + path = path.trimmingCharacters(in: .whitespacesAndNewlines) |
181 | 196 | return URL(fileURLWithPath: path, isDirectory: false)
|
182 | 197 | }
|
0 commit comments