From 0974e2c9a12ebbd64b2480160b7166742aa2098c Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Thu, 17 Nov 2016 13:29:25 +0100 Subject: [PATCH] Optimize deps to make #2020 work - fixes #2020 --- .../BasicResolverSpecs.fs | 11 --- .../Paket.IntegrationTests/PaketCoreSpecs.fs | 11 +-- .../before/paket.dependencies | 3 - .../before/paket.dependencies | 3 - .../i001928-casing/before/paket.dependencies | 2 - src/Paket.Core/PackageResolver.fs | 2 +- src/Paket.Core/Requirements.fs | 72 ++++++++++++++----- src/Paket/Paket.fsproj | 4 +- tests/Paket.Tests/DependencySetSpecs.fs | 16 +++++ 9 files changed, 73 insertions(+), 51 deletions(-) delete mode 100644 integrationtests/scenarios/i000263-prereleases/before/paket.dependencies delete mode 100644 integrationtests/scenarios/i000263-semver-prereleases/before/paket.dependencies delete mode 100644 integrationtests/scenarios/i001928-casing/before/paket.dependencies diff --git a/integrationtests/Paket.IntegrationTests/BasicResolverSpecs.fs b/integrationtests/Paket.IntegrationTests/BasicResolverSpecs.fs index 18aaa038d9..1bbee6aa33 100644 --- a/integrationtests/Paket.IntegrationTests/BasicResolverSpecs.fs +++ b/integrationtests/Paket.IntegrationTests/BasicResolverSpecs.fs @@ -70,17 +70,6 @@ let ``#220 should respect the == operator``() = lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "Microsoft.AspNet.Razor"].Version |> shouldEqual (SemVer.Parse "2.0.30506.0") -[] -let ``#263 should respect SemVer prereleases``() = - let lockFile = update "i000263-semver-prereleases" - lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "Ninject"].Version - |> shouldEqual (SemVer.Parse "3.2.3-unstable-001") - -[] -let ``#263 should respect prereleases``() = - let lockFile = update "i000263-prereleases" - lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "Ninject"].Version - |> shouldBeGreaterThan (SemVer.Parse "3.2.3-unstable-011") [] let ``#299 should restore package ending in lib``() = diff --git a/integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs b/integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs index 0a751d1402..9eb58766ab 100644 --- a/integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs +++ b/integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs @@ -62,13 +62,4 @@ let ``#1259 install via script``() = let lockFile = LockFile.LoadFrom(Path.Combine(scenarioTempPath "i001259-install-script","paket.lock")) lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "Suave"].Version - |> shouldBeGreaterThan (SemVer.Parse "0.33.0") - - -[] -let ``#1928 reference via script with casing``() = - install "i001928-casing" |> ignore - - let dependenciesFile = Dependencies.Locate(Path.Combine(scenarioTempPath "i001928-casing")) - let model = dependenciesFile.GetInstalledPackageModel(None, "paket.core") - model.GetReferenceFolders() |> Seq.length |> shouldBeGreaterThan 0 + |> shouldBeGreaterThan (SemVer.Parse "0.33.0") \ No newline at end of file diff --git a/integrationtests/scenarios/i000263-prereleases/before/paket.dependencies b/integrationtests/scenarios/i000263-prereleases/before/paket.dependencies deleted file mode 100644 index 03ac01d143..0000000000 --- a/integrationtests/scenarios/i000263-prereleases/before/paket.dependencies +++ /dev/null @@ -1,3 +0,0 @@ -source http://nuget.org/api/v2 - -nuget Ninject >= 3.2.3 prerelease #clever comment goes here \ No newline at end of file diff --git a/integrationtests/scenarios/i000263-semver-prereleases/before/paket.dependencies b/integrationtests/scenarios/i000263-semver-prereleases/before/paket.dependencies deleted file mode 100644 index 4b05ba27dd..0000000000 --- a/integrationtests/scenarios/i000263-semver-prereleases/before/paket.dependencies +++ /dev/null @@ -1,3 +0,0 @@ -source http://nuget.org/api/v2 - -nuget Ninject == 3.2.3-unstable-001 \ No newline at end of file diff --git a/integrationtests/scenarios/i001928-casing/before/paket.dependencies b/integrationtests/scenarios/i001928-casing/before/paket.dependencies deleted file mode 100644 index f1e2c5bcb6..0000000000 --- a/integrationtests/scenarios/i001928-casing/before/paket.dependencies +++ /dev/null @@ -1,2 +0,0 @@ -source http://www.nuget.org/api/v2 -nuget Paket.Core \ No newline at end of file diff --git a/src/Paket.Core/PackageResolver.fs b/src/Paket.Core/PackageResolver.fs index e35fe4434e..07f0dee025 100644 --- a/src/Paket.Core/PackageResolver.fs +++ b/src/Paket.Core/PackageResolver.fs @@ -325,7 +325,7 @@ let Resolve(getVersionsF, getPackageDetailsF, groupName:GroupName, globalStrateg Version = version Dependencies = filteredDependencies Unlisted = packageDetails.Unlisted - Settings = settings + Settings = { settings with FrameworkRestrictions = newRestrictions } Source = packageDetails.Source } exploredPackages.Add(key,explored) Some explored diff --git a/src/Paket.Core/Requirements.fs b/src/Paket.Core/Requirements.fs index d0cafb400f..d3da8c7d86 100644 --- a/src/Paket.Core/Requirements.fs +++ b/src/Paket.Core/Requirements.fs @@ -19,7 +19,7 @@ type FrameworkRestriction = | FrameworkRestriction.AtLeast r -> ">= " + r.ToString() | FrameworkRestriction.Between(min,max) -> sprintf ">= %O < %O" min max - member private x.GetOneIdentifier = + member x.GetOneIdentifier = match x with | Exactly r -> Some r | Portable _ -> None @@ -113,7 +113,7 @@ let rec optimizeRestrictions restrictions = | [] -> [] | [x] -> [x] | odered -> - let newRestrictions' = + let newRestrictions = match odered |> Seq.tryFind (function | FrameworkRestriction.AtLeast r -> true | _ -> false) with | Some((FrameworkRestriction.AtLeast(DotNetFramework(v)) as r)) -> odered @@ -131,9 +131,9 @@ let rec optimizeRestrictions restrictions = | _ -> true) | _ -> odered - let newRestrictions = - match newRestrictions' |> Seq.rev |> Seq.tryFind (function | FrameworkRestriction.AtLeast r -> true | _ -> false) with - | None -> newRestrictions' + let filtered = + match newRestrictions |> Seq.rev |> Seq.tryFind (function | FrameworkRestriction.AtLeast r -> true | _ -> false) with + | None -> newRestrictions | Some r -> let currentVersion = match r with @@ -141,7 +141,7 @@ let rec optimizeRestrictions restrictions = | FrameworkRestriction.AtLeast(DotNetStandard(x)) -> DotNetStandard x | x -> failwithf "Unknown .NET moniker %O" x - let isLowerVersion (currentVersion:FrameworkIdentifier) x = + let isLowerVersion (currentVersion:FrameworkIdentifier) compareVersion = let isMatching (x:FrameworkIdentifier) = if x = DotNetFramework FrameworkVersion.V3_5 && currentVersion = DotNetFramework FrameworkVersion.V4 then true else if x = DotNetFramework FrameworkVersion.V3_5 && currentVersion = DotNetFramework FrameworkVersion.V4_Client then true else @@ -155,15 +155,23 @@ let rec optimizeRestrictions restrictions = not hasFrameworksBetween && not hasStandardsBetween - match x with + match compareVersion with | FrameworkRestriction.Exactly(DotNetFramework(x)) -> isMatching (DotNetFramework x) | FrameworkRestriction.Exactly(DotNetStandard(x)) -> isMatching (DotNetStandard x) - | FrameworkRestriction.AtLeast(DotNetFramework(x)) -> isMatching (DotNetFramework x) - | FrameworkRestriction.AtLeast(DotNetStandard(x)) -> isMatching (DotNetStandard x) + | FrameworkRestriction.AtLeast(DotNetFramework(x)) -> + isMatching (DotNetFramework x) || + (match currentVersion with + | DotNetFramework(y) when x < y -> true + | _ -> false) + | FrameworkRestriction.AtLeast(DotNetStandard(x)) -> + isMatching (DotNetStandard x) || + (match currentVersion with + | DotNetStandard(y) when x < y -> true + | _ -> false) | _ -> false - match newRestrictions' |> Seq.tryFind (isLowerVersion currentVersion) with - | None -> newRestrictions' + match newRestrictions |> Seq.tryFind (isLowerVersion currentVersion) with + | None -> newRestrictions | Some n -> let newLowest = match n with @@ -174,12 +182,12 @@ let rec optimizeRestrictions restrictions = | x -> failwithf "Unknown .NET moniker %O" x let filtered = - newRestrictions' + newRestrictions |> List.filter (fun x -> x <> r && x <> n) filtered @ [FrameworkRestriction.AtLeast(newLowest)] - if restrictions = newRestrictions then sorting newRestrictions else optimizeRestrictions newRestrictions + if restrictions = filtered then sorting filtered else optimizeRestrictions filtered let hasDotNetFrameworkOrAnyCase = List.exists (fun (_,_,rs) -> @@ -425,25 +433,51 @@ let private combineSameCategoryOrPortableRestrictions x y = if min' = max' then [FrameworkRestriction.Exactly(min')] else [] -let combineRestrictions (x : FrameworkRestriction) y = - if (x.IsSameCategoryAs(y) = Some(false)) then - [] - else +let combineRestrictions loose (x : FrameworkRestriction) y = + if x.IsSameCategoryAs(y) <> Some false then combineSameCategoryOrPortableRestrictions x y + else + if loose then + match (x.GetOneIdentifier, y.GetOneIdentifier) with + | Some (FrameworkIdentifier.DotNetFramework _ ), Some (FrameworkIdentifier.DotNetStandard _ ) -> [x] + | Some (FrameworkIdentifier.DotNetStandard _ ), Some (FrameworkIdentifier.DotNetFramework _ ) -> [y] + | _ -> [] + else + [] let filterRestrictions (list1:FrameworkRestrictions) (list2:FrameworkRestrictions) = let list1 = getRestrictionList list1 let list2 = getRestrictionList list2 - let optimized = + let filtered = match list1, list2 with | [],_ -> list2 | _,[] -> list1 | _ -> [for x in list1 do for y in list2 do - let c = combineRestrictions x y + let c = combineRestrictions false x y if c <> [] then yield! c] + + let tryLoose = + (filtered |> List.exists (fun r -> match r.GetOneIdentifier with | Some (FrameworkIdentifier.DotNetFramework _ ) -> true | _ -> false) |> not) && + (list2 |> List.exists (fun r -> match r.GetOneIdentifier with | Some (FrameworkIdentifier.DotNetFramework _ ) -> true | _ -> false)) + + let filtered = + if tryLoose then + match list1, list2 with + | [],_ -> list2 + | _,[] -> list1 + | _ -> + [for x in list1 do + for y in list2 do + let c = combineRestrictions true x y + if c <> [] then yield! c] + else + filtered + + let optimized = + filtered |> optimizeRestrictions FrameworkRestrictionList optimized diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index a863fb733b..ec4618072f 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -57,8 +57,8 @@ D:\temp\repo3 install -v D:\temp\IconPacksTestApp\src - install - D:\temp\PaketRepro + update + D:\temp\primitives 11 diff --git a/tests/Paket.Tests/DependencySetSpecs.fs b/tests/Paket.Tests/DependencySetSpecs.fs index 59e9b2ba28..f24b2ed2fb 100644 --- a/tests/Paket.Tests/DependencySetSpecs.fs +++ b/tests/Paket.Tests/DependencySetSpecs.fs @@ -251,3 +251,19 @@ let ``should optimize real world restrictions 3``() = let result = optimizeRestrictions original result |> shouldEqual expected + + + +[] +let ``should optimize real world .NET Standard restrictions``() = + let original = + [FrameworkRestriction.AtLeast (DotNetFramework(FrameworkVersion.V4_5_1)) + FrameworkRestriction.AtLeast (DotNetStandard(DotNetStandardVersion.V1_1)) + FrameworkRestriction.AtLeast (DotNetStandard(DotNetStandardVersion.V1_3))] + + let expected = + [FrameworkRestriction.AtLeast (DotNetFramework(FrameworkVersion.V4_5_1)) + FrameworkRestriction.AtLeast (DotNetStandard(DotNetStandardVersion.V1_1))] + + let result = optimizeRestrictions original + result |> shouldEqual expected \ No newline at end of file