Skip to content

Commit

Permalink
Merge pull request #2368 from fsharp/matthid-patch-1
Browse files Browse the repository at this point in the history
Push logic into findFiles
  • Loading branch information
matthid authored Aug 17, 2019
2 parents 64d5c19 + 5058b04 commit 86240f2
Showing 1 changed file with 15 additions and 12 deletions.
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

0 comments on commit 86240f2

Please sign in to comment.