From d5a490b1f2434d24e5bc9cf1e470f9ee6b5b445b Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Wed, 22 Sep 2021 17:19:21 -0700 Subject: [PATCH 1/2] fsharp core location --- src/fsharp/utils/CompilerLocationUtils.fs | 25 ++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/fsharp/utils/CompilerLocationUtils.fs b/src/fsharp/utils/CompilerLocationUtils.fs index 803e5d25e02..4fa0f2775b4 100644 --- a/src/fsharp/utils/CompilerLocationUtils.fs +++ b/src/fsharp/utils/CompilerLocationUtils.fs @@ -353,24 +353,35 @@ module internal FSharpEnvironment = let getFSharpCoreLibraryName = "FSharp.Core" let fsiLibraryName = "FSharp.Compiler.Interactive.Settings" - let getFSharpCompilerLocation() = - let location = Path.GetDirectoryName(typeof.Assembly.Location) - match BinFolderOfDefaultFSharpCompiler (Some location) with + let getFSharpCompilerLocationWithDefaultFromType (defaultLocation: Type) = + let location = + try + Some (Path.GetDirectoryName(defaultLocation.Assembly.Location)) + with | _ -> + None + match BinFolderOfDefaultFSharpCompiler (location) with | Some path -> path | None -> + let path = location |> Option.defaultValue "" #if DEBUG Debug.Print(sprintf """FSharpEnvironment.BinFolderOfDefaultFSharpCompiler (Some '%s') returned None Location customized incorrectly: algorithm here: https://github.com/dotnet/fsharp/blob/03f3f1c35f82af26593d025dabca57a6ef3ea9a1/src/utils/CompilerLocationUtils.fs#L171""" - location) + path) #endif // Use the location of this dll - location + path + + // Fallback to ambient FSharp.CompilerService.dll + let getFSharpCompilerLocation() = getFSharpCompilerLocationWithDefaultFromType(typeof) + + // Fallback to ambient FSharp.Core.dll + let getDefaultFSharpCoreLocation() = getFSharpCompilerLocationWithDefaultFromType(typeof) - let getDefaultFSharpCoreLocation() = Path.Combine(getFSharpCompilerLocation(), getFSharpCoreLibraryName + ".dll") + // Must be alongside the location of FSharp.CompilerService.dll let getDefaultFsiLibraryLocation() = Path.Combine(getFSharpCompilerLocation(), fsiLibraryName + ".dll") // Path to the directory containing the fsharp compilers - let fsharpCompilerPath = Path.Combine(Path.GetDirectoryName(typeof.GetTypeInfo().Assembly.Location), "Tools") + let fsharpCompilerPath = Path.Combine(Path.GetDirectoryName(getFSharpCompilerLocation()), "Tools") let isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) From 4817bfe6437d44e12039dcd8bdb841962d323db4 Mon Sep 17 00:00:00 2001 From: KevinRansom Date: Wed, 22 Sep 2021 18:27:44 -0700 Subject: [PATCH 2/2] FSharp core location --- src/fsharp/utils/CompilerLocationUtils.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fsharp/utils/CompilerLocationUtils.fs b/src/fsharp/utils/CompilerLocationUtils.fs index 4fa0f2775b4..0adb3250fa8 100644 --- a/src/fsharp/utils/CompilerLocationUtils.fs +++ b/src/fsharp/utils/CompilerLocationUtils.fs @@ -372,13 +372,13 @@ module internal FSharpEnvironment = path // Fallback to ambient FSharp.CompilerService.dll - let getFSharpCompilerLocation() = getFSharpCompilerLocationWithDefaultFromType(typeof) + let getFSharpCompilerLocation() = Path.Combine(getFSharpCompilerLocationWithDefaultFromType(typeof)); // Fallback to ambient FSharp.Core.dll - let getDefaultFSharpCoreLocation() = getFSharpCompilerLocationWithDefaultFromType(typeof) + let getDefaultFSharpCoreLocation() = Path.Combine(getFSharpCompilerLocationWithDefaultFromType(typeof), getFSharpCoreLibraryName + ".dll") // Must be alongside the location of FSharp.CompilerService.dll - let getDefaultFsiLibraryLocation() = Path.Combine(getFSharpCompilerLocation(), fsiLibraryName + ".dll") + let getDefaultFsiLibraryLocation() = Path.Combine(Path.GetDirectoryName(getFSharpCompilerLocation()), fsiLibraryName + ".dll") // Path to the directory containing the fsharp compilers let fsharpCompilerPath = Path.Combine(Path.GetDirectoryName(getFSharpCompilerLocation()), "Tools")