Skip to content

Commit

Permalink
Better grouping of framework restrictions - fixes #1093
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Sep 28, 2015
1 parent 5ea953c commit e05c507
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 59 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### 2.4.3 - 28.09.2015
#### 2.4.4 - 28.09.2015
* BUGFIX: Inconsistent framework exclusion in paket.dependencies - https://github.com/fsprojects/Paket/issues/1093

#### 2.4.1 - 28.09.2015
Expand Down
28 changes: 16 additions & 12 deletions src/Paket.Core/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,23 @@ type TargetProfile =
| _ -> "portable-net45+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1" // Use Portable259 as default

module KnownTargetProfiles =
let DotNetFrameworkVersions =
[FrameworkVersion.V1
FrameworkVersion.V1_1
FrameworkVersion.V2
FrameworkVersion.V3
FrameworkVersion.V3_5
FrameworkVersion.V4_Client
FrameworkVersion.V4
FrameworkVersion.V4_5
FrameworkVersion.V4_5_1
FrameworkVersion.V4_5_2
FrameworkVersion.V4_5_3
FrameworkVersion.V4_6]

let DotNetFrameworkProfiles =
[SinglePlatform(DotNetFramework FrameworkVersion.V1)
SinglePlatform(DotNetFramework FrameworkVersion.V1_1)
SinglePlatform(DotNetFramework FrameworkVersion.V2)
SinglePlatform(DotNetFramework FrameworkVersion.V3)
SinglePlatform(DotNetFramework FrameworkVersion.V3_5)
SinglePlatform(DotNetFramework FrameworkVersion.V4_Client)
SinglePlatform(DotNetFramework FrameworkVersion.V4)
SinglePlatform(DotNetFramework FrameworkVersion.V4_5)
SinglePlatform(DotNetFramework FrameworkVersion.V4_5_1)
SinglePlatform(DotNetFramework FrameworkVersion.V4_5_2)
SinglePlatform(DotNetFramework FrameworkVersion.V4_5_3)
SinglePlatform(DotNetFramework FrameworkVersion.V4_6)]
DotNetFrameworkVersions
|> List.map (fun x -> SinglePlatform(DotNetFramework(x)))

let WindowsProfiles =
[SinglePlatform(Windows "v4.5")
Expand Down
88 changes: 62 additions & 26 deletions src/Paket.Core/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ let optimizeRestrictions packages =
| _ -> () ]
|> List.sortBy fst

let globalMax =
invertedRestrictions
|> List.tryLast
|> Option.map fst

let emptyRestrictions =
[for (n,vr,r:FrameworkRestrictions) in packages do
if r = [] then
Expand All @@ -130,35 +135,66 @@ let optimizeRestrictions packages =
group
|> List.map (fun (_,_,res) -> res)
|> List.concat
|> List.distinct
|> List.sort

let localMaxDotNetRestriction = findMaxDotNetRestriction plain
let localMaxDotNetRestriction = findMaxDotNetRestriction plain
let globalMax = defaultArg globalMax localMaxDotNetRestriction

let dotnetRestrictions,others = List.partition (function | FrameworkRestriction.Exactly(DotNetFramework(_)) -> true | _ -> false) plain
let restrictions =
match plain with
| [] -> plain
| [x] -> plain
| _ ->
plain
|> List.map (fun restriction ->
match restriction with
| FrameworkRestriction.Exactly r ->
if r = localMaxDotNetRestriction then
let globalMax =
invertedRestrictions
|> List.skipWhile (fun (r,l) -> r <= localMaxDotNetRestriction && l |> List.exists (fun (n,vr) -> n = name && vr = versionRequirement))
|> List.map fst

if globalMax = [] || r >= globalMax.Head then
FrameworkRestriction.AtLeast r
else
FrameworkRestriction.Between(r,globalMax.Head)
else
restriction
| _ -> restriction)
|> List.distinct
|> List.sort

yield name,versionRequirement,restrictions]
let rec calcRestrictions restrictions =
match restrictions with
| [] -> restrictions
| [x] -> restrictions
| _ ->

