Skip to content

Commit

Permalink
Fsdk: fix VsWhere when no entries are returned
Browse files Browse the repository at this point in the history
Otherwise First() would fail with IOE: Sequence contains no
elements.
  • Loading branch information
knocte committed Aug 12, 2023
1 parent 7acb7a5 commit 2268d50
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
11 changes: 6 additions & 5 deletions Fsdk/Process.fs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ module Process =
commandNamesByOrderOfPreference

// FIXME: it returns the first result, but we should return all (array<string>)
let VsWhere(searchPattern: string) : string =
let VsWhere(searchPattern: string) : Option<string> =
if Misc.GuessPlatform() <> Misc.Platform.Windows then
failwith "vswhere.exe doesn't exist in other platforms than Windows"

Expand All @@ -523,14 +523,15 @@ module Process =

let procResult = Execute(vswhereCmd, Echo.Off)

let firstResult =
let entries =
procResult
.UnwrapDefault()
.Split(
Array.singleton Environment.NewLine,
StringSplitOptions.RemoveEmptyEntries
)
.First()
.Trim()

firstResult
if entries.Any() then
entries.First().Trim() |> Some
else
None
5 changes: 4 additions & 1 deletion fsxc/Fsxc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,10 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
"dotnet"
#else
match Misc.GuessPlatform() with
| Misc.Platform.Windows -> Process.VsWhere "**\\fsc.exe"
| Misc.Platform.Windows ->
match Process.VsWhere "**\\fsc.exe" with
| None -> failwith "fsc.exe not found"
| Some fscExe -> fscExe
| _ -> "fsharpc"
#endif

Expand Down
4 changes: 3 additions & 1 deletion scripts/make.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ let FindBuildTool() : string * string =
#if !LEGACY_FRAMEWORK
"dotnet", "build"
#else
(Process.VsWhere "MSBuild\\**\\Bin\\MSBuild.exe"), String.Empty
match Process.VsWhere "MSBuild\\**\\Bin\\MSBuild.exe" with
| None -> failwith "msbuild not found?"
| Some msbuildExe -> msbuildExe, String.Empty
#endif

let BuildSolution
Expand Down
5 changes: 4 additions & 1 deletion scripts/runTests.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ let fsharpCompilerCommand =
"dotnet"
#else
match Misc.GuessPlatform() with
| Misc.Platform.Windows -> Process.VsWhere "**\\fsc.exe"
| Misc.Platform.Windows ->
match Process.VsWhere "**\\fsc.exe" with
| None -> failwith "fsc.exe not found"
| Some fscExe -> fscExe
| _ -> "fsharpc"
#endif

Expand Down
4 changes: 3 additions & 1 deletion test/testProcess.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ let command =
if Misc.GuessPlatform() = Misc.Platform.Windows then
// HACK: we should call fsx here but then we would get this problem in
// the tests: error FS0193: The process cannot access the file 'D:\a\fsx\fsx\test\bin\FSharp.Core.dll' because it is being used by another process.
Process.VsWhere "**\\fsi.exe"
match Process.VsWhere "**\\fsi.exe" with
| None -> failwith "fsi.exe not found"
| Some fsiExe -> fsiExe
else
// FIXME: extract PREFIX from build.config instead of assuming default
"/usr/local/bin/fsx"
Expand Down

0 comments on commit 2268d50

Please sign in to comment.