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

Selective update resolves the graph for selected package #957

Merged
merged 12 commits into from
Aug 4, 2015
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
20 changes: 16 additions & 4 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,21 @@ type DependenciesFile(fileName,options,sources,packages : PackageRequirement lis
member __.FileName = fileName
member __.Lines = textRepresentation
member __.Sources = sources
member this.Resolve(force) =

member this.Resolve(force,packages) =
let getSha1 origin owner repo branch = RemoteDownload.getSHA1OfBranch origin owner repo branch |> Async.RunSynchronously
let root = Path.GetDirectoryName this.FileName
this.Resolve(getSha1,NuGetV2.GetVersions root,NuGetV2.GetPackageDetails root force)
this.Resolve(getSha1,NuGetV2.GetVersions root,NuGetV2.GetPackageDetails root force,packages)

member this.Resolve(force) =
this.Resolve(force,Some packages)

member __.Resolve(getSha1,getVersionF, getPackageDetailsF,rootDependencies) =
let rootDependencies =
match rootDependencies with
| None -> packages
| Some d -> d

member __.Resolve(getSha1,getVersionF, getPackageDetailsF) =
let resolveSourceFile(file:ResolvedSourceFile) : PackageRequirement list =
let parserF text =
try
Expand All @@ -339,9 +348,12 @@ type DependenciesFile(fileName,options,sources,packages : PackageRequirement lis
VersionRequirement = v })
|> Seq.toList

{ ResolvedPackages = PackageResolver.Resolve(getVersionF, getPackageDetailsF, options.Settings.FrameworkRestrictions, remoteDependencies @ packages)
{ ResolvedPackages = PackageResolver.Resolve(getVersionF, getPackageDetailsF, options.Settings.FrameworkRestrictions, remoteDependencies @ rootDependencies, Set.ofList packages)
ResolvedSourceFiles = remoteFiles }

member __.Resolve(getSha1,getVersionF, getPackageDetailsF) =
__.Resolve(getSha1,getVersionF,getPackageDetailsF,Some packages)

member __.AddAdditionalPackage(packageName:PackageName,versionRequirement,resolverStrategy,settings,?pinDown) =
let pinDown = defaultArg pinDown false
let packageString = DependenciesFileSerializer.packageString packageName versionRequirement resolverStrategy settings
Expand Down
6 changes: 4 additions & 2 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ module LockFileParser =
Settings = InstallSettings.Parse(optionsString)
Version = SemVer.Parse version } :: state.Packages }
| None -> failwith "no source has been specified."
| NugetDependency (name, _) ->
| NugetDependency (name, v) ->
let parts = v.Split([|" - "|],StringSplitOptions.None)
let version = parts.[0]
if state.LastWasPackage then
match state.Packages with
| currentPackage :: otherPackages ->
{ state with
Packages = { currentPackage with
Dependencies = Set.add (PackageName name, VersionRequirement.AllReleases, []) currentPackage.Dependencies
Dependencies = Set.add (PackageName name, DependenciesFileParser.parseVersionRequirement version, []) currentPackage.Dependencies
} :: otherPackages }
| [] -> failwith "cannot set a dependency - no package has been specified."
else
Expand Down
15 changes: 13 additions & 2 deletions src/Paket.Core/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type Resolved = {
ResolvedSourceFiles : ModuleResolver.ResolvedSourceFile list }

