зеркало из https://github.com/dotnet/fsharp.git
merge
This commit is contained in:
Коммит
46d7a308e2
|
@ -129,3 +129,4 @@ msbuild.binlog
|
||||||
/fcs/FSharp.Compiler.Service.netstandard/*.fs
|
/fcs/FSharp.Compiler.Service.netstandard/*.fs
|
||||||
/fcs/FSharp.Compiler.Service.netstandard/*.fsi
|
/fcs/FSharp.Compiler.Service.netstandard/*.fsi
|
||||||
/.ionide/
|
/.ionide/
|
||||||
|
**/.DS_Store
|
||||||
|
|
|
@ -2806,7 +2806,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
|
||||||
if Directory.Exists runtimeRootWPF then
|
if Directory.Exists runtimeRootWPF then
|
||||||
yield runtimeRootWPF // PresentationCore.dll is in C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF
|
yield runtimeRootWPF // PresentationCore.dll is in C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF
|
||||||
|
|
||||||
match getFrameworkRefsPackDirectory with
|
match frameworkRefsPackDirectory with
|
||||||
| Some path when Directory.Exists(path) ->
|
| Some path when Directory.Exists(path) ->
|
||||||
yield path
|
yield path
|
||||||
| _ -> ()
|
| _ -> ()
|
||||||
|
|
|
@ -7,6 +7,7 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
|
||||||
open System
|
open System
|
||||||
open System.Collections.Generic
|
open System.Collections.Generic
|
||||||
open System.Diagnostics
|
open System.Diagnostics
|
||||||
|
open System.Globalization
|
||||||
open System.IO
|
open System.IO
|
||||||
open System.Reflection
|
open System.Reflection
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
|
||||||
|
|
||||||
let getFSharpCoreLibraryName = "FSharp.Core"
|
let getFSharpCoreLibraryName = "FSharp.Core"
|
||||||
let getFsiLibraryName = "FSharp.Compiler.Interactive.Settings"
|
let getFsiLibraryName = "FSharp.Compiler.Interactive.Settings"
|
||||||
let frameworkDir = Path.GetDirectoryName(typeof<Object>.Assembly.Location)
|
let implementationAssemblyDir = Path.GetDirectoryName(typeof<obj>.Assembly.Location)
|
||||||
let getDefaultFSharpCoreReference = typeof<Microsoft.FSharp.Core.Unit>.Assembly.Location
|
let getDefaultFSharpCoreReference = typeof<Microsoft.FSharp.Core.Unit>.Assembly.Location
|
||||||
let getFSharpCompilerLocation = Path.GetDirectoryName(typeof<TypeInThisAssembly>.Assembly.Location)
|
let getFSharpCompilerLocation = Path.GetDirectoryName(typeof<TypeInThisAssembly>.Assembly.Location)
|
||||||
let isRunningOnCoreClr = (typeof<obj>.Assembly).FullName.StartsWith("System.Private.CoreLib", StringComparison.InvariantCultureIgnoreCase)
|
let isRunningOnCoreClr = (typeof<obj>.Assembly).FullName.StartsWith("System.Private.CoreLib", StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
@ -35,49 +36,28 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
|
||||||
None
|
None
|
||||||
with _ -> None
|
with _ -> None
|
||||||
|
|
||||||
// Compare nuget version strings
|
|
||||||
//
|
|
||||||
// Format:
|
|
||||||
// =======
|
|
||||||
// $(Major).$(Minor).$(Build) [-SomeSuffix]
|
|
||||||
// Major, Minor, Build collates normally
|
|
||||||
// Strings without -SomeSuffix collate higher than SomeSuffix,
|
|
||||||
// SomeSuffix collates using normal alphanumeric rules
|
|
||||||
//
|
|
||||||
let deconstructVersion (version:string) =
|
|
||||||
let version, suffix =
|
|
||||||
let pos = version.IndexOf("-")
|
|
||||||
if pos >= 0 then
|
|
||||||
version.Substring(0, pos), version.Substring(pos + 1)
|
|
||||||
else version, ""
|
|
||||||
|
|
||||||
let elements = version.Split('.')
|
// Algorithm:
|
||||||
if elements.Length < 3 then
|
// use implementation location of obj type, on shared frameworks it will always be in:
|
||||||
struct (0, 0, 0, suffix)
|
//
|
||||||
else
|
// dotnet\shared\Microsoft.NETCore.App\sdk-version\System.Private.CoreLib.dll
|
||||||
struct (Int32.Parse(elements.[0]), Int32.Parse(elements.[1]), Int32.Parse(elements.[2]), suffix)
|
//
|
||||||
|
// if that changes we will need to find another way to do this. Hopefully the sdk will eventually provide an API
|
||||||
let versionCompare c1 c2 =
|
// use the well know location for obj to traverse the file system towards the
|
||||||
if c1 = c2 then 0
|
//
|
||||||
else
|
// packs\Microsoft.NETCore.App.Ref\sdk-version\netcoreappn.n
|
||||||
try
|
// we will rely on the sdk-version match on the two paths to ensure that we get the product that ships with the
|
||||||
let struct (major1, minor1, build1, suffix1 ) = deconstructVersion c1
|
// version of the runtime we are executing on
|
||||||
let struct (major2, minor2, build2, suffix2 ) = deconstructVersion c2
|
// Use the reference assemblies for the highest netcoreapp tfm that we find in that location.
|
||||||
let v = major1 - major2
|
let version, frameworkRefsPackDirectoryRoot =
|
||||||
if v <> 0 then v
|
try
|
||||||
else
|
let version = DirectoryInfo(implementationAssemblyDir).Name
|
||||||
let v = minor1 - minor2
|
let microsoftNETCoreAppRef = Path.Combine(implementationAssemblyDir, "../../../packs/Microsoft.NETCore.App.Ref")
|
||||||
if v <> 0 then v
|
if Directory.Exists(microsoftNETCoreAppRef) then
|
||||||
else
|
Some version, Some microsoftNETCoreAppRef
|
||||||
let v = build1 - build2
|
else
|
||||||
if v <> 0 then v
|
Some version, None
|
||||||
else
|
with | _ -> None, None
|
||||||
match String.IsNullOrEmpty(suffix1), String.IsNullOrEmpty(suffix2) with
|
|
||||||
| true, true -> 0
|
|
||||||
| true, false -> 1
|
|
||||||
| false, true -> -1
|
|
||||||
| false, false -> String.Compare(suffix1, suffix2, StringComparison.InvariantCultureIgnoreCase)
|
|
||||||
with _ -> 0
|
|
||||||
|
|
||||||
// Tries to figure out the tfm for the compiler instance.
|
// Tries to figure out the tfm for the compiler instance.
|
||||||
// On coreclr it uses the deps.json file
|
// On coreclr it uses the deps.json file
|
||||||
|
@ -163,31 +143,44 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
|
||||||
match netcoreTfm with
|
match netcoreTfm with
|
||||||
| Some tfm -> tfm
|
| Some tfm -> tfm
|
||||||
| _ -> getWindowsDesktopTfm ()
|
| _ -> getWindowsDesktopTfm ()
|
||||||
|
|
||||||
let getFrameworkRefsPackDirectoryPath =
|
|
||||||
match netcoreTfm with
|
|
||||||
| Some _ ->
|
|
||||||
let appRefDir = Path.Combine(getFSharpCompilerLocation, "../../../packs/Microsoft.NETCore.App.Ref")
|
|
||||||
if Directory.Exists(appRefDir) then
|
|
||||||
Some appRefDir
|
|
||||||
else
|
|
||||||
None
|
|
||||||
| _ -> None
|
|
||||||
|
|
||||||
let isInReferenceAssemblyPackDirectory filename =
|
let isInReferenceAssemblyPackDirectory filename =
|
||||||
match getFrameworkRefsPackDirectoryPath with
|
match frameworkRefsPackDirectoryRoot with
|
||||||
| Some appRefDir ->
|
| Some root ->
|
||||||
let path = Path.GetDirectoryName(filename)
|
let path = Path.GetDirectoryName(filename)
|
||||||
path.StartsWith(appRefDir, StringComparison.OrdinalIgnoreCase)
|
path.StartsWith(root, StringComparison.OrdinalIgnoreCase)
|
||||||
| _ -> false
|
| _ -> false
|
||||||
|
|
||||||
let getFrameworkRefsPackDirectory =
|
let frameworkRefsPackDirectory =
|
||||||
match netcoreTfm, getFrameworkRefsPackDirectoryPath with
|
let tfmPrefix = "netcoreapp"
|
||||||
| Some tfm, Some appRefDir ->
|
let tfmCompare c1 c2 =
|
||||||
|
let deconstructTfmApp (netcoreApp: DirectoryInfo) =
|
||||||
|
let name = netcoreApp.Name
|
||||||
|
try
|
||||||
|
if name.StartsWith(tfmPrefix, StringComparison.InvariantCultureIgnoreCase) then
|
||||||
|
Some (Double.Parse(name.Substring(tfmPrefix.Length), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture))
|
||||||
|
else
|
||||||
|
None
|
||||||
|
with _ -> None
|
||||||
|
|
||||||
|
if c1 = c2 then 0
|
||||||
|
else
|
||||||
|
match (deconstructTfmApp c1), (deconstructTfmApp c2) with
|
||||||
|
| Some c1, Some c2 -> int(c1 - c2)
|
||||||
|
| None, Some _ -> -1
|
||||||
|
| Some _, None -> 1
|
||||||
|
| _ -> 0
|
||||||
|
|
||||||
|
match version, frameworkRefsPackDirectoryRoot with
|
||||||
|
| Some version, Some root ->
|
||||||
try
|
try
|
||||||
let refDirs = Directory.GetDirectories(appRefDir)
|
let ref = Path.Combine(root, version, "ref")
|
||||||
let versionPath = refDirs |> Array.sortWith (versionCompare) |> Array.last
|
let highestTfm = DirectoryInfo(ref).GetDirectories()
|
||||||
Some(Path.Combine(versionPath, "ref", tfm))
|
|> Array.sortWith tfmCompare
|
||||||
|
|> Array.tryLast
|
||||||
|
|
||||||
|
match highestTfm with
|
||||||
|
| Some tfm -> Some (Path.Combine(ref, tfm.Name))
|
||||||
|
| None -> None
|
||||||
with | _ -> None
|
with | _ -> None
|
||||||
| _ -> None
|
| _ -> None
|
||||||
|
|
||||||
|
@ -196,15 +189,16 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
|
||||||
|
|
||||||
// Identify path to a dll in the framework directory from a simple name
|
// Identify path to a dll in the framework directory from a simple name
|
||||||
let frameworkPathFromSimpleName simpleName =
|
let frameworkPathFromSimpleName simpleName =
|
||||||
let pathDll = Path.Combine(frameworkDir, simpleName + ".dll")
|
let root = Path.Combine(implementationAssemblyDir, simpleName)
|
||||||
if not (File.Exists(pathDll)) then
|
let pathOpt =
|
||||||
let pathExe = Path.Combine(frameworkDir, simpleName + ".exe")
|
[| ""; ".dll"; ".exe" |]
|
||||||
if not (File.Exists(pathExe)) then
|
|> Seq.tryPick(fun ext ->
|
||||||
pathDll
|
let path = root + ext
|
||||||
else
|
if File.Exists(path) then Some path
|
||||||
pathExe
|
else None)
|
||||||
else
|
match pathOpt with
|
||||||
pathDll
|
| Some path -> path
|
||||||
|
| None -> root
|
||||||
|
|
||||||
// Collect all assembly dependencies into assemblies dictionary
|
// Collect all assembly dependencies into assemblies dictionary
|
||||||
let rec traverseDependencies reference =
|
let rec traverseDependencies reference =
|
||||||
|
@ -285,14 +279,14 @@ module internal FSharp.Compiler.DotNetFrameworkDependencies
|
||||||
let getImplementationReferences () =
|
let getImplementationReferences () =
|
||||||
// Coreclr supports netstandard assemblies only for now
|
// Coreclr supports netstandard assemblies only for now
|
||||||
(getDependenciesOf [
|
(getDependenciesOf [
|
||||||
yield Path.Combine(frameworkDir, "netstandard.dll")
|
yield Path.Combine(implementationAssemblyDir, "netstandard.dll")
|
||||||
yield getDefaultFSharpCoreReference
|
yield getDefaultFSharpCoreReference
|
||||||
if useFsiAuxLib then yield getFsiLibraryName
|
if useFsiAuxLib then yield getFsiLibraryName
|
||||||
]).Values |> Seq.toList
|
]).Values |> Seq.toList
|
||||||
|
|
||||||
if useSdkRefs then
|
if useSdkRefs then
|
||||||
// Go fetch references
|
// Go fetch references
|
||||||
match getFrameworkRefsPackDirectory with
|
match frameworkRefsPackDirectory with
|
||||||
| Some path ->
|
| Some path ->
|
||||||
try [ yield! Directory.GetFiles(path, "*.dll")
|
try [ yield! Directory.GetFiles(path, "*.dll")
|
||||||
yield getDefaultFSharpCoreReference
|
yield getDefaultFSharpCoreReference
|
||||||
|
|
|
@ -66,7 +66,7 @@ type LanguageVersion (specifiedVersion) =
|
||||||
match specifiedVersion with
|
match specifiedVersion with
|
||||||
| "?" -> 0m
|
| "?" -> 0m
|
||||||
| "preview" -> previewVersion
|
| "preview" -> previewVersion
|
||||||
| "default" -> latestVersion
|
| "default" -> defaultVersion
|
||||||
| "latest" -> latestVersion
|
| "latest" -> latestVersion
|
||||||
| "latestmajor" -> latestMajorVersion
|
| "latestmajor" -> latestMajorVersion
|
||||||
| _ ->
|
| _ ->
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
<Compile Include="ProductVersion.fs" />
|
<Compile Include="ProductVersion.fs" />
|
||||||
<Compile Include="EditDistance.fs" />
|
<Compile Include="EditDistance.fs" />
|
||||||
<Compile Include="SuggestionBuffer.fs" />
|
<Compile Include="SuggestionBuffer.fs" />
|
||||||
<Compile Include="VersionCompare.fs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
|
|
||||||
namespace FSharp.Compiler.UnitTests
|
|
||||||
|
|
||||||
open System
|
|
||||||
open System.Globalization
|
|
||||||
open System.Text
|
|
||||||
open NUnit.Framework
|
|
||||||
open FSharp.Compiler
|
|
||||||
|
|
||||||
[<TestFixture>]
|
|
||||||
module VersionCompare =
|
|
||||||
open FSharp.Compiler.DotNetFrameworkDependencies
|
|
||||||
|
|
||||||
[<TestCase("1.0.0", "1.0.1", ExpectedResult = -1)>] // 1.0.0 < 1.0.1
|
|
||||||
[<TestCase("1.0.0", "1.0.0", ExpectedResult = 0)>] // 1.0.0 = 1.0.0
|
|
||||||
[<TestCase("1.0.1", "1.0.0", ExpectedResult = 1)>] // 1.0.1 > 1.0.1
|
|
||||||
[<TestCase("0.0.9", "1.0.0-Suffix1", ExpectedResult = -1)>] // 0.0.9 < 1.0.0-Suffix1
|
|
||||||
[<TestCase("1.0.0", "1.0.0-Suffix1", ExpectedResult = 1)>] // 1.0.0 > 1.0.0-Suffix1
|
|
||||||
[<TestCase("1.0.0-Suffix1", "1.0.0", ExpectedResult = -1)>] // 1.0.0-Suffix1 < 1.0.0
|
|
||||||
[<TestCase("1.0.0-Suffix1", "1.0.0-Suffix2", ExpectedResult = -1)>] // 1.0.0-Suffix1 < 1.0.0-Suffix2
|
|
||||||
[<TestCase("1.0.0-Suffix2", "1.0.0-Suffix1", ExpectedResult = 1)>] // 1.0.0-Suffix2 > 1.0.0-Suffix1
|
|
||||||
[<TestCase("1.0.0-Suffix1", "1.0.0-Suffix1", ExpectedResult = 0)>] // 1.0.0-Suffix1 > 1.0.0-Suffix2
|
|
||||||
[<TestCase("1.0.1", "1.0.0-Suffix1", ExpectedResult = 1)>] // 1.0.1 > 1.0.0-Suffix1
|
|
||||||
[<TestCase("1.0.0-Suffix1", "1.0.1", ExpectedResult = -1)>] // 1.0.0-Suffix1 < 1.0.1
|
|
||||||
let VersionCompareTest (str1: string, str2: string) : int =
|
|
||||||
versionCompare str1 str2
|
|
||||||
|
|
||||||
|
|
||||||
[<Test>]
|
|
||||||
[<TestCase("", ExpectedResult = "3.0.0-preview4-27610-06")>]
|
|
||||||
let VersionCompareSortArrayHighestPreview _: string =
|
|
||||||
let versions = [|
|
|
||||||
"1.0.0-preview4-20000-01"
|
|
||||||
"3.0.0-preview4-27610-06"
|
|
||||||
"1.0.0-preview4-20000-02"
|
|
||||||
"3.0.0-preview4-27610-05"
|
|
||||||
"3.0.0-preview4-27609-10"
|
|
||||||
|]
|
|
||||||
versions |> Array.sortWith (versionCompare) |> Array.last
|
|
||||||
|
|
||||||
[<Test>]
|
|
||||||
[<TestCase("", ExpectedResult = "3.0.0")>]
|
|
||||||
let VersionCompareSortArrayHighestRelease _: string =
|
|
||||||
let versions = [|
|
|
||||||
"1.0.0-preview4-20000-01"
|
|
||||||
"3.0.0"
|
|
||||||
"3.0.0-preview4-27610-06"
|
|
||||||
"1.0.0-preview4-20000-02"
|
|
||||||
"3.0.0-preview4-27610-05"
|
|
||||||
"3.0.0-preview4-27609-10"
|
|
||||||
|]
|
|
||||||
versions |> Array.sortWith (versionCompare) |> Array.last
|
|
||||||
|
|
||||||
[<Test>]
|
|
||||||
[<TestCase("", ExpectedResult = "3.0.1")>]
|
|
||||||
let VersionCompareSortArrayEvenHighestRelease _: string =
|
|
||||||
let versions = [|
|
|
||||||
"3.0.1"
|
|
||||||
"1.0.0-preview4-20000-01"
|
|
||||||
"3.0.0"
|
|
||||||
"3.0.0-preview4-27610-06"
|
|
||||||
"1.0.0-preview4-20000-02"
|
|
||||||
"3.0.0-preview4-27610-05"
|
|
||||||
"3.0.0-preview4-27609-10"
|
|
||||||
|]
|
|
||||||
versions |> Array.sortWith (versionCompare) |> Array.last
|
|
Загрузка…
Ссылка в новой задаче