Skip to content

Commit 86240f2

Browse files
authored
Merge pull request #2368 from fsharp/matthid-patch-1
Push logic into findFiles
2 parents 64d5c19 + 5058b04 commit 86240f2

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/app/Fake.Core.Process/ProcessUtils.fs

+15-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module ProcessUtils =
1010

1111
/// Searches the given directories for all occurrences of the given file name
1212
/// [omit]
13-
let findFiles dirs file =
13+
let private findFilesInternal dirs file =
1414
let files =
1515
dirs
1616
|> Seq.map (fun (path : string) ->
@@ -35,6 +35,18 @@ module ProcessUtils =
3535
|> Seq.cache
3636
files
3737

38+
/// Searches the given directories for all occurrences of the given file name, on windows PATHEXT is considered (and preferred when searching)
39+
let findFiles dirs file =
40+
// See https://unix.stackexchange.com/questions/280528/is-there-a-unix-equivalent-of-the-windows-environment-variable-pathext
41+
if Environment.isWindows then
42+
// Prefer PATHEXT, see https://github.com/fsharp/FAKE/issues/1911
43+
// and https://github.com/fsharp/FAKE/issues/1899
44+
Environment.environVarOrDefault "PATHEXT" ".COM;.EXE;.BAT"
45+
|> String.split ';'
46+
|> Seq.collect (fun postFix -> findFilesInternal dirs (file + postFix))
47+
|> fun findings -> Seq.append findings (findFilesInternal dirs file)
48+
else findFilesInternal dirs file
49+
3850
/// Searches the given directories for all occurrences of the given file name
3951
/// [omit]
4052
let tryFindFile dirs file =
@@ -54,16 +66,7 @@ module ProcessUtils =
5466
Environment.pathDirectories
5567
|> Seq.filter Path.isValidPath
5668
|> Seq.append [ "." ]
57-
|> fun path ->
58-
// See https://unix.stackexchange.com/questions/280528/is-there-a-unix-equivalent-of-the-windows-environment-variable-pathext
59-
if Environment.isWindows then
60-
// Prefer PATHEXT, see https://github.com/fsharp/FAKE/issues/1911
61-
// and https://github.com/fsharp/FAKE/issues/1899
62-
Environment.environVarOrDefault "PATHEXT" ".COM;.EXE;.BAT"
63-
|> String.split ';'
64-
|> Seq.collect (fun postFix -> findFiles path (file + postFix))
65-
|> fun findings -> Seq.append findings (findFiles path file)
66-
else findFiles path file
69+
|> fun dirs -> findFiles dirs file
6770

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

0 commit comments

Comments
 (0)