let newRestrictions' =
restrictions
|> List.map (fun restriction ->
match restriction with
| FrameworkRestriction.Exactly r ->
if r = localMaxDotNetRestriction && r = globalMax then
FrameworkRestriction.AtLeast r
else
restriction
| _ -> restriction)
|> List.distinct
|> List.sort

let newRestrictions =
match newRestrictions' |> Seq.tryFind (function | FrameworkRestriction.AtLeast r -> true | _ -> false) with
| None -> newRestrictions'
| Some r ->
let currentVersion =
match r with
| FrameworkRestriction.AtLeast(DotNetFramework(x)) -> x
| x -> failwithf "Unknown .NET moniker %O" x

let isLowerVersion x =
match x with
| FrameworkRestriction.Exactly(DotNetFramework(x)) ->
if x = FrameworkVersion.V3_5 && currentVersion = FrameworkVersion.V4 then true else
let hasFrameworksBetween = KnownTargetProfiles.DotNetFrameworkVersions |> Seq.exists (fun p -> p > x && p < currentVersion)
not hasFrameworksBetween
| _ -> false

match newRestrictions' |> Seq.tryFind isLowerVersion with
| None -> newRestrictions'
| Some n ->
let newLowest =
match n with
| FrameworkRestriction.Exactly(DotNetFramework(x)) -> x
| x -> failwithf "Unknown .NET moniker %O" x

(newRestrictions'
|> List.filter (fun x -> x <> r && x <> n)) @ [FrameworkRestriction.AtLeast(DotNetFramework(newLowest))]

if restrictions = newRestrictions then newRestrictions else calcRestrictions newRestrictions

calcRestrictions dotnetRestrictions

yield name,versionRequirement,others @ restrictions]

type InstallSettings =
{ ImportTargets : bool option
Expand Down
2 changes: 1 addition & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<StartWorkingDirectory>c:\code\Paket09x</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\Pakettest</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\Paketkopie</StartWorkingDirectory>
<StartArguments>update -f</StartArguments>
<StartArguments>update</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>c:\code\Paketkopie</StartWorkingDirectory>
Expand Down
16 changes: 4 additions & 12 deletions tests/Paket.Tests/DependencySetSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ let ``should optimize 2 restriction set with only exactly``() =
PackageName("P2"), VersionRequirement.AllReleases, [FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V3_5))]]

let expected =
[PackageName("P1"), VersionRequirement.AllReleases,
[FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V3_5))
FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V4))
FrameworkRestriction.AtLeast (DotNetFramework(FrameworkVersion.V4_5))]
[PackageName("P1"), VersionRequirement.AllReleases, [FrameworkRestriction.AtLeast (DotNetFramework(FrameworkVersion.V3_5))]
PackageName("P2"), VersionRequirement.AllReleases, [FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V3_5))]]

original
Expand Down Expand Up @@ -56,10 +53,7 @@ let ``should optimize 2 restriction sets with between``() =
PackageName("P2"), VersionRequirement.AllReleases, [FrameworkRestriction.Between (DotNetFramework(FrameworkVersion.V3_5),DotNetFramework(FrameworkVersion.V4_Client))]]

let expected =
[PackageName("P1"), VersionRequirement.AllReleases,
[FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V3_5))
FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V4))
FrameworkRestriction.AtLeast (DotNetFramework(FrameworkVersion.V4_5))]
[PackageName("P1"), VersionRequirement.AllReleases, [FrameworkRestriction.AtLeast (DotNetFramework(FrameworkVersion.V3_5))]
PackageName("P2"), VersionRequirement.AllReleases, [FrameworkRestriction.Between (DotNetFramework(FrameworkVersion.V3_5),DotNetFramework(FrameworkVersion.V4_Client))]]

