Skip to content

Commit

Permalink
Implement commandLineFitsWithinSystemLimits and `tokenizeResponseFi…
Browse files Browse the repository at this point in the history
…le` for Windows
  • Loading branch information
stevapple committed Dec 19, 2020
1 parent 660a709 commit 59019ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ extension Driver {
///
/// - Parameter content: response file's content to be tokenized.
private static func tokenizeResponseFile(_ content: String) -> [String] {
#if !os(macOS) && !os(Linux) && !os(Android)
#if !os(macOS) && !os(Linux) && !os(Android) && !os(Windows)
#warning("Response file tokenization unimplemented for platform; behavior may be incorrect")
#endif
return content.split { $0 == "\n" || $0 == "\r\n" }
Expand Down
21 changes: 21 additions & 0 deletions Sources/SwiftDriver/Utilities/System.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#if os(macOS)
import Darwin
#elseif os(Windows)
import WinSDK.core.file
#elseif canImport(Glibc)
import Glibc
#endif
Expand Down Expand Up @@ -46,6 +48,25 @@ func commandLineFitsWithinSystemLimits(path: String, args: [String]) -> Bool {
}
return commandLineLength < effectiveArgMax
}
#elseif os(Windows)
// See: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
func commandLineFitsWithinSystemLimits(path: String, args: [String]) -> Bool {
// Known limit for all CreateProcess APIs.
guard path.utf8.count + args.map(\.count).reduce(0, +) < 32_767 else {
return false
}

// Path component length limit for Unicode APIs.
var length: UInt32 = 0
withUnsafeMutablePointer(to: &length) { ptr -> Void in
GetVolumeInformationA(nil, nil, 0, nil, ptr, nil, nil, 0)
}
guard path.split(separator: "\\").reduce(true, { result, component in
result && component.utf8.count < length
}) else { return false }

return true
}
#else
func commandLineFitsWithinSystemLimits(path: String, args: [String]) -> Bool {
#warning("missing implementation for current platform")
Expand Down

0 comments on commit 59019ff

Please sign in to comment.