/// Resolves all direct and transitive dependencies
let Resolve(getVersionsF, getPackageDetailsF, globalFrameworkRestrictions, rootDependencies:PackageRequirement list) =
let Resolve(getVersionsF, getPackageDetailsF, globalFrameworkRestrictions, rootDependencies, (requirements : Set<PackageRequirement>)) =
tracefn "Resolving packages:"
let exploredPackages = Dictionary<NormalizedPackageName*SemVerInfo,ResolvedPackage>()
let allVersions = Dictionary<NormalizedPackageName,SemVerInfo list>()
Expand Down Expand Up @@ -244,8 +244,19 @@ let Resolve(getVersionsF, getPackageDetailsF, globalFrameworkRestrictions, rootD
match Map.tryFind currentRequirement.Name filteredVersions with
| None ->
// we didn't select a version yet so all versions are possible

let requirement =
requirements
|> Seq.tryFind (fun r -> NormalizedPackageName currentRequirement.Name = NormalizedPackageName r.Name)

let isInRange ver =
let inRange = currentRequirement.VersionRequirement.IsInRange(ver)
match requirement with
| None -> inRange
| Some requirement -> inRange && requirement.VersionRequirement.IsInRange(ver)

availableVersions := getAllVersions(currentRequirement.Sources,currentRequirement.Name,currentRequirement.VersionRequirement.Range)
compatibleVersions := List.filter currentRequirement.VersionRequirement.IsInRange (!availableVersions)
compatibleVersions := List.filter isInRange (!availableVersions)
if currentRequirement.VersionRequirement.Range.IsGlobalOverride then
globalOverride := true
else
Expand Down
70 changes: 56 additions & 14 deletions src/Paket.Core/UpdateProcess.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Contains methods for the update process.
/// Contains methods for the update process.
module Paket.UpdateProcess

open Paket
Expand Down Expand Up @@ -46,25 +46,67 @@ let addPackagesFromReferenceFiles projects (dependenciesFile : DependenciesFile)
newDependenciesFile.Save()
newDependenciesFile

let SelectiveUpdate(dependenciesFile : DependenciesFile, updateAll, exclude, force) =
let lockFileName = DependenciesFile.FindLockfile dependenciesFile.FileName
let selectiveUpdate resolve lockFile dependenciesFile updateAll package =
let install () =
let changedDependencies = DependencyChangeDetection.findChangesInDependenciesFile(dependenciesFile,lockFile)
let dependenciesFile = DependencyChangeDetection.PinUnchangedDependencies dependenciesFile lockFile Set.empty
resolve dependenciesFile None

let selectiveUpdate package =
let selectiveResolution =
dependenciesFile.Packages
|> List.filter (fun p -> package = NormalizedPackageName p.Name)
|> Some
|> resolve dependenciesFile

let merge destination source =
Map.fold (fun acc key value -> Map.add key value acc) destination source

let resolution =
let resolvedPackages =
selectiveResolution.ResolvedPackages.GetModelOrFail()
|> merge lockFile.ResolvedPackages

let dependencies =
resolvedPackages
|> Seq.map (fun d -> d.Value.Dependencies |> Seq.map (fun (n,_,_) -> n))
|> Seq.concat
|> Set.ofSeq

let isDirectDependency package =
dependenciesFile.DirectDependencies
|> Map.exists (fun p _ -> NormalizedPackageName p = package)

let isTransitiveDependency package =
dependencies
|> Set.exists (fun p -> NormalizedPackageName p = package)

resolvedPackages
|> Map.filter (fun p _ -> isDirectDependency p || isTransitiveDependency p)

{ ResolvedPackages = Resolution.Ok(resolution); ResolvedSourceFiles = lockFile.SourceFiles }

let resolution =
if not lockFileName.Exists || updateAll then
dependenciesFile.Resolve(force)
if updateAll then
resolve dependenciesFile None
else
let oldLockFile = LockFile.LoadFrom(lockFileName.FullName)
let changedDependencies = DependencyChangeDetection.findChangesInDependenciesFile(dependenciesFile,oldLockFile)
match package with
| None -> install ()
| Some package -> selectiveUpdate package

let changed =
match exclude with
| None -> changedDependencies
| Some package -> Set.add package changedDependencies
LockFile(lockFile.FileName, dependenciesFile.Options, resolution.ResolvedPackages.GetModelOrFail(), resolution.ResolvedSourceFiles)

let dependenciesFile = DependencyChangeDetection.PinUnchangedDependencies dependenciesFile oldLockFile changed
let SelectiveUpdate(dependenciesFile : DependenciesFile, updateAll, exclude, force) =
let lockFileName = DependenciesFile.FindLockfile dependenciesFile.FileName
let oldLockFile =
if not lockFileName.Exists then
LockFile.Parse(lockFileName.FullName, [||])
else
LockFile.LoadFrom lockFileName.FullName

dependenciesFile.Resolve(force)
LockFile.Create(lockFileName.FullName, dependenciesFile.Options, resolution.ResolvedPackages, resolution.ResolvedSourceFiles)
let lockFile = selectiveUpdate (fun d p -> d.Resolve(force, p)) oldLockFile dependenciesFile updateAll exclude
lockFile.Save()
lockFile

/// Smart install command
let SmartInstall(dependenciesFileName, updateAll, exclude, options : UpdaterOptions) =
Expand Down
6 changes: 3 additions & 3 deletions tests/Paket.Tests/Lockfile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ let ``should parse lock file``() =
packages.[1].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[1].Name |> shouldEqual (PackageName "Castle.Windsor-log4net")
packages.[1].Version |> shouldEqual (SemVer.Parse "3.3")
packages.[1].Dependencies |> shouldEqual (Set.ofList [PackageName "Castle.Windsor", VersionRequirement.AllReleases, []; PackageName "log4net", VersionRequirement.AllReleases, []])
packages.[1].Dependencies |> shouldEqual (Set.ofList [PackageName "Castle.Windsor", VersionRequirement(Minimum(SemVer.Parse "2.0"), PreReleaseStatus.No), []; PackageName "log4net", VersionRequirement(Minimum(SemVer.Parse "1.0"), PreReleaseStatus.No), []])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did these tests change?


packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "log4net")
packages.[5].Version |> shouldEqual (SemVer.Parse "1.1")
packages.[5].Dependencies |> shouldEqual (Set.ofList [PackageName "log", VersionRequirement.AllReleases, []])
packages.[5].Dependencies |> shouldEqual (Set.ofList [PackageName "log", VersionRequirement(Minimum(SemVer.Parse "1.0"), PreReleaseStatus.No), []])

