Skip to content

Commit 4f5aeee

Browse files
committed
Find executables in Windows system paths
1 parent 66889f0 commit 4f5aeee

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import class Foundation.ProcessInfo
1212

1313
#if os(Windows)
1414
import Foundation
15+
import WinSDK.core.sysinfo
1516
#endif
1617

1718
@_implementationOnly import TSCclibc
@@ -324,9 +325,28 @@ public final class Process: ObjectIdentifierProtocol {
324325
pathString: ProcessEnv.path,
325326
currentWorkingDirectory: localFileSystem.currentWorkingDirectory
326327
)
328+
#if os(Windows)
329+
var searchPaths = [String]()
330+
let buffer = UnsafeMutablePointer<String>.allocate(capacity: 260)
331+
332+
// The 32-bit Windows system directory
333+
GetSystemDirectoryW(buffer, 260)
334+
searchPaths += buffer.pointee
335+
336+
// The 16-bit Windows system directory
337+
searchPaths += "\(ProcessEnv.vars["systemdrive"] ?? "C:")\\System"
338+
339+
// The Windows directory
340+
GetWindowsDirectoryW(buffer, 260)
341+
searchPaths += buffer.pointee
342+
343+
searchPaths.append(contentsOf: envSearchPaths)
344+
#else
345+
let searchPaths = envSearchPaths
346+
#endif
327347
// Lookup and cache the executable path.
328348
let value = lookupExecutablePath(
329-
filename: program, searchPaths: envSearchPaths)
349+
filename: program, searchPaths: searchPaths)
330350
Process.validatedExecutablesMap[program] = value
331351
return value
332352
}

0 commit comments

Comments
 (0)