Skip to content

Commit

Permalink
Respect default search paths on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Dec 7, 2021
1 parent 90ec47d commit dab60f0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Sources/TSCBasic/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import var Foundation.NSLocalizedDescriptionKey

#if os(Windows)
import Foundation
import WinSDK
#endif

@_implementationOnly import TSCclibc
Expand Down Expand Up @@ -350,10 +351,26 @@ public final class Process {
pathString: ProcessEnv.path,
currentWorkingDirectory: cwdOpt
)
var searchPaths: [AbsolutePath] = []
#if os(Windows)
var buffer = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))
// The 32-bit Windows system directory
if GetSystemDirectoryW(&buffer, .init(buffer.count)) > 0 {
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
}
if GetWindowsDirectoryW(&buffer, .init(buffer.count)) > 0 {
let windowsDirectory = String(decodingCString: buffer, as: UTF16.self)
// The 16-bit Windows system directory
searchPaths.append(AbsolutePath("\(windowsDirectory)\\System"))
// The Windows directory
searchPaths.append(AbsolutePath(windowsDirectory))
}
#endif
searchPaths.append(contentsOf: envSearchPaths)
let value = lookupExecutablePath(
filename: program,
currentWorkingDirectory: cwdOpt,
searchPaths: envSearchPaths
searchPaths: searchPaths
)
return value
}
Expand Down

0 comments on commit dab60f0

Please sign in to comment.