Skip to content

Commit 2dfed37

Browse files
committed
Build a merged install model with all packages - references #297
1 parent 66af893 commit 2dfed37

8 files changed

Lines changed: 68 additions & 38 deletions

File tree

‎RELEASE_NOTES.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#### 0.10.2 - 28.10.2014
2-
* revert 0.10.1
1+
#### 0.11.0-alpha001 - 28.10.2014
2+
* Build a merged install model with all packages - https://github.com/fsprojects/Paket/issues/297
33

44
#### 0.10.0 - 24.10.2014
55
* Initial version of `paket remove` command - http://fsprojects.github.io/Paket/paket-remove.html

‎src/Paket.Core/InstallModel.fs‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Paket
22

33
open System.IO
4+
open System.Collections.Generic
45

56
[<RequireQualifiedAccess>]
67
type Reference =
@@ -43,6 +44,11 @@ type InstallFiles =
4344
member this.AddFrameworkAssemblyReference assemblyName =
4445
{ this with References = Set.add (Reference.FrameworkAssemblyReference assemblyName) this.References }
4546

47+
member this.MergeWith(that:InstallFiles)=
48+
{ this with
49+
References = Set.union that.References this.References
50+
ContentFiles = Set.union that.ContentFiles this.ContentFiles }
51+
4652
type FrameworkGroup =
4753
{ Frameworks : Map<FrameworkIdentifier, InstallFiles>
4854
Fallbacks : InstallFiles }
@@ -72,6 +78,16 @@ type FrameworkGroup =
7278
| Some files when Set.isEmpty files.References |> not -> Map.add framework (mapReferencesF files) this.Frameworks
7379
| _ -> Map.add framework (emptyReferencesF()) this.Frameworks }
7480

81+
member this.MergeWith(that:FrameworkGroup) =
82+
let mergedFrameworks =
83+
that.Frameworks
84+
|> Map.fold (fun group frameworkName framework ->
85+
match Map.tryFind frameworkName this.Frameworks with
86+
| Some files -> { group with Frameworks = Map.add frameworkName (files.MergeWith framework) group.Frameworks }
87+
| None -> { group with Frameworks = Map.add frameworkName framework group.Frameworks }) this
88+
{ mergedFrameworks with
89+
Fallbacks = this.Fallbacks.MergeWith(that.Fallbacks) }
90+
7591
type InstallModel =
7692
{ PackageName : string
7793
PackageVersion : SemVerInfo
@@ -169,7 +185,6 @@ type InstallModel =
169185
model.MapGroupFrameworks(fun _ files -> { files with References = Set.filter f files.References }) )
170186
this
171187

172-
173188
member this.UseLowerVersionLibIfEmpty() =
174189
this.AddOrReplaceGroup(
175190
FrameworkIdentifier.DefaultGroup,
@@ -204,13 +219,24 @@ type InstallModel =
204219
(fun files -> files))),
205220
(fun _ -> Some(FrameworkGroup.singleton(framework,{ References = newFiles; ContentFiles = Set.empty }))))) this
206221

222+
223+
member this.MergeWith(that:InstallModel) =
224+
let mergedGroups =
225+
that.Groups
226+
|> Map.fold (fun (model : InstallModel) groupName group ->
227+
match this.Groups.TryFind groupName with
228+
| Some g -> { model with Groups = Map.add groupName (group.MergeWith(g)) model.Groups }
229+
| None -> { model with Groups = Map.add groupName group model.Groups }) this
230+
{ mergedGroups with
231+
DefaultFallback = this.DefaultFallback.MergeWith(that.DefaultFallback) }
232+
207233
member this.UseLastInGroupAsFallback() =
208234
this.MapGroups(fun _ group -> { group with Fallbacks = (group.Frameworks |> Seq.last).Value })
209235

210236
member this.UseLastGroupFallBackAsDefaultFallBack() =
211237
{ this with DefaultFallback = this.Groups.[FrameworkIdentifier.DefaultGroup].Fallbacks }
212238

