Skip to content

Commit

Permalink
Optimize deps to make #2020 work - fixes #2020
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Nov 17, 2016
1 parent 35598d3 commit 0974e2c
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 51 deletions.
11 changes: 0 additions & 11 deletions integrationtests/Paket.IntegrationTests/BasicResolverSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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")

[<Test>]
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")

[<Test>]
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")

[<Test>]
let ``#299 should restore package ending in lib``() =
Expand Down
11 changes: 1 addition & 10 deletions integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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")


[<Test>]
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")

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/Paket.Core/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 53 additions & 19 deletions src/Paket.Core/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -131,17 +131,17 @@ 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
| FrameworkRestriction.AtLeast(DotNetFramework(x)) -> DotNetFramework x
| 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
Expand All @@ -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
Expand All @@ -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) ->
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<StartWorkingDirectory>D:\temp\repo3</StartWorkingDirectory>
<StartArguments>install -v</StartArguments>
<StartWorkingDirectory>D:\temp\IconPacksTestApp\src</StartWorkingDirectory>
<StartArguments>install</StartArguments>
<StartWorkingDirectory>D:\temp\PaketRepro</StartWorkingDirectory>
<StartArguments>update</StartArguments>
<StartWorkingDirectory>D:\temp\primitives</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
Expand Down
16 changes: 16 additions & 0 deletions tests/Paket.Tests/DependencySetSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,19 @@ let ``should optimize real world restrictions 3``() =

let result = optimizeRestrictions original
result |> shouldEqual expected



[<Test>]
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

0 comments on commit 0974e2c

Please sign in to comment.