original
Expand Down Expand Up @@ -146,10 +140,8 @@ let ``should optimize ZendeskApi_v2 ``() =

let expected =
[PackageName("Newtonsoft.Json"), VersionRequirement.AllReleases,
[FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V3_5))
FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V4))
FrameworkRestriction.Portable "portable-net45+sl40+wp71+win80"
FrameworkRestriction.AtLeast (DotNetFramework(FrameworkVersion.V4_5))]
[FrameworkRestriction.Portable "portable-net45+sl40+wp71+win80"
FrameworkRestriction.AtLeast (DotNetFramework(FrameworkVersion.V3_5))]
PackageName("AsyncCTP"), VersionRequirement.AllReleases, [FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V4))]
PackageName("Microsoft.Bcl.Async"), VersionRequirement.AllReleases, [FrameworkRestriction.Portable "portable-net45+sl40+wp71+win80"]]

Expand Down
7 changes: 3 additions & 4 deletions tests/Paket.Tests/NuGetOData/ODataSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ let ``can detect explicit dependencies for ReadOnlyCollectionExtensions``() =
[PackageName "LinqBridge",DependenciesFileParser.parseVersionRequirement(">= 1.3.0"), [FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V2))]
PackageName "ReadOnlyCollectionInterfaces",DependenciesFileParser.parseVersionRequirement("1.0.0"),
[FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V2))
FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V3_5))
FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_Client))]]
FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V3_5))]]
SourceUrl = fakeUrl }

[<Test>]
Expand Down Expand Up @@ -138,7 +137,7 @@ let ``can detect explicit dependencies for Microsoft.AspNet.WebApi.Client``() =
let dependencies = odata.Dependencies |> Array.ofList
dependencies.[0] |> shouldEqual
(PackageName "Newtonsoft.Json", DependenciesFileParser.parseVersionRequirement(">= 6.0.4"),
[FrameworkRestriction.Portable("portable-wp80+win+net45+wp81+wpa81"); FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_5))])
[FrameworkRestriction.Portable("portable-wp80+win+net45+wp81+wpa81"); FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))])
dependencies.[1] |> shouldEqual
(PackageName "Microsoft.Net.Http", DependenciesFileParser.parseVersionRequirement(">= 2.2.22"),
[FrameworkRestriction.Portable("portable-wp80+win+net45+wp81+wpa81")])
Expand All @@ -163,4 +162,4 @@ let ``can detect explicit dependencies for WindowsAzure.Storage``() =

dependencies.[44] |> shouldEqual
(PackageName "Newtonsoft.Json", DependenciesFileParser.parseVersionRequirement(">= 6.0.8"),
[FrameworkRestriction.Exactly(WindowsPhoneSilverlight("v8.0")); FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_Client))])
[FrameworkRestriction.Exactly(WindowsPhoneSilverlight("v8.0")); FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_Client))])
5 changes: 2 additions & 3 deletions tests/Paket.Tests/Nuspec/NuspecSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ let ``can detect explicit dependencies for ReadOnlyCollectionExtensions``() =
[FrameworkRestriction.Exactly (DotNetFramework(FrameworkVersion.V2))]
PackageName "ReadOnlyCollectionInterfaces",DependenciesFileParser.parseVersionRequirement("1.0.0"),
[FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V2))
FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V3_5))
FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_Client))]]
FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V3_5))]]

[<Test>]
let ``can detect framework assemblies for MathNet.Numerics``() =
Expand Down Expand Up @@ -189,7 +188,7 @@ let ``can detect explicit dependencies for WindowsAzure.Storage``() =
(PackageName "Newtonsoft.Json",
DependenciesFileParser.parseVersionRequirement(">= 5.0.8"),
[FrameworkRestriction.Exactly(WindowsPhoneSilverlight("v8.0"))
FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_Client))])
FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_Client))])

[<Test>]
let ``can detect framework assemblies for Microsoft.Framework.Logging``() =
Expand Down

0 comments on commit e05c507

Please sign in to comment.