213-
member this.DeleteIfGroupFallback() =
239+
member this.FilterFallbacks() =
214240
this.MapGroups(fun _ group ->
215241
let fallbacks = group.Fallbacks
216242
{ group with Frameworks =
@@ -262,9 +288,7 @@ type InstallModel =
262288
.UseLowerVersionLibForSpecicalFrameworksIfEmpty()
263289
.FilterBlackList()
264290
.UseLastInGroupAsFallback()
265-
.UseLastGroupFallBackAsDefaultFallBack()
266-
267-
member this.BuildModel() = this.BuildUnfilteredModel().DeleteIfGroupFallback()
291+
.UseLastGroupFallBackAsDefaultFallBack()
268292

269293
member this.GetReferenceNames =
270294
lazy ([ for g in this.Groups do
@@ -279,4 +303,5 @@ type InstallModel =
279303
InstallModel
280304
.EmptyModel(packageName, packageVersion)
281305
.AddReferences(libs, nuspec.References)
282-
.AddFrameworkAssemblyReferences(nuspec.FrameworkAssemblyReferences).BuildModel()
306+
.AddFrameworkAssemblyReferences(nuspec.FrameworkAssemblyReferences)
307+
.BuildUnfilteredModel()

‎src/Paket.Core/ProjectFile.fs‎

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,23 @@ type ProjectFile =
161161
let itemGroup = createNode(this.Document,"ItemGroup")
162162

163163
for lib in references do
164-
let reference =
165-
match lib with
166-
| Reference.Library lib ->
167-
let fi = new FileInfo(normalizePath lib)
164+
match lib with
165+
| Reference.Library lib ->
166+
let fi = new FileInfo(normalizePath lib)
168167

169-
createNode(this.Document,"Reference")
170-
|> addAttribute "Include" (fi.Name.Replace(fi.Extension,""))
171-
|> addChild (createNodeWithText(this.Document,"HintPath",createRelativePath this.FileName fi.FullName))
172-
|> addChild (createNodeWithText(this.Document,"Private","True"))
173-
|> addChild (createNodeWithText(this.Document,"Paket","True"))
174-
| Reference.FrameworkAssemblyReference frameworkAssembly ->
175-
createNode(this.Document,"Reference")
176-
|> addAttribute "Include" frameworkAssembly
177-
|> addChild (createNodeWithText(this.Document,"Paket","True"))
178-
179-
itemGroup.AppendChild(reference) |> ignore
168+
createNode(this.Document,"Reference")
169+
|> addAttribute "Include" (fi.Name.Replace(fi.Extension,""))
170+
|> addChild (createNodeWithText(this.Document,"HintPath",createRelativePath this.FileName fi.FullName))
171+
|> addChild (createNodeWithText(this.Document,"Private","True"))
172+
|> addChild (createNodeWithText(this.Document,"Paket","True"))
173+
|> itemGroup.AppendChild
174+
|> ignore
175+
| Reference.FrameworkAssemblyReference frameworkAssembly ->
176+
createNode(this.Document,"Reference")
177+
|> addAttribute "Include" frameworkAssembly
178+
|> addChild (createNodeWithText(this.Document,"Paket","True"))
179+
|> itemGroup.AppendChild
180+
|> ignore
180181
itemGroup
181182

182183
let groupChooseNode = this.Document.CreateElement("Choose", Constants.ProjectDefaultNameSpace)
@@ -235,16 +236,19 @@ type ProjectFile =
235236
let installModel = completeModel.[kv.Key.ToLower()]
236237
this.DeleteCustomNodes(installModel)
237238

238-
for kv in usedPackages do
239-
let packageName = kv.Key
240-
let installModel = completeModel.[packageName.ToLower()]
241-
242-
if this.HasCustomNodes(installModel) then
243-
verbosefn " - custom nodes for %s ==> skipping" packageName
244-
else
245-
let chooseNode = this.GenerateXml(installModel)
246-
this.ProjectNode.AppendChild(chooseNode) |> ignore
247-
239+
let merged =
240+
usedPackages
241+
|> Seq.fold (fun (model:InstallModel) kv ->
242+
let installModel = completeModel.[kv.Key.ToLower()]
243+
if this.HasCustomNodes(installModel) then
244+
verbosefn " - custom nodes for %s ==> skipping" kv.Key
245+
model
246+
else model.MergeWith(completeModel.[kv.Key.ToLower()]))
247+
(InstallModel.EmptyModel("",SemVer.Parse "0"))
248+
249+
let chooseNode = this.GenerateXml(merged.FilterFallbacks())
250+
this.ProjectNode.AppendChild(chooseNode) |> ignore
251+
248252
member this.Save() =
249253
if Utils.normalizeXml this.Document <> this.OriginalText then
250254
verbosefn "Project %s changed" this.FileName

‎src/Paket/Paket.fsproj‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
<DefineConstants>TRACE</DefineConstants>
4141
<WarningLevel>3</WarningLevel>
4242
<DocumentationFile>..\..\bin\Paket.xml</DocumentationFile>
43-
<StartArguments>update</StartArguments>
44-
<StartWorkingDirectory>D:\code\paketkopie</StartWorkingDirectory>
43+
<StartArguments>install</StartArguments>
44+
<StartWorkingDirectory>D:\code\PaketKopie</StartWorkingDirectory>
4545
</PropertyGroup>
4646
<PropertyGroup>
4747
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>

‎tests/Paket.Tests/InstallModel/ProcessingSpecs.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ let ``should handle lib install of DotNetZip 1.9.3``() =
224224

225225
[<Test>]
226226
let ``should reduce lib install of DotNetZip 1.9.3``() =
227-
let model = emptymodel.AddReferences([ @"..\DotNetZip\lib\net20\Ionic.Zip.dll" ]).BuildModel()
227+
let model = emptymodel.AddReferences([ @"..\DotNetZip\lib\net20\Ionic.Zip.dll" ]).BuildUnfilteredModel().FilterFallbacks()
228228

229229
model.GetFiles(DotNetFramework(FrameworkVersion.V2)) |> shouldNotContain @"..\DotNetZip\lib\net20\Ionic.Zip.dll"
230230
model.GetFiles(DotNetFramework(FrameworkVersion.V4_5)) |> shouldNotContain @"..\DotNetZip\lib\net20\Ionic.Zip.dll"

‎tests/Paket.Tests/InstallModel/Xml/Fantomas.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let ``should generate Xml for Fantomas 1.5``() =
2121
[ @"..\Fantomas\lib\FantomasLib.dll"
2222
@"..\Fantomas\lib\FSharp.Core.dll"
2323
@"..\Fantomas\lib\Fantomas.exe" ],
24-
Nuspec.Explicit ["FantomasLib.dll"])
24+
Nuspec.Explicit ["FantomasLib.dll"]).FilterFallbacks()
2525

2626
let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model)
2727
chooseNode.OuterXml

‎tests/Paket.Tests/InstallModel/Xml/SystemNetHttp.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() =
293293

294294
@"..\Microsoft.Net.Http\lib\wpa81\System.Net.Http.Extensions.dll"
295295
@"..\Microsoft.Net.Http\lib\wpa81\System.Net.Http.Primitives.dll" ],
296-
Nuspec.All)
296+
Nuspec.All).FilterFallbacks()
297297

298298
let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model)
299299
chooseNode.OuterXml

‎tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithFrameworkReferences.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() =
230230
FrameworkAssemblyReferences =
231231
[{ AssemblyName = "System.Net.Http"; TargetFramework = DotNetFramework(FrameworkVersion.V4_5) }
232232
{ AssemblyName = "System.Net.Http.WebRequest"; TargetFramework = DotNetFramework(FrameworkVersion.V4_5) }]})
233+
.FilterFallbacks()
233234

234235
let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model)
235236
chooseNode.OuterXml

0 commit comments

Comments
 (0)