let sourceFiles = List.rev lockFile.SourceFiles
sourceFiles|> shouldEqual
Expand Down Expand Up @@ -103,7 +103,7 @@ let ``should parse strict lock file``() =
packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "log4net")
packages.[5].Version |> shouldEqual (SemVer.Parse "1.1")
packages.[5].Dependencies |> shouldEqual (Set.ofList [PackageName "log", VersionRequirement.AllReleases, []])
packages.[5].Dependencies |> shouldEqual (Set.ofList [PackageName "log", VersionRequirement(Minimum(SemVer.Parse "1.0"), PreReleaseStatus.No), []])

let redirectsLockFile = """REDIRECTS: ON
IMPORT-TARGETS: TRUE
Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
</Content>
<Compile Include="PackagesConfig\ReadConfig.fs" />
<Compile Include="PackagesConfig\WriteConfig.fs" />
<Compile Include="UpdateProcessSpecs.fs" />
<Compile Include="RemotePushUrlSpecs.fs" />
<Content Include="Nuspec\FSharp.Data.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let safeResolve graph (dependencies : (string * VersionRange) list) =
Parent = PackageRequirementSource.DependenciesFile ""
Settings = InstallSettings.Default
ResolverStrategy = ResolverStrategy.Max })
PackageResolver.Resolve(VersionsFromGraph graph, PackageDetailsFromGraph graph, [], packages)
PackageResolver.Resolve(VersionsFromGraph graph, PackageDetailsFromGraph graph, [], packages, Set.empty)

let resolve graph dependencies = (safeResolve graph dependencies).GetModelOrFail()

Expand Down
Loading