From b1e5ef9fe6cec868b505a351a8e4666860f59ba2 Mon Sep 17 00:00:00 2001 From: stevapple Date: Sat, 19 Dec 2020 15:11:05 +0800 Subject: [PATCH] Implement functions to depress warnings --- Sources/SwiftDriver/Driver/Driver.swift | 2 +- Sources/SwiftDriver/Utilities/System.swift | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftDriver/Driver/Driver.swift b/Sources/SwiftDriver/Driver/Driver.swift index e832a353b..93f5750f4 100644 --- a/Sources/SwiftDriver/Driver/Driver.swift +++ b/Sources/SwiftDriver/Driver/Driver.swift @@ -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" } diff --git a/Sources/SwiftDriver/Utilities/System.swift b/Sources/SwiftDriver/Utilities/System.swift index dc2159272..3b4ad26eb 100644 --- a/Sources/SwiftDriver/Utilities/System.swift +++ b/Sources/SwiftDriver/Utilities/System.swift @@ -12,6 +12,8 @@ #if os(macOS) import Darwin +#elseif os(Windows) +import WinSDK.core.file #elseif canImport(Glibc) import Glibc #endif @@ -46,6 +48,26 @@ 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 + 1) + args.map({ $0.utf8.count + 1 }).reduce(0, +) < 32_767 else { + return false + } + + // Path component length limit for Unicode APIs + var maxComponentLength: UInt32 = 0 + withUnsafeMutablePointer(to: &maxComponentLength) { ptr -> Void in + GetVolumeInformationA(nil, nil, 0, nil, ptr, nil, nil, 0) + } + for component in path.split(separator: #"\"#) + where component.utf8.count < maxComponentLength { + return false + } + + return true +} #else func commandLineFitsWithinSystemLimits(path: String, args: [String]) -> Bool { #warning("missing implementation for current platform")