Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push logic into findFiles #2368

Merged
merged 2 commits into from
Aug 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/app/Fake.Core.Process/ProcessUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module ProcessUtils =

/// Searches the given directories for all occurrences of the given file name
/// [omit]
let findFiles dirs file =
let private findFilesInternal dirs file =
let files =
dirs
|> Seq.map (fun (path : string) ->
Expand All @@ -35,6 +35,18 @@ module ProcessUtils =
|> Seq.cache
files

/// Searches the given directories for all occurrences of the given file name, on windows PATHEXT is considered (and preferred when searching)
let findFiles dirs file =
// See https://unix.stackexchange.com/questions/280528/is-there-a-unix-equivalent-of-the-windows-environment-variable-pathext
if Environment.isWindows then
// Prefer PATHEXT, see https://github.com/fsharp/FAKE/issues/1911
// and https://github.com/fsharp/FAKE/issues/1899
Environment.environVarOrDefault "PATHEXT" ".COM;.EXE;.BAT"
|> String.split ';'
|> Seq.collect (fun postFix -> findFilesInternal dirs (file + postFix))
|> fun findings -> Seq.append findings (findFilesInternal dirs file)
else findFilesInternal dirs file

/// Searches the given directories for all occurrences of the given file name
/// [omit]
let tryFindFile dirs file =
Expand All @@ -54,16 +66,7 @@ module ProcessUtils =
Environment.pathDirectories
|> Seq.filter Path.isValidPath
|> Seq.append [ "." ]
|> fun path ->
// See https://unix.stackexchange.com/questions/280528/is-there-a-unix-equivalent-of-the-windows-environment-variable-pathext
if Environment.isWindows then
// Prefer PATHEXT, see https://github.com/fsharp/FAKE/issues/1911
// and https://github.com/fsharp/FAKE/issues/1899
Environment.environVarOrDefault "PATHEXT" ".COM;.EXE;.BAT"
|> String.split ';'
|> Seq.collect (fun postFix -> findFiles path (file + postFix))
|> fun findings -> Seq.append findings (findFiles path file)
else findFiles path file
|> fun dirs -> findFiles dirs file

/// Searches the current directory and the directories within the PATH
/// environment variable for the given file. If successful returns the full
Expand Down Expand Up @@ -92,4 +95,4 @@ module ProcessUtils =
let findPath fallbackValue tool =
match tryFindPath fallbackValue tool with
| Some file -> file
| None -> tool
| None -> tool