From 94914be185294884e0ab7dc401b2c909329abfc0 Mon Sep 17 00:00:00 2001 From: Dmitry Batalov Date: Thu, 17 Aug 2017 00:04:26 +0400 Subject: [PATCH 1/2] [FIX] Issue #2382 "paket simplify does not operate on groups in paket.references" was fixed. --- src/Paket.Core/PackageAnalysis/Simplifier.fs | 13 ++- .../Simplifier/BasicScenarioSpecs.fs | 106 +++++++++++++++++- 2 files changed, 113 insertions(+), 6 deletions(-) diff --git a/src/Paket.Core/PackageAnalysis/Simplifier.fs b/src/Paket.Core/PackageAnalysis/Simplifier.fs index 49d08b082a..b305d3c6ec 100644 --- a/src/Paket.Core/PackageAnalysis/Simplifier.fs +++ b/src/Paket.Core/PackageAnalysis/Simplifier.fs @@ -68,20 +68,23 @@ let simplify interactive environment = trial { let flatLookup = lockFile.GetDependencyLookupTable() let dependenciesFileRef = ref (environment.DependenciesFile.SimplifyFrameworkRestrictions()) let projectsRef = ref None + let projectFiles, referencesFiles = List.unzip environment.Projects + let referencesFilesRef = ref referencesFiles for kv in lockFile.Groups do let groupName = kv.Key let! dependenciesFile = simplifyDependenciesFile(!dependenciesFileRef, groupName, flatLookup, interactive) dependenciesFileRef := dependenciesFile - let projectFiles, referencesFiles = List.unzip environment.Projects - + let! referencesFiles' = - referencesFiles + !referencesFilesRef |> List.map (fun refFile -> simplifyReferencesFile(refFile, groupName, flatLookup, interactive)) |> collect - let projects = List.zip projectFiles referencesFiles' - projectsRef := Some projects + referencesFilesRef := referencesFiles' + + let projects = List.zip projectFiles (!referencesFilesRef) + projectsRef := Some projects return beforeAndAfter environment (!dependenciesFileRef) (!projectsRef).Value } diff --git a/tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs b/tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs index f5e93c6bcd..f173b79caf 100644 --- a/tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs +++ b/tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs @@ -190,6 +190,79 @@ nuget C 1.0""" depFile.ToString() |> shouldEqual (normalizeLineEndings expected) + +let lockFile4 = """ + +GROUP Foo +NUGET + remote: https://www.nuget.org/api/v2 + specs: + A (1.0) + B (1.0) + B (1.0) + D (1.0) + C (1.0) + E (1.0) + D (1.0) + E (1.0) + E (1.0) + F (1.0) + F (1.0)""" |> (fun x -> LockFile.Parse("", toLines x)) |> Some + +let depFile4 = """ +source http://www.nuget.org/api/v2 + +group Foo +source http://www.nuget.org/api/v2 + +nuget A 1.0 +nuget B 1.0 +nuget C 1.0 +nuget D 1.0 +nuget E 1.0 +nuget F 1.0""" |> DependenciesFile.FromSource + +let projects4 = [ + ReferencesFile.FromLines [|"group Foo";"A";"B";"C";"D";"F"|] + ReferencesFile.FromLines [|"group Foo";"C";"D";"E"|] ] |> List.zip [dummyProjectFile; dummyProjectFile] + +[] +let ``should remove all transitive dependencies from dep file and ref file with empty main group and non empty group foo``() = + let before = PaketEnv.create dummyDir depFile4 lockFile4 projects4 + let fooGroupName = (GroupName "Foo") + + match Simplifier.simplify false before with + | Chessie.ErrorHandling.Bad(msgs) -> + failwith (String.concat Environment.NewLine (msgs |> List.map string)) + | Chessie.ErrorHandling.Ok((_,after),_) -> + let depFile,refFiles = after.DependenciesFile, after.Projects |> List.map snd + depFile.Groups.[fooGroupName].Packages |> List.map (fun p -> p.Name) |> shouldEqual [PackageName"A";PackageName"C"] + refFiles.Head.Groups.[fooGroupName].NugetPackages |> shouldEqual [PackageInstallSettings.Default("A"); PackageInstallSettings.Default("C")] + refFiles.Tail.Head.Groups.[fooGroupName].NugetPackages |> shouldEqual [PackageInstallSettings.Default("C"); PackageInstallSettings.Default("D")] + + let expected = """source http://www.nuget.org/api/v2 + +group Foo +source http://www.nuget.org/api/v2 + +nuget A 1.0 +nuget C 1.0""" + + depFile.ToString() + |> shouldEqual (normalizeLineEndings expected) + + let refFirstFileExpected = """group Foo +A +C""" + refFiles.Head.ToString() + |> shouldEqual (normalizeLineEndings refFirstFileExpected) + + let refSecondFileExpected = """group Foo +C +D""" + refFiles.Tail.Head.ToString() + |> shouldEqual (normalizeLineEndings refSecondFileExpected) + [] [] let ``should simplify framework restrictions in main group``() = @@ -375,4 +448,35 @@ nuget Autofac.WebApi2.Owin 3.2.0""" let originalLockFile = DependenciesFile.FromSource(before) originalLockFile.SimplifyFrameworkRestrictions().ToString() |> normalizeLineEndings - |> shouldEqual (normalizeLineEndings expected) \ No newline at end of file + |> shouldEqual (normalizeLineEndings expected) + + +[] +let ``#2382 paket simplify does not operate on groups in paket.references``() = + let before = """source https://api.nuget.org/v3/index.json + +group Foo +source https://api.nuget.org/v3/index.json +nuget Castle.Core 4.0.0 restriction: >= net452 +nuget Castle.Windsor 4.0.0 restriction: >= net452 +nuget System.ValueTuple 4.3.0 restriction: >= net452""" + let beforeRefFile = """group Foo +Castle.Core +Castle.Windsor +System.ValueTuple""" + + let after = """source https://api.nuget.org/v3/index.json + +group Foo +source https://api.nuget.org/v3/index.json +nuget Castle.Windsor 4.0.0 restriction: >= net452 +nuget System.ValueTuple 4.3.0 restriction: >= net452""" + + let afterRefFile = """group Foo +Castle.Windsor +System.ValueTuple""" + + let originalLockFile = DependenciesFile.FromSource(before) + originalLockFile.SimplifyFrameworkRestrictions().ToString() + |> normalizeLineEndings + |> shouldEqual (normalizeLineEndings before) \ No newline at end of file From b8e7e9c0c75411bbcb860e91252b9897da60710d Mon Sep 17 00:00:00 2001 From: Dmitry Batalov Date: Thu, 17 Aug 2017 00:09:47 +0400 Subject: [PATCH 2/2] [RENAME] A few renames was done. --- tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs b/tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs index f173b79caf..e15cbb6e36 100644 --- a/tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs +++ b/tests/Paket.Tests/Simplifier/BasicScenarioSpecs.fs @@ -251,17 +251,17 @@ nuget C 1.0""" depFile.ToString() |> shouldEqual (normalizeLineEndings expected) - let refFirstFileExpected = """group Foo + let firstRefFileExpected = """group Foo A C""" refFiles.Head.ToString() - |> shouldEqual (normalizeLineEndings refFirstFileExpected) + |> shouldEqual (normalizeLineEndings firstRefFileExpected) - let refSecondFileExpected = """group Foo + let secondRefFileExpected = """group Foo C D""" refFiles.Tail.Head.ToString() - |> shouldEqual (normalizeLineEndings refSecondFileExpected) + |> shouldEqual (normalizeLineEndings secondRefFileExpected) [] []