|
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 {
|
@@ -78,7 +81,11 @@ public final class TibsToolchain {
|
78 | 81 | let fsec = Float(usec) / 1_000_000
|
79 | 82 | fputs("warning: waiting \(fsec) second\(fsec == 1.0 ? "" : "s") to ensure file timestamp " +
|
80 | 83 | "differs; \(reason)\n", stderr)
|
| 84 | +#if os(Windows) |
| 85 | + Sleep(usec / 1000) |
| 86 | +#else |
81 | 87 | usleep(usec)
|
| 88 | +#endif |
82 | 89 | }
|
83 | 90 | }
|
84 | 91 | }
|
@@ -160,15 +167,28 @@ extension TibsToolchain {
|
160 | 167 | public func findTool(name: String) -> URL? {
|
161 | 168 | #if os(macOS)
|
162 | 169 | 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] |
163 | 178 | #else
|
164 | 179 | let cmd = ["/usr/bin/which", name]
|
165 | 180 | #endif
|
166 | 181 |
|
167 | 182 | guard var path = try? Process.tibs_checkNonZeroExit(arguments: cmd) else {
|
168 | 183 | return nil
|
169 | 184 | }
|
| 185 | +#if os(Windows) |
| 186 | + let paths = path.split { $0.isNewline } |
| 187 | + path = String(paths[0]).trimmingCharacters(in: .whitespacesAndNewlines) |
| 188 | +#else |
170 | 189 | if path.last == "\n" {
|
171 | 190 | path = String(path.dropLast())
|
172 | 191 | }
|
| 192 | +#endif |
173 | 193 | return URL(fileURLWithPath: path, isDirectory: false)
|
174 | 194 | }
|
0 commit comments