From a2977e1e359e5f16acfa872f5091966c6e4536e4 Mon Sep 17 00:00:00 2001 From: Marcio Rinaldi Date: Fri, 16 Oct 2015 14:45:53 -0300 Subject: [PATCH] Fixes lock file restrictions parsing --- src/Paket.Core/LockFile.fs | 28 ++++++++++++----------- tests/Paket.Tests/Lockfile/ParserSpecs.fs | 28 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/Paket.Core/LockFile.fs b/src/Paket.Core/LockFile.fs index 0fb34b6a99..af7305f8e0 100644 --- a/src/Paket.Core/LockFile.fs +++ b/src/Paket.Core/LockFile.fs @@ -208,6 +208,16 @@ module LockFileParser = let Parse(lockFileLines) = let remove textToRemove (source:string) = source.Replace(textToRemove, "") let removeBrackets = remove "(" >> remove ")" + let parsePackage (s : string) = + let parts = s.Split([|" - "|],StringSplitOptions.None) + let optionsString = + if parts.Length < 2 then "" else + if parts.[1] <> "" && parts.[1].Contains(":") |> not then + ("framework: " + parts.[1]) // TODO: This is for backwards-compat and should be removed later + else + parts.[1] + parts.[0],InstallSettings.Parse(optionsString) + ([{ GroupName = Constants.MainDependencyGroup; RepositoryType = None; RemoteUrl = None; Packages = []; SourceFiles = []; Options = InstallOptions.Default; LastWasPackage = false }], lockFileLines) ||> Seq.fold(fun state line -> match state with @@ -234,15 +244,9 @@ module LockFileParser = | NugetPackage details -> match currentGroup.RemoteUrl with | Some remote -> - let parts = details.Split([|" - "|],StringSplitOptions.None) - let parts' = parts.[0].Split ' ' + let package,settings = parsePackage details + let parts' = package.Split ' ' let version = parts'.[1] |> removeBrackets - let optionsString = - if parts.Length < 2 then "" else - if parts.[1] <> "" && parts.[1].Contains(":") |> not then - ("framework: " + parts.[1]) // TODO: This is for backwards-compat and should be removed later - else - parts.[1] { currentGroup with LastWasPackage = true @@ -251,19 +255,17 @@ module LockFileParser = Name = PackageName parts'.[0] Dependencies = Set.empty Unlisted = false - Settings = InstallSettings.Parse(optionsString) + Settings = settings Version = SemVer.Parse version } :: currentGroup.Packages }::otherGroups | None -> failwith "no source has been specified." | NugetDependency (name, v) -> - let parts = v.Split([|" - "|],StringSplitOptions.None) - let version = parts.[0] - let restrictions = if parts.Length <= 1 then [] else parseRestrictions parts.[1] + let version,settings = parsePackage v if currentGroup.LastWasPackage then match currentGroup.Packages with | currentPackage :: otherPackages -> { currentGroup with Packages = { currentPackage with - Dependencies = Set.add (PackageName name, DependenciesFileParser.parseVersionRequirement version, restrictions) currentPackage.Dependencies + Dependencies = Set.add (PackageName name, DependenciesFileParser.parseVersionRequirement version, settings.FrameworkRestrictions) currentPackage.Dependencies } :: otherPackages } ::otherGroups | [] -> failwithf "cannot set a dependency to %s %s - no package has been specified." name v else diff --git a/tests/Paket.Tests/Lockfile/ParserSpecs.fs b/tests/Paket.Tests/Lockfile/ParserSpecs.fs index d91e4e381e..c26dca3ae9 100644 --- a/tests/Paket.Tests/Lockfile/ParserSpecs.fs +++ b/tests/Paket.Tests/Lockfile/ParserSpecs.fs @@ -273,12 +273,26 @@ let ``should parse framework restricted lock file``() = let packages = List.rev lockFile.Packages packages.Length |> shouldEqual 7 + packages.[0].Dependencies |> Set.toList |> List.map (fun (_, _, r) -> r) + |> List.item 2 + |> shouldEqual ([FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client))]) + packages.[3].Source |> shouldEqual PackageSources.DefaultNugetSource packages.[3].Name |> shouldEqual (PackageName "LinqBridge") packages.[3].Version |> shouldEqual (SemVer.Parse "1.3.0") packages.[3].Settings.FrameworkRestrictions |> shouldEqual ([FrameworkRestriction.Between(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2),FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))]) packages.[3].Settings.ImportTargets |> shouldEqual None + let dependencies4 = + packages.[4].Dependencies |> Set.toList |> List.map (fun (_, _, r) -> r) + + dependencies4.Head + |> shouldEqual ([FrameworkRestriction.Between(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2), FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))]) + dependencies4.Tail.Head + |> shouldEqual ([FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2)) + FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5)) + FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client))]) + packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource packages.[5].Name |> shouldEqual (PackageName "ReadOnlyCollectionInterfaces") packages.[5].Version |> shouldEqual (SemVer.Parse "1.0.0") @@ -312,6 +326,10 @@ let ``should parse framework restricted lock file in new syntax``() = let packages = List.rev lockFile.Packages packages.Length |> shouldEqual 7 + packages.[0].Dependencies |> Set.toList |> List.map (fun (_, _, r) -> r) + |> List.item 2 + |> shouldEqual ([FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client))]) + packages.[3].Source |> shouldEqual PackageSources.DefaultNugetSource packages.[3].Name |> shouldEqual (PackageName "LinqBridge") packages.[3].Version |> shouldEqual (SemVer.Parse "1.3.0") @@ -321,6 +339,16 @@ let ``should parse framework restricted lock file in new syntax``() = packages.[3].Settings.IncludeVersionInPath |> shouldEqual (Some true) packages.[3].Settings.OmitContent |> shouldEqual (Some ContentCopySettings.Omit) + let dependencies4 = + packages.[4].Dependencies |> Set.toList |> List.map (fun (_, _, r) -> r) + + dependencies4.Head + |> shouldEqual ([FrameworkRestriction.Between(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2), FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))]) + dependencies4.Tail.Head + |> shouldEqual ([FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2)) + FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5)) + FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client))]) + packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource packages.[5].Name |> shouldEqual (PackageName "ReadOnlyCollectionInterfaces") packages.[5].Version |> shouldEqual (SemVer.Parse "1.0.0")