Skip to content

Commit

Permalink
Create a "use exactly this" operator in order to override package con…
Browse files Browse the repository at this point in the history
…flicts - references #220
  • Loading branch information
forki committed Oct 6, 2014
1 parent 09f73da commit 2681e47
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.4.26 - 06.10.2014
* Create a "use exactly this" operator in order to override package conflicts - https://github.com/fsprojects/Paket/issues/220

#### 0.4.25 - 06.10.2014
* Throw if we don't get any versions

Expand Down
17 changes: 10 additions & 7 deletions src/Paket/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ let Resolve(getVersionsF, getPackageDetailsF, rootDependencies:PackageRequiremen
versions
| true,versions -> versions

let rec improveModel (filteredVersions,packages:ResolvedPackage list,closed:Set<PackageRequirement>,stillOpen:Set<PackageRequirement>) =
let rec improveModel (filteredVersions:Map<string , (SemVerInfo list * bool)>,packages:ResolvedPackage list,closed:Set<PackageRequirement>,stillOpen:Set<PackageRequirement>) =
if Set.isEmpty stillOpen then
let isOk =
filteredVersions
|> Map.forall (fun _ v ->
match v with
| [_] -> true
| [_],_ -> true
| _ -> false)

if isOk then
Expand All @@ -110,15 +110,18 @@ let Resolve(getVersionsF, getPackageDetailsF, rootDependencies:PackageRequiremen
let dependency = Seq.head stillOpen
let rest = stillOpen |> Set.remove dependency

let compatibleVersions =
let compatibleVersions,globalOverride =
match Map.tryFind dependency.Name filteredVersions with
| None ->
let versions = getAllVersions(dependency.Sources,dependency.Name)
if Seq.isEmpty versions then
failwithf "Couldn't retrieve versions for %s." dependency.Name
versions
| Some versions -> versions
|> List.filter dependency.VersionRequirement.IsInRange
if dependency.VersionRequirement.Range.IsGlobalOverride then
List.filter dependency.VersionRequirement.IsInRange versions,true
else
List.filter dependency.VersionRequirement.IsInRange versions,false
| Some(versions,globalOverride) ->
if globalOverride then versions,true else List.filter dependency.VersionRequirement.IsInRange versions,false

let sorted =
match dependency.Parent with
Expand All @@ -134,7 +137,7 @@ let Resolve(getVersionsF, getPackageDetailsF, rootDependencies:PackageRequiremen
match state with
| Conflict _ ->
let exploredPackage = getExploredPackage(dependency.Sources,dependency.Name,versionToExplore)
let newFilteredVersion = Map.add dependency.Name [versionToExplore] filteredVersions
let newFilteredVersion = Map.add dependency.Name ([versionToExplore],globalOverride) filteredVersions
let newDependencies =
exploredPackage.Dependencies
|> Set.map (fun (n,v) -> {dependency with Name = n; VersionRequirement = v; Parent = Package(dependency.Name,versionToExplore) })
Expand Down
5 changes: 3 additions & 2 deletions src/Paket/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ type PackageRequirement =
interface System.IComparable with
member this.CompareTo that =
match that with
| :? PackageRequirement as that -> compare (this.Parent,this.Name,this.VersionRequirement) (that.Parent,that.Name,that.VersionRequirement)
| _ -> invalidArg "that" "cannot compare value of different types"
| :? PackageRequirement as that ->
compare (not this.VersionRequirement.Range.IsGlobalOverride,this.Parent,this.Name,this.VersionRequirement) (not that.VersionRequirement.Range.IsGlobalOverride,that.Parent,that.Name,that.VersionRequirement)
| _ -> invalidArg "that" "cannot compare value of different types"
5 changes: 5 additions & 0 deletions src/Paket/VersionRange.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type PreReleaseStatus =

/// Represents version information.
type VersionRange =
| OverrideAll of SemVerInfo
| Specific of SemVerInfo
| Minimum of SemVerInfo
| GreaterThan of SemVerInfo
Expand All @@ -26,6 +27,8 @@ type VersionRange =

static member Between(version1,version2) = Range(Including, SemVer.parse version1, SemVer.parse version2, Excluding)

member x.IsGlobalOverride = match x with | OverrideAll _ -> true | _ -> false

type VersionRequirement =
| VersionRequirement of VersionRange * PreReleaseStatus
/// Checks wether the given version is in the version range
Expand All @@ -43,6 +46,7 @@ type VersionRequirement =

match range with
| Specific v -> v = version
| OverrideAll v -> v = version
| Minimum v -> v = version || (v <= version && checkPrerelease prerelease version)
| GreaterThan v -> v < version && checkPrerelease prerelease version
| Maximum v -> v = version || (v >= version && checkPrerelease prerelease version)
Expand Down Expand Up @@ -74,6 +78,7 @@ type VersionRequirement =
override this.ToString() =
match this.Range with
| Specific v -> v.ToString()
| OverrideAll v -> "== " + v.ToString()
| Minimum v -> ">= " + v.ToString()
| GreaterThan v -> "> " + v.ToString()
| Maximum v -> "<= " + v.ToString()
Expand Down
13 changes: 12 additions & 1 deletion tests/Paket.Tests/Resolver/ConflictGraphSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@ let ``should analyze graph2 and report conflict``() =
| Conflict(_,stillOpen) ->
let conflicting = stillOpen |> Seq.head
conflicting.Name |> shouldEqual "D"
conflicting.VersionRequirement.Range |> shouldEqual (VersionRange.Between("1.6", "1.7"))
conflicting.VersionRequirement.Range |> shouldEqual (VersionRange.Between("1.6", "1.7"))

[<Test>]
let ``should override graph2 conflict to first version``() =
let resolved = resolve graph2 ["A",VersionRange.AtLeast "1.0"; "D",VersionRange.OverrideAll(SemVer.parse "1.4")]
getVersion resolved.["D"] |> shouldEqual "1.4"


[<Test>]
let ``should override graph2 conflict to second version``() =
let resolved = resolve graph2 ["A",VersionRange.AtLeast "1.0"; "D",VersionRange.OverrideAll(SemVer.parse "1.6")]
getVersion resolved.["D"] |> shouldEqual "1.6"

0 comments on commit 2681e47

Please sign in to comment.