Permalink
Browse files

Fixes bug in resolver we package required a non-existant package

  • Loading branch information...
forki committed Mar 22, 2016
1 parent f6a36e9 commit 3b4425f1e3a35f65f72dcf2abaea0a784fbb9b51
Showing with 58 additions and 44 deletions.
  1. +47 −43 src/Paket.Core/PackageResolver.fs
  2. +11 −1 tests/Paket.Tests/Resolver/DependencyGraphSpecs.fs
@@ -249,7 +249,7 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, glob
let package = { package with Settings = { package.Settings with FrameworkRestrictions = FrameworkRestrictionList newRestrictions } }
exploredPackages.[key] <- package
package
Some package
| false,_ ->
match updateMode with
| Install -> tracefn " - %O %A" dependency.Name version
@@ -260,28 +260,31 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, glob
let newRestrictions = filterRestrictions dependency.Settings.FrameworkRestrictions globalFrameworkRestrictions
let packageDetails : PackageDetails = getPackageDetailsF packageSources dependency.Name version
let filteredDependencies = 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
let settings = settings.AdjustWithSpecialCases packageDetails.Name
let explored =
{ Name = packageDetails.Name
Version = version
Dependencies = filteredDependencies
Unlisted = packageDetails.Unlisted
Settings = settings
Source = packageDetails.Source }
exploredPackages.Add(key,explored)
explored
try
let packageDetails : PackageDetails = getPackageDetailsF packageSources dependency.Name version
let filteredDependencies = 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
let settings = settings.AdjustWithSpecialCases packageDetails.Name
let explored =
{ Name = packageDetails.Name
Version = version
Dependencies = filteredDependencies
Unlisted = packageDetails.Unlisted
Settings = settings
Source = packageDetails.Source }
exploredPackages.Add(key,explored)
Some explored
with
| _ -> None
let getCompatibleVersions(relax,filteredVersions:Map<PackageName, ((SemVerInfo * PackageSource list) list * bool)>,openRequirements:Set<PackageRequirement>,currentRequirement:PackageRequirement) =
verbosefn " Trying to resolve %O" currentRequirement
@@ -460,32 +463,33 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, glob
trial := !trial + 1
let versionToExplore = Seq.head !versionsToExplore
versionsToExplore := Seq.tail !versionsToExplore
let exploredPackage = getExploredPackage(currentRequirement,versionToExplore)
if exploredPackage.Unlisted && not !useUnlisted then
()
else
let newFilteredVersions = Map.add currentRequirement.Name ([versionToExplore],globalOverride) filteredVersions
match getExploredPackage(currentRequirement,versionToExplore) with
| None -> ()
| Some exploredPackage ->
if exploredPackage.Unlisted && not !useUnlisted then
()
else
let newFilteredVersions = Map.add currentRequirement.Name ([versionToExplore],globalOverride) filteredVersions
let newOpen = calcOpenRequirements(exploredPackage,globalFrameworkRestrictions,versionToExplore,currentRequirement,closedRequirements,openRequirements)
if newOpen = openRequirements then
failwithf "The resolver confused itself. The new open requirements are the same as the old ones. This will result in an endless loop.%sCurrent Requirement: %A%sRequirements: %A" Environment.NewLine currentRequirement Environment.NewLine newOpen
let newOpen = calcOpenRequirements(exploredPackage,globalFrameworkRestrictions,versionToExplore,currentRequirement,closedRequirements,openRequirements)
if newOpen = openRequirements then
failwithf "The resolver confused itself. The new open requirements are the same as the old ones. This will result in an endless loop.%sCurrent Requirement: %A%sRequirements: %A" Environment.NewLine currentRequirement Environment.NewLine newOpen
let newResolution = Map.add exploredPackage.Name exploredPackage currentResolution
let newResolution = Map.add exploredPackage.Name exploredPackage currentResolution
let newClosed = Set.add currentRequirement closedRequirements
let newClosed = Set.add currentRequirement closedRequirements
state := step (relax,newFilteredVersions,newResolution,newClosed,newOpen)
state := step (relax,newFilteredVersions,newResolution,newClosed,newOpen)
match !state with
| Resolution.Conflict(resolved,closed,stillOpen,conflicts,lastPackageRequirement,getVersionF)
when
(Set.isEmpty conflicts |> not) &&
(conflicts |> Set.exists (fun r -> r = currentRequirement || r.Graph |> List.contains currentRequirement) |> not) ->
forceBreak := true
| _ -> ()
match !state with
| Resolution.Conflict(resolved,closed,stillOpen,conflicts,lastPackageRequirement,getVersionF)
when
(Set.isEmpty conflicts |> not) &&
(conflicts |> Set.exists (fun r -> r = currentRequirement || r.Graph |> List.contains currentRequirement) |> not) ->
forceBreak := true
| _ -> ()
allUnlisted := exploredPackage.Unlisted && !allUnlisted
allUnlisted := exploredPackage.Unlisted && !allUnlisted
if not !useUnlisted && !allUnlisted && not (isOk()) then
useUnlisted := true
@@ -111,4 +111,14 @@ let ``should report missing top-level versions``() =
failwith "expected error"
with exn ->
if not <| exn.Message.Contains("package A") then
reraise()
reraise()
let graphWithMissingDependency = [
"P44","9.44.25", []
"P44","43.24.27.26", ["P33",VersionRequirement(VersionRange.Exactly "21.30.42",PreReleaseStatus.No)]
]
[<Test>]
let ``should solve graph with missing specific dependency``() =
let resolved = resolve graphWithMissingDependency ["P44",VersionRange.AtLeast "9.44.25" ]
getVersion resolved.[PackageName "P44"] |> shouldEqual "9.44.25"

0 comments on commit 3b4425f

Please sign in to comment.