Skip to content

Commit 1168dea

Browse files
committed
Implement functions to depress warnings
1 parent 660a709 commit 1168dea

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Sources/SwiftDriver/Driver/Driver.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ extension Driver {
744744
///
745745
/// - Parameter content: response file's content to be tokenized.
746746
private static func tokenizeResponseFile(_ content: String) -> [String] {
747-
#if !os(macOS) && !os(Linux) && !os(Android)
747+
#if !os(macOS) && !os(Linux) && !os(Android) && !os(Windows)
748748
#warning("Response file tokenization unimplemented for platform; behavior may be incorrect")
749749
#endif
750750
return content.split { $0 == "\n" || $0 == "\r\n" }

Sources/SwiftDriver/Utilities/System.swift

+21
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#if os(macOS)
1414
import Darwin
15+
#elseif os(Windows)
16+
import WinSDK.core.file
1517
#elseif canImport(Glibc)
1618
import Glibc
1719
#endif
@@ -46,6 +48,25 @@ func commandLineFitsWithinSystemLimits(path: String, args: [String]) -> Bool {
4648
}
4749
return commandLineLength < effectiveArgMax
4850
}
51+
#elseif os(Windows)
52+
// See: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
53+
func commandLineFitsWithinSystemLimits(path: String, args: [String]) -> Bool {
54+
// Known limit for all CreateProcess APIs
55+
guard path.utf8.count + args.map(\.utf8.count).reduce(0, +) < 32_767 else {
56+
return false
57+
}
58+
59+
// Path component length limit for Unicode APIs
60+
var length: UInt32 = 0
61+
withUnsafeMutablePointer(to: &length) { ptr -> Void in
62+
GetVolumeInformationA(nil, nil, 0, nil, ptr, nil, nil, 0)
63+
}
64+
guard path.split(separator: "\\").reduce(true, { result, component in
65+
result && component.utf8.count < length
66+
}) else { return false }
67+
68+
return true
69+
}
4970
#else
5071
func commandLineFitsWithinSystemLimits(path: String, args: [String]) -> Bool {
5172
#warning("missing implementation for current platform")

0 commit comments

Comments
 (0)