11namespace Paket
22
33open System.IO
4+ open System.Collections .Generic
45
56[<RequireQualifiedAccess>]
67type 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+
4652type 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+
7591type 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()
0 commit comments