Skip to content

Commit

Permalink
Always filter framework restrictions - fixes #1182
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 31, 2015
1 parent c711b22 commit 2934794
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 26 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#### 2.20.0 - 30.10.2015
* Allow filtered updates of packages matching a regex - https://github.com/fsprojects/Paket/pull/1178
* Search for paket.references in startup directory (auto-restore feature) - https://github.com/fsprojects/Paket/pull/1179
* BUGFIX: Framework filtering for transisitve packages - https://github.com/fsprojects/Paket/issues/1182

#### 2.19.0 - 29.10.2015
* Resolver changed to breadth first search to escape more quickly from conflict situations - https://github.com/fsprojects/Paket/issues/1174
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ open Paket.Requirements
let ``#140 windsor should resolve framework dependent dependencies``() =
let lockFile = update "i000140-resolve-framework-restrictions"
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "TaskParallelLibrary"].Settings.FrameworkRestrictions
|> shouldEqual [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V3_5))]
|> shouldEqual [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V3_5))]

[<Test>]
let ``#1182 framework restrictions overwrite each other``() =
let lockFile = update "i001182-framework-restrictions"
let lockFile = lockFile.ToString()
lockFile.Contains("Microsoft.Data.OData (>= 5.6.2) ") |> shouldEqual true
lockFile.Contains("framework: winv4.5") |> shouldEqual false
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
framework: net452
content: none
redirects: off

source https://www.nuget.org/api/v2/
source https://nuget.bittitan.com/nuget/Components


nuget WindowsAzure.Storage 4.3.0
15 changes: 12 additions & 3 deletions src/Paket.Core/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ let calcOpenRequirements (exploredPackage:ResolvedPackage,globalFrameworkRestric
let rest = Set.remove dependency stillOpen

dependenciesByName
|> Set.map (fun (n, v, restriction) ->
|> Set.map (fun (n, v, restriction) ->
let newRestrictions =
filterRestrictions restriction exploredPackage.Settings.FrameworkRestrictions
|> filterRestrictions globalFrameworkRestrictions

{ dependency with Name = n
VersionRequirement = v
Parent = Package(dependency.Name, versionToExplore)
Expand Down Expand Up @@ -230,21 +231,29 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, stra
| _ -> tracefn " - %O %A" dependency.Name version

let packageDetails : PackageDetails = getPackageDetailsF sources dependency.Name version
let restrictedDependencies = DependencySetFilter.filterByRestrictions newRestrictions packageDetails.DirectDependencies
let settings =
match dependency.Parent with
| DependenciesFile(_) -> dependency.Settings
| Package(_) ->
match rootSettings.TryGetValue packageDetails.Name with
| true, s -> s + dependency.Settings
| _ -> dependency.Settings
|> fun s -> s.AdjustWithSpecialCases packageDetails.Name

let restrictedDependencies =
DependencySetFilter.filterByRestrictions newRestrictions packageDetails.DirectDependencies
|> Set.map (fun (n,v,r) ->
let r' =
filterRestrictions r settings.FrameworkRestrictions
|> filterRestrictions globalFrameworkRestrictions
(n,v,r'))

let explored =
{ Name = packageDetails.Name
Version = version
Dependencies = restrictedDependencies
Unlisted = packageDetails.Unlisted
Settings = settings.AdjustWithSpecialCases packageDetails.Name
Settings = settings
Source = packageDetails.Source }
exploredPackages.Add((dependency.Name,version),explored)
explored
Expand Down
10 changes: 5 additions & 5 deletions src/Paket.Core/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ let rec optimizeRestrictions restrictions =
let newRestrictions' =
restrictions
|> List.distinct
|> List.sort
|> List.sort

let newRestrictions =
match newRestrictions' |> Seq.tryFind (function | FrameworkRestriction.AtLeast r -> true | _ -> false) with
Expand All @@ -94,7 +94,7 @@ let rec optimizeRestrictions restrictions =
let currentVersion =
match r with
| FrameworkRestriction.AtLeast(DotNetFramework(x)) -> x
| x -> failwithf "Unknown .NET moniker %O" x
| x -> failwithf "Unknown .NET moniker %O" x

let isLowerVersion x =
let isMatching x =
Expand All @@ -115,7 +115,7 @@ let rec optimizeRestrictions restrictions =
match n with
| FrameworkRestriction.Exactly(DotNetFramework(x)) -> x
| FrameworkRestriction.AtLeast(DotNetFramework(x)) -> x
| x -> failwithf "Unknown .NET moniker %O" x
| x -> failwithf "Unknown .NET moniker %O" x

(newRestrictions'
|> List.filter (fun x -> x <> r && x <> n)) @ [FrameworkRestriction.AtLeast(DotNetFramework(newLowest))]
Expand Down Expand Up @@ -166,15 +166,15 @@ let optimizeDependencies packages =
|> List.sort

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

let dotnetRestrictions,others = List.partition (function | FrameworkRestriction.Exactly(DotNetFramework(_)) -> true | FrameworkRestriction.AtLeast(DotNetFramework(_)) -> true | _ -> false) plain

let restrictions' =
dotnetRestrictions
|> List.map (fun restriction ->
match restriction with
| FrameworkRestriction.Exactly r ->
| FrameworkRestriction.Exactly r ->
if r = localMaxDotNetRestriction && r = globalMax then
FrameworkRestriction.AtLeast r
else
Expand Down
2 changes: 1 addition & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<StartWorkingDirectory>d:\code\paketkopie</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\paketbug</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\paketrepro</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\Paket\integrationtests\scenarios\i001166-resolve-nancy-fast\temp</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\Paket\integrationtests\scenarios\i001182-framework-restrictions\temp</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
32 changes: 16 additions & 16 deletions tests/Paket.Tests/Lockfile/GeneratorSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ let ``should generate lock file with framework restrictions for packages``() =
specs:
Castle.Windsor (2.1) - framework: net35
Castle.Windsor-log4net (3.3) - framework: net35
Castle.Windsor (>= 2.0)
log4net (>= 1.0)
Castle.Windsor (>= 2.0) - framework: net35
log4net (>= 1.0) - framework: net35
log (1.2) - framework: net35
log4net (1.1) - framework: net35
log (>= 1.0)
log (>= 1.0) - framework: net35
Rx-Core (2.1) - framework: >= net40
Rx-Main (2.0) - framework: >= net40
Rx-Core (>= 2.1)"""
Rx-Core (>= 2.1) - framework: >= net40"""

let cfg = DependenciesFile.FromCode(configWithRestrictions)
ResolveWithGraph(cfg,noSha1,VersionsFromGraphAsSeq graph, PackageDetailsFromGraph graph).[Constants.MainDependencyGroup].ResolvedPackages.GetModelOrFail()
Expand All @@ -90,14 +90,14 @@ let ``should generate lock file with no targets import for packages``() =
specs:
Castle.Windsor (2.1) - import_targets: false, framework: net35
Castle.Windsor-log4net (3.3) - import_targets: false, framework: net35
Castle.Windsor (>= 2.0)
log4net (>= 1.0)
Castle.Windsor (>= 2.0) - framework: net35
log4net (>= 1.0) - framework: net35
log (1.2) - import_targets: false, framework: net35
log4net (1.1) - import_targets: false, framework: net35
log (>= 1.0)
log (>= 1.0) - framework: net35
Rx-Core (2.1) - framework: >= net40
Rx-Main (2.0) - framework: >= net40
Rx-Core (>= 2.1)"""
Rx-Core (>= 2.1) - framework: >= net40"""

let cfg = DependenciesFile.FromCode(configWithNoImport)
ResolveWithGraph(cfg,noSha1,VersionsFromGraphAsSeq graph, PackageDetailsFromGraph graph).[Constants.MainDependencyGroup].ResolvedPackages.GetModelOrFail()
Expand All @@ -117,14 +117,14 @@ let ``should generate lock file with no copy local for packages``() =
specs:
Castle.Windsor (2.1) - copy_local: false, import_targets: false, framework: net35
Castle.Windsor-log4net (3.3) - copy_local: false, import_targets: false, framework: net35
Castle.Windsor (>= 2.0)
log4net (>= 1.0)
Castle.Windsor (>= 2.0) - framework: net35
log4net (>= 1.0) - framework: net35
log (1.2) - copy_local: false, import_targets: false, framework: net35
log4net (1.1) - copy_local: false, import_targets: false, framework: net35
log (>= 1.0)
log (>= 1.0) - framework: net35
Rx-Core (2.1) - framework: >= net40
Rx-Main (2.0) - framework: >= net40
Rx-Core (>= 2.1)"""
Rx-Core (>= 2.1) - framework: >= net40"""
let cfg = DependenciesFile.FromCode(configWithCopyLocal)
ResolveWithGraph(cfg,noSha1,VersionsFromGraphAsSeq graph, PackageDetailsFromGraph graph).[Constants.MainDependencyGroup].ResolvedPackages.GetModelOrFail()
|> LockFileSerializer.serializePackages cfg.Groups.[Constants.MainDependencyGroup].Options
Expand All @@ -144,14 +144,14 @@ let ``should generate lock file with disabled content for packages``() =
specs:
Castle.Windsor (2.1) - framework: net35
Castle.Windsor-log4net (3.3) - framework: net35
Castle.Windsor (>= 2.0)
log4net (>= 1.0)
Castle.Windsor (>= 2.0) - framework: net35
log4net (>= 1.0) - framework: net35
log (1.2) - framework: net35
log4net (1.1) - framework: net35
log (>= 1.0)
log (>= 1.0) - framework: net35
Rx-Core (2.1) - content: none, framework: >= net40
Rx-Main (2.0) - content: none, framework: >= net40
Rx-Core (>= 2.1)"""
Rx-Core (>= 2.1) - framework: >= net40"""
let cfg = DependenciesFile.FromCode(configWithDisabledContent)
ResolveWithGraph(cfg,noSha1,VersionsFromGraphAsSeq graph, PackageDetailsFromGraph graph).[Constants.MainDependencyGroup].ResolvedPackages.GetModelOrFail()
|> LockFileSerializer.serializePackages cfg.Groups.[Constants.MainDependencyGroup].Options
Expand Down

0 comments on commit 2934794

Please sign in to comment.