From 2daab5b4903a9d11ca2f6154bdf89f14bfc82eab Mon Sep 17 00:00:00 2001 From: Julien Roncaglia Date: Sun, 11 Oct 2015 14:15:29 +0200 Subject: [PATCH] Extract the framework restriction application code --- src/Paket.Core/InstallModel.fs | 20 +------------------- src/Paket.Core/Requirements.fs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/Paket.Core/InstallModel.fs b/src/Paket.Core/InstallModel.fs index 693d2a616b..8afb16de85 100644 --- a/src/Paket.Core/InstallModel.fs +++ b/src/Paket.Core/InstallModel.fs @@ -288,25 +288,7 @@ type InstallModel = | [] -> this | restrictions -> let applRestriction folder = - { folder with - Targets = - folder.Targets - |> List.filter - (function - | SinglePlatform pf -> - restrictions - |> List.exists (fun restriction -> - match restriction with - | FrameworkRestriction.Exactly fw -> pf = fw - | FrameworkRestriction.Portable r -> false - | FrameworkRestriction.AtLeast fw -> pf >= fw - | FrameworkRestriction.Between(min,max) -> pf >= min && pf < max) - | _ -> - restrictions - |> List.exists (fun restriction -> - match restriction with - | FrameworkRestriction.Portable r -> true - | _ -> false))} + { folder with Targets = applyRestrictionsToTargets restrictions folder.Targets} {this with ReferenceFileFolders = diff --git a/src/Paket.Core/Requirements.fs b/src/Paket.Core/Requirements.fs index 7ab980a905..d995724b72 100644 --- a/src/Paket.Core/Requirements.fs +++ b/src/Paket.Core/Requirements.fs @@ -213,6 +213,29 @@ let filterRestrictions (list1:FrameworkRestrictions) (list2:FrameworkRestriction if c <> [] then yield! c] |> optimizeRestrictions +/// Get if a target should be considered with the specified restrictions +let isTargetMatchingRestrictions (restrictions:FrameworkRestrictions) = function + | SinglePlatform pf -> + restrictions + |> List.exists (fun restriction -> + match restriction with + | FrameworkRestriction.Exactly fw -> pf = fw + | FrameworkRestriction.Portable _ -> false + | FrameworkRestriction.AtLeast fw -> pf >= fw + | FrameworkRestriction.Between(min,max) -> pf >= min && pf < max) + | _ -> + restrictions + |> List.exists (fun restriction -> + match restriction with + | FrameworkRestriction.Portable r -> true + | _ -> false) + +/// Get all targets that should be considered with the specified restrictions +let applyRestrictionsToTargets (restrictions:FrameworkRestrictions) (targets: TargetProfile list) = + let result = targets |> List.filter (isTargetMatchingRestrictions restrictions) + result + + type ContentCopySettings = | Omit | Overwrite