Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow transitive deps - fixes #2557 #2559

Merged
merged 22 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3')">
<ItemGroup>
<Reference Include="Microsoft.Diagnostics.Tracing.EventSource">
<HintPath>..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist\lib\net40\Microsoft.Diagnostics.Tracing.EventSource.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7')">
<ItemGroup>
<Reference Include="Microsoft.Diagnostics.Tracing.EventSource">
<HintPath>..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist\lib\net46\Microsoft.Diagnostics.Tracing.EventSource.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7')">
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Paket.Core/Dependencies/DependenciesFileParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ module DependenciesFileParser =
Graph = Set.empty
Sources = sources
Settings = InstallSettings.Parse(optionsText).AdjustWithSpecialCases packageName
TransitivePrereleases = versionRequirement.PreReleases <> PreReleaseStatus.No
VersionRequirement = versionRequirement
IsCliTool = isCliTool }

Expand Down
55 changes: 26 additions & 29 deletions src/Paket.Core/Dependencies/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ type ResolvedPackage = {

type PackageResolution = Map<PackageName, ResolvedPackage>

type ResolverStep = {
Relax: bool
FilteredVersions : Map<PackageName, ((SemVerInfo * PackageSource list) list * bool)>
CurrentResolution : Map<PackageName,ResolvedPackage>;
ClosedRequirements : Set<PackageRequirement>
OpenRequirements : Set<PackageRequirement> }

module DependencySetFilter =
let isIncluded (restriction:FrameworkRestriction) (dependency:PackageName * VersionRequirement * FrameworkRestrictions) =
let _,_,dependencyRestrictions = dependency
Expand All @@ -80,16 +87,19 @@ module DependencySetFilter =
dependencies
|> Set.filter (isIncluded restrictions)

let isPackageCompatible specialPrereleaseSettings (dependencies:DependencySet) (package:ResolvedPackage) : bool =
let prereleaseStatus = specialPrereleaseSettings |> Set.contains package.Name
let isPackageCompatible (currentStep:ResolverStep) (dependencies:DependencySet) (package:ResolvedPackage) : bool =
dependencies
// exists any non-matching stuff
|> Seq.filter (fun (name, _, _) -> name = package.Name)
|> Seq.exists (fun (name, requirement, restriction) ->
if name = package.Name && not (requirement.IsInRange (package.Version, prereleaseStatus)) then
let allowTransitivePreleases =
(currentStep.ClosedRequirements |> Set.exists (fun r -> r.TransitivePrereleases && r.Name = name)) ||
(currentStep.OpenRequirements |> Set.exists (fun r -> r.TransitivePrereleases && r.Name = name))

if not (requirement.IsInRange (package.Version, allowTransitivePreleases)) then
tracefn " Incompatible dependency: %O %O conflicts with resolved version %O" name requirement package.Version
true
else false
)
else false)
|> not // then we are not compatible


Expand All @@ -102,12 +112,7 @@ let cleanupNames (model : PackageResolution) : PackageResolution =
|> Set.map (fun (name, v, d) -> model.[name].Name, v, d) })


type ResolverStep = {
Relax: bool
FilteredVersions : Map<PackageName, ((SemVerInfo * PackageSource list) list * bool)>
CurrentResolution : Map<PackageName,ResolvedPackage>;
ClosedRequirements : Set<PackageRequirement>
OpenRequirements : Set<PackageRequirement> }


type ConflictInfo =
{ ResolveStep : ResolverStep
Expand Down Expand Up @@ -305,6 +310,7 @@ let calcOpenRequirements (exploredPackage:ResolvedPackage,globalFrameworkRestric
VersionRequirement = v
Parent = Package(dependency.Name, versionToExplore, exploredPackage.Source)
Graph = Set.add dependency dependency.Graph
TransitivePrereleases = dependency.TransitivePrereleases && exploredPackage.Version.PreRelease.IsSome
Settings = { dependency.Settings with FrameworkRestrictions = newRestrictions } })
|> Set.filter (fun d ->
resolverStep.ClosedRequirements
Expand Down Expand Up @@ -509,25 +515,29 @@ let private getCompatibleVersions
let availableVersions =
match currentRequirement.VersionRequirement.Range with
| OverrideAll v -> getSingleVersion v
| Specific v -> getSingleVersion v
| Specific v -> getSingleVersion v
| _ ->
let resolverStrategy = getResolverStrategy globalStrategyForDirectDependencies globalStrategyForTransitives allRequirementsOfCurrentPackage currentRequirement
getVersionsF currentRequirement.Sources resolverStrategy groupName currentRequirement.Name

let compatibleVersions = Seq.filter (isInRange id) availableVersions |> Seq.cache

let compatibleVersions = Seq.filter (isInRange id) (availableVersions) |> Seq.cache
let compatibleVersions, globalOverride =
if currentRequirement.VersionRequirement.Range.IsGlobalOverride then
compatibleVersions, true
elif Seq.isEmpty compatibleVersions && currentRequirement.TransitivePrereleases && not (currentRequirement.Parent.IsRootRequirement()) then
Seq.filter (isInRange (fun r -> r.IncludingPrereleases(PreReleaseStatus.All))) availableVersions |> Seq.cache, globalOverride
elif Seq.isEmpty compatibleVersions then

let prereleaseStatus (r:PackageRequirement) =
if r.Parent.IsRootRequirement() && r.VersionRequirement <> VersionRequirement.AllReleases then
r.VersionRequirement.PreReleases
else
PreReleaseStatus.All

let available = availableVersions |> Seq.toList
let allPrereleases = available |> List.filter (fun (v,_) -> v.PreRelease <> None) = available
let prereleases = List.filter (isInRange (fun r -> r.IncludingPrereleases(prereleaseStatus r))) available
let allPrereleases = prereleases |> List.filter (fun (v,_) -> v.PreRelease <> None) = prereleases
if allPrereleases then
Seq.ofList prereleases, globalOverride
else
Expand Down Expand Up @@ -629,7 +639,7 @@ let private boostConflicts
(stackpack:StackPack)
(conflictState:ConflictState) =
let conflictStatus = conflictState.Status
let isNewConflict =
let isNewConflict =
match stackpack.ConflictHistory.TryGetValue currentRequirement.Name with
| true,count ->
stackpack.ConflictHistory.[currentRequirement.Name] <- count + 1
Expand Down Expand Up @@ -832,17 +842,6 @@ let WorkerCount = 6
let Resolve (getVersionsRaw, getPreferredVersionsRaw, getPackageDetailsRaw, groupName:GroupName, globalStrategyForDirectDependencies, globalStrategyForTransitives, globalFrameworkRestrictions, (rootDependencies:PackageRequirement Set), updateMode : UpdateMode) =
tracefn "Resolving packages for group %O:" groupName

let specialPrereleaseSettings =
rootDependencies
|> Seq.choose (fun r ->
match r.Parent with
| PackageRequirementSource.DependenciesFile _ ->
match r.VersionRequirement.PreReleases with
| PreReleaseStatus.No -> None
| _ -> Some r.Name
| _ -> None)
|> Set.ofSeq

let cliToolSettings =
rootDependencies
|> Seq.choose (fun r ->
Expand Down Expand Up @@ -1182,8 +1181,6 @@ let Resolve (getVersionsRaw, getPreferredVersionsRaw, getPackageDetailsRaw, grou
tracefn " %O %O was unlisted" exploredPackage.Name exploredPackage.Version
step (Inner ((currentConflict,currentStep,currentRequirement), priorConflictSteps)) stackpack compatibleVersions flags
else


// It might be that this version is already not possible because of our current set.
// Example: We took A with version 1.0.0 (in our current resolution), but this version depends on A > 1.0.0
let canTakePackage =
Expand All @@ -1192,7 +1189,7 @@ let Resolve (getVersionsRaw, getPreferredVersionsRaw, getPackageDetailsRaw, grou
|> Seq.map snd
// Ignore packages which have "OverrideAll", otherwise == will not work anymore.
|> Seq.filter (fun resolved -> lockedPackages.Contains resolved.Name |> not)
|> Seq.forall (DependencySetFilter.isPackageCompatible specialPrereleaseSettings exploredPackage.Dependencies)
|> Seq.forall (DependencySetFilter.isPackageCompatible currentStep exploredPackage.Dependencies)

if canTakePackage then
let nextStep =
Expand Down
1 change: 1 addition & 0 deletions src/Paket.Core/PackageManagement/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ let createPackageRequirement sources (packageName, versionRange, restrictions) d
Parent = PackageRequirementSource.DependenciesFile dependenciesFileName
Sources = sources
IsCliTool = false
TransitivePrereleases = false
Graph = Set.empty }

let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode =
Expand Down
3 changes: 3 additions & 0 deletions src/Paket.Core/PaketConfigFiles/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
Graph = Set.empty
Sources = group.Sources
IsCliTool = false
TransitivePrereleases = v.PreReleases <> PreReleaseStatus.No
Settings = group.Options.Settings })
|> Seq.toList

Expand Down Expand Up @@ -283,6 +284,7 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
Graph = Set.empty
Sources = group.Sources
IsCliTool = false
TransitivePrereleases = versionReq.PreReleases <> PreReleaseStatus.No
Settings = group.Options.Settings })
|> Seq.toList

Expand Down Expand Up @@ -310,6 +312,7 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
Graph = Set.empty
Sources = group.Sources
IsCliTool = false
TransitivePrereleases = true
Settings =
match oldDepsInfo with
| Some d -> d.Settings
Expand Down
5 changes: 5 additions & 0 deletions src/Paket.Core/Versioning/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ type PackageRequirement =
Parent: PackageRequirementSource
Graph: PackageRequirement Set
Sources: PackageSource list
TransitivePrereleases: bool
IsCliTool : bool
Settings: InstallSettings }

Expand All @@ -904,6 +905,8 @@ type PackageRequirement =
this.ResolverStrategyForTransitives = that.ResolverStrategyForTransitives &&
this.ResolverStrategyForDirectDependencies = that.ResolverStrategyForDirectDependencies &&
this.Settings.FrameworkRestrictions = that.Settings.FrameworkRestrictions &&
this.TransitivePrereleases = that.TransitivePrereleases &&
this.IsCliTool = that.IsCliTool &&
this.Parent = that.Parent
| _ -> false

Expand Down Expand Up @@ -943,6 +946,8 @@ type PackageRequirement =
if c <> 0 then c else
let c = compare x.Name y.Name
if c <> 0 then c else
let c = compare x.TransitivePrereleases y.TransitivePrereleases
if c <> 0 then c else
let c = compare x.Settings.FrameworkRestrictions y.Settings.FrameworkRestrictions
if c <> 0 then c else 0

Expand Down
4 changes: 2 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartAction>Project</StartAction>
<StartArguments>-v push file nuget/legacy/FAKE.5.0.0-alpha012.nupkg</StartArguments>
<StartWorkingDirectory>C:\proj\FAKE\</StartWorkingDirectory>
<StartArguments>update</StartArguments>
<StartWorkingDirectory>D:\temp\test</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let require packageName strategyForTransitives text : PackageRequirement =
Graph = Set.empty
Sources = []
IsCliTool = false
TransitivePrereleases = false
Settings = InstallSettings.Default }

[<Test>]
Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/Resolver/ConflictGraphSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let defaultPackage =
VersionRequirement = VersionRequirement(VersionRange.Exactly "1.0", PreReleaseStatus.No)
Settings = InstallSettings.Default
IsCliTool = false
TransitivePrereleases = false
ResolverStrategyForDirectDependencies = Some ResolverStrategy.Max
ResolverStrategyForTransitives = Some ResolverStrategy.Max }

Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/Resolver/ConflictSourcesSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let ``should resolve source files with correct sha``() =
ResolverStrategyForTransitives = Some ResolverStrategy.Max
Graph = Set.empty
Sources = []
TransitivePrereleases = false
Parent = Requirements.PackageRequirementSource.DependenciesFile ""
Settings = InstallSettings.Default
IsCliTool = false
Expand Down
Loading