Skip to content

Commit

Permalink
Address feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Dec 7, 2021
1 parent 0866f42 commit c8885fa
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions Sources/TSCBasic/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,35 +351,30 @@ public final class Process {
pathString: ProcessEnv.path,
currentWorkingDirectory: cwdOpt
)
var searchPaths: [AbsolutePath] = []
#if os(Windows)
var searchPaths = Array<AbsolutePath>()
var buffer = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))

// The 32-bit Windows system directory
GetSystemDirectoryW(&buffer, .init(MAX_PATH + 1))
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))

if GetSystemDirectoryW(&buffer, buffer.count) > 0 {
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
}
// The 16-bit Windows system directory
if let systemDrive = ProcessEnv.vars["systemdrive"],
let systemPath = try? AbsolutePath(validating: "\(systemDrive))\\System") {
searchPaths.append(systemPath)
}

// The Windows directory
GetWindowsDirectoryW(&buffer, .init(MAX_PATH + 1))
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))

searchPaths.append(contentsOf: envSearchPaths)
#else
let searchPaths = envSearchPaths
if GetWindowsDirectoryW(&buffer, buffer.count) > 0 {
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
}
#endif
searchPaths.append(contentsOf: envSearchPaths)
// Lookup and cache the executable path.
let value = lookupExecutablePath(
filename: program,
currentWorkingDirectory: cwdOpt,
searchPaths: searchPaths
)
Process.validatedExecutablesMap[program] = value
return value
}
// This should cover the most common cases, i.e. when the cache is most helpful.
Expand Down

0 comments on commit c8885fa

Please sign in to comment.