From 25bf9178d173440a6bcd7af5b24fdfb9dec3ffbe Mon Sep 17 00:00:00 2001 From: Julien Roncaglia Date: Sun, 11 Oct 2015 14:15:29 +0200 Subject: [PATCH 1/6] 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 830a0bdc3f..afc24ff2b7 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 From e08a3a68ac0431882aee063cca66ff7c4f88b482 Mon Sep 17 00:00:00 2001 From: Julien Roncaglia Date: Sun, 11 Oct 2015 14:16:21 +0200 Subject: [PATCH 2/6] Add a test proving issue with '>= net40' and silverlight Issue #1124 --- tests/Paket.Tests/Paket.Tests.fsproj | 1 + .../RestrictionApplicationSpecs.fs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/Paket.Tests/RestrictionApplicationSpecs.fs diff --git a/tests/Paket.Tests/Paket.Tests.fsproj b/tests/Paket.Tests/Paket.Tests.fsproj index a9721aafc3..ea36ef233c 100644 --- a/tests/Paket.Tests/Paket.Tests.fsproj +++ b/tests/Paket.Tests/Paket.Tests.fsproj @@ -91,6 +91,7 @@ + Always diff --git a/tests/Paket.Tests/RestrictionApplicationSpecs.fs b/tests/Paket.Tests/RestrictionApplicationSpecs.fs new file mode 100644 index 0000000000..16fa95ca5b --- /dev/null +++ b/tests/Paket.Tests/RestrictionApplicationSpecs.fs @@ -0,0 +1,19 @@ +module Packet.RestrictionApplicationSpecs + +open System.IO +open Paket +open Paket.Domain +open Chessie.ErrorHandling +open FsUnit +open NUnit.Framework +open TestHelpers +open Paket.Requirements + +[] +let ``>= net40 does not include silverlight (#1124)`` () = + /// https://github.com/fsprojects/Paket/issues/1124 + let restrictions = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4))] + let targets = KnownTargetProfiles.DotNetFrameworkProfiles @ KnownTargetProfiles.SilverlightProfiles + let restricted = applyRestrictionsToTargets restrictions targets + + restricted |> shouldEqual KnownTargetProfiles.DotNetFrameworkProfiles \ No newline at end of file From f913ce230578c1f98f528c9c0603e4f048ee3d30 Mon Sep 17 00:00:00 2001 From: Julien Roncaglia Date: Sun, 11 Oct 2015 18:55:03 +0200 Subject: [PATCH 3/6] Handle framework identifiers comparison FrameworkIdentifier instances were compared structurally before but it was problematic in some cases as '>= net45' matched 'sl40' that wasn't in the same framework. This commit add new operators (.>, .>=, .<, .<=) and methods (Min, Max, IsSameFramework) to FrameworkIdentifier that do the comparison with the expected semantic. Fixes #1124 --- src/Paket.Core/FrameworkHandling.fs | 65 +++++++- src/Paket.Core/InstallModel.fs | 4 +- src/Paket.Core/PackageResolver.fs | 10 +- src/Paket.Core/Requirements.fs | 55 ++++--- .../FrameworkIdentifierSpecs.fs | 140 ++++++++++++++++++ tests/Paket.Tests/Paket.Tests.fsproj | 5 +- .../RestrictionApplicationSpecs.fs | 83 +++++++++++ .../RestrictionFilterSpecs.fs | 2 +- .../RestrictionApplicationSpecs.fs | 19 --- 9 files changed, 327 insertions(+), 56 deletions(-) create mode 100644 tests/Paket.Tests/FrameworkHandling/FrameworkIdentifierSpecs.fs create mode 100644 tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs rename tests/Paket.Tests/{ => Requirements}/RestrictionFilterSpecs.fs (95%) delete mode 100644 tests/Paket.Tests/RestrictionApplicationSpecs.fs diff --git a/src/Paket.Core/FrameworkHandling.fs b/src/Paket.Core/FrameworkHandling.fs index 471ae81232..f21764908d 100644 --- a/src/Paket.Core/FrameworkHandling.fs +++ b/src/Paket.Core/FrameworkHandling.fs @@ -68,7 +68,6 @@ module KnownAliases = ".", "" ] |> List.map (fun (p,r) -> p.ToLower(),r.ToLower()) - /// Framework Identifier type. type FrameworkIdentifier = | DotNetFramework of FrameworkVersion @@ -84,7 +83,68 @@ type FrameworkIdentifier = | WindowsPhoneSilverlight of string | Silverlight of string - + static member private ParseVersion(s:string) = + if s.Length > 0 && s.[0] = 'v' then + match Version.TryParse(s.Substring(1)) with + | true, v -> v + | false, _ -> failwith ("Invalid version syntax: " + s) + else + failwith ("Invalid version syntax: " + s) + + member private x.ApplyOperator y compareFramework compareVersion = + let compareVersion' a b = + let va = FrameworkIdentifier.ParseVersion(a) + let vb = FrameworkIdentifier.ParseVersion(b) + compareVersion va vb + + match x,y with + | DotNetFramework a, DotNetFramework b -> compareFramework a b + | DNX a, DNX b -> compareFramework a b + | DNXCore a, DNXCore b -> compareFramework a b + | MonoAndroid, MonoAndroid -> false + | MonoTouch, MonoTouch -> false + | MonoMac, MonoMac -> false + | XamariniOS, XamariniOS -> false + | XamarinMac, XamarinMac -> false + | Windows a, Windows b -> compareVersion' a b + | WindowsPhoneApp a, WindowsPhoneApp b -> compareVersion' a b + | WindowsPhoneSilverlight a, WindowsPhoneSilverlight b -> compareVersion' a b + | Silverlight a, Silverlight b -> compareVersion' a b + | _ -> false + + /// Is x considered supperior to y + static member (.>) (x:FrameworkIdentifier, y:FrameworkIdentifier) = + x.ApplyOperator y (>) (>) + + /// Is x considered supperior or equal to y + static member (.>=) (x:FrameworkIdentifier, y:FrameworkIdentifier) = + x = y || x .> y + + /// Is x considered inferior to y + static member (.<) (x:FrameworkIdentifier, y:FrameworkIdentifier) = + x.ApplyOperator y (<) (<) + + /// Is x considered inferior or equal to y + static member (.<=) (x:FrameworkIdentifier, y:FrameworkIdentifier) = + x = y || x .< y + + static member IsSameFramework (x:FrameworkIdentifier) y = + x = y || x .< y || x .> y + + static member Min (x:FrameworkIdentifier) y = + match x .<= y, y .<= x with + | true, true -> x + | true, false -> x + | false, true -> y + | false, false -> failwith (sprintf "Not the same framework '%O' and '%O'" x y) + + static member Max (x:FrameworkIdentifier) y = + match x .>= y, y .>= x with + | true, true -> x + | true, false -> x + | false, true -> y + | false, false -> failwith (sprintf "Not the same framework '%O' and '%O'" x y) + override x.ToString() = match x with | DotNetFramework v -> "net" + v.ShortString() @@ -100,7 +160,6 @@ type FrameworkIdentifier = | WindowsPhoneSilverlight v -> "wp" + v | Silverlight v -> "sl" + v.Replace("v","").Replace(".","") - // returns a list of compatible platforms that this platform also supports member x.SupportedPlatforms = match x with diff --git a/src/Paket.Core/InstallModel.fs b/src/Paket.Core/InstallModel.fs index 8afb16de85..476a0d0cfa 100644 --- a/src/Paket.Core/InstallModel.fs +++ b/src/Paket.Core/InstallModel.fs @@ -241,10 +241,10 @@ type InstallModel = |> List.exists (fun t -> t = target) | FrameworkRestriction.AtLeast target -> folder.GetSinglePlatforms() - |> List.exists (fun t -> t >= target) + |> List.exists (fun t -> t .>= target) | FrameworkRestriction.Between(min,max) -> folder.GetSinglePlatforms() - |> List.exists (fun t -> t >= min && t < max) ) + |> List.exists (fun t -> t .>= min && t .< max) ) this.MapFolders(fun folder -> if referenceApplies folder then diff --git a/src/Paket.Core/PackageResolver.fs b/src/Paket.Core/PackageResolver.fs index 51ed22a965..cd0c5439a9 100644 --- a/src/Paket.Core/PackageResolver.fs +++ b/src/Paket.Core/PackageResolver.fs @@ -21,16 +21,16 @@ module DependencySetFilter = |> Seq.exists (fun r2 -> match r2 with | FrameworkRestriction.Exactly v2 when v1 = v2 -> true - | FrameworkRestriction.AtLeast v2 when v1 >= v2 -> true - | FrameworkRestriction.Between(v2,v3) when v1 >= v2 && v1 < v3 -> true + | FrameworkRestriction.AtLeast v2 when v1 .>= v2 -> true + | FrameworkRestriction.Between(v2,v3) when v1 .>= v2 && v1 .< v3 -> true | _ -> false) | FrameworkRestriction.AtLeast v1 -> restrictions |> Seq.exists (fun r2 -> match r2 with - | FrameworkRestriction.Exactly v2 when v1 <= v2 -> true - | FrameworkRestriction.AtLeast v2 when v1 <= v2 -> true - | FrameworkRestriction.Between(v2,v3) when v1 <= v2 && v1 < v3 -> true + | FrameworkRestriction.Exactly v2 when v1 .<= v2 -> true + | FrameworkRestriction.AtLeast v2 when v1 .<= v2 -> true + | FrameworkRestriction.Between(v2,v3) when v1 .<= v2 && v1 .< v3 -> true | _ -> false) | _ -> true diff --git a/src/Paket.Core/Requirements.fs b/src/Paket.Core/Requirements.fs index afc24ff2b7..a60261994b 100644 --- a/src/Paket.Core/Requirements.fs +++ b/src/Paket.Core/Requirements.fs @@ -53,15 +53,15 @@ let private minRestriction = FrameworkRestriction.Exactly(DotNetFramework(Framew let findMaxDotNetRestriction restrictions = minRestriction :: restrictions - |> List.filter (fun (r:FrameworkRestriction) -> + |> List.choose (fun (r:FrameworkRestriction) -> match r with - | FrameworkRestriction.Exactly r -> r.ToString().StartsWith("net") - | _ -> false) + | FrameworkRestriction.Exactly i -> + match i with + | DotNetFramework f -> Some(f) + | _ -> None + | _ -> None) |> List.max - |> fun r -> - match r with - | FrameworkRestriction.Exactly r -> r - | _ -> failwith "error" + |> DotNetFramework let rec optimizeRestrictions restrictions = match restrictions with @@ -178,29 +178,36 @@ let combineRestrictions x y = match y with | FrameworkRestriction.Exactly r' -> if r = r' then [FrameworkRestriction.Exactly r] else [] | FrameworkRestriction.Portable _ -> [] - | FrameworkRestriction.AtLeast r' -> if r' <= r then [FrameworkRestriction.Exactly r] else [] - | FrameworkRestriction.Between(min,max) -> if min <= r && r <= max then [FrameworkRestriction.Exactly r] else [] + | FrameworkRestriction.AtLeast r' -> if r' .<= r then [FrameworkRestriction.Exactly r] else [] + | FrameworkRestriction.Between(min,max) -> if min .<= r && r .<= max then [FrameworkRestriction.Exactly r] else [] | FrameworkRestriction.Portable r -> match y with | FrameworkRestriction.Portable r' -> if r = r' then [FrameworkRestriction.Portable r] else [] | _ -> [] | FrameworkRestriction.AtLeast r -> match y with - | FrameworkRestriction.Exactly r' -> if r <= r' then [FrameworkRestriction.Exactly r'] else [] + | FrameworkRestriction.Exactly r' -> if r .<= r' then [FrameworkRestriction.Exactly r'] else [] | FrameworkRestriction.Portable _ -> [] - | FrameworkRestriction.AtLeast r' -> [FrameworkRestriction.AtLeast (max r r')] - | FrameworkRestriction.Between(min,max) -> if min <= r && r <= max then [FrameworkRestriction.Between(r,max)] else [] + | FrameworkRestriction.AtLeast r' -> + if FrameworkIdentifier.IsSameFramework r r' then + [FrameworkRestriction.AtLeast (FrameworkIdentifier.Max r r')] + else + [] + | FrameworkRestriction.Between(min,max) -> if min .<= r && r .<= max then [FrameworkRestriction.Between(r,max)] else [] | FrameworkRestriction.Between(min1,max1) -> match y with - | FrameworkRestriction.Exactly r -> if min1 <= r && r <= max1 then [FrameworkRestriction.Exactly r] else [] + | FrameworkRestriction.Exactly r -> if min1 .<= r && r .<= max1 then [FrameworkRestriction.Exactly r] else [] | FrameworkRestriction.Portable _ -> [] - | FrameworkRestriction.AtLeast r -> if min1 <= r && r <= max1 then [FrameworkRestriction.Between(r,max1)] else [] - | FrameworkRestriction.Between(min2,max2) -> - let min' = max min1 min2 - let max' = min max1 max2 - if min' < max' then [FrameworkRestriction.Between(min',max')] else - if min' = max' then [FrameworkRestriction.Exactly(min')] else - [] + | FrameworkRestriction.AtLeast r -> if min1 .<= r && r .<= max1 then [FrameworkRestriction.Between(r,max1)] else [] + | FrameworkRestriction.Between(min2, max2) -> + if FrameworkIdentifier.IsSameFramework min1 min2 && FrameworkIdentifier.IsSameFramework max1 max2 then + let min' = FrameworkIdentifier.Max min1 min2 + let max' = FrameworkIdentifier.Min max1 max2 + if min' .< max' then [FrameworkRestriction.Between(min',max')] else + if min' = max' then [FrameworkRestriction.Exactly(min')] else + [] + else + [] let filterRestrictions (list1:FrameworkRestrictions) (list2:FrameworkRestrictions) = match list1,list2 with @@ -221,13 +228,13 @@ let isTargetMatchingRestrictions (restrictions:FrameworkRestrictions) = function match restriction with | FrameworkRestriction.Exactly fw -> pf = fw | FrameworkRestriction.Portable _ -> false - | FrameworkRestriction.AtLeast fw -> pf >= fw - | FrameworkRestriction.Between(min,max) -> pf >= min && pf < max) - | _ -> + | FrameworkRestriction.AtLeast fw -> pf .>= fw + | FrameworkRestriction.Between(min,max) -> pf .>= min && pf .< max) + | PortableProfile(_,_) -> restrictions |> List.exists (fun restriction -> match restriction with - | FrameworkRestriction.Portable r -> true + | FrameworkRestriction.Portable _ -> true | _ -> false) /// Get all targets that should be considered with the specified restrictions diff --git a/tests/Paket.Tests/FrameworkHandling/FrameworkIdentifierSpecs.fs b/tests/Paket.Tests/FrameworkHandling/FrameworkIdentifierSpecs.fs new file mode 100644 index 0000000000..c1021cdfc4 --- /dev/null +++ b/tests/Paket.Tests/FrameworkHandling/FrameworkIdentifierSpecs.fs @@ -0,0 +1,140 @@ +module Paket.FrameworkHandling.FrameworkIdentifierSpecs + +open System.IO +open Paket +open Paket.Domain +open Chessie.ErrorHandling +open FsUnit +open NUnit.Framework +open TestHelpers +open Paket.Requirements + +let silverlight x = FrameworkIdentifier.Silverlight(x) +let dotnet x = FrameworkIdentifier.DotNetFramework(x) + +[] +let ``.>= should work for dotnet``() = + dotnet FrameworkVersion.V4 .>= dotnet FrameworkVersion.V1 + |> shouldEqual true + dotnet FrameworkVersion.V4 .>= dotnet FrameworkVersion.V4 + |> shouldEqual true + dotnet FrameworkVersion.V4 .>= dotnet FrameworkVersion.V4_5 + |> shouldEqual false + +[] +let ``.> should work for dotnet``() = + dotnet FrameworkVersion.V4 .> dotnet FrameworkVersion.V1 + |> shouldEqual true + dotnet FrameworkVersion.V4 .> dotnet FrameworkVersion.V4 + |> shouldEqual false + dotnet FrameworkVersion.V4 .> dotnet FrameworkVersion.V4_5 + |> shouldEqual false + +[] +let ``.<= should work for dotnet``() = + dotnet FrameworkVersion.V4 .<= dotnet FrameworkVersion.V1 + |> shouldEqual false + dotnet FrameworkVersion.V4 .<= dotnet FrameworkVersion.V4 + |> shouldEqual true + dotnet FrameworkVersion.V4 .<= dotnet FrameworkVersion.V4_5 + |> shouldEqual true + +[] +let ``.< should work for dotnet``() = + dotnet FrameworkVersion.V4 .< dotnet FrameworkVersion.V1 + |> shouldEqual false + dotnet FrameworkVersion.V4 .< dotnet FrameworkVersion.V4 + |> shouldEqual false + dotnet FrameworkVersion.V4 .< dotnet FrameworkVersion.V4_5 + |> shouldEqual true + +[] +let ``.>= should work for silverlight``() = + silverlight "v4.0" .>= silverlight "v3.0" + |> shouldEqual true + silverlight "v4.0" .>= silverlight "v4.0" + |> shouldEqual true + silverlight "v4.0" .>= silverlight "v5.0" + |> shouldEqual false + +[] +let ``.> should work for silverlight``() = + silverlight "v4.0" .> silverlight "v3.0" + |> shouldEqual true + silverlight "v4.0" .> silverlight "v4.0" + |> shouldEqual false + silverlight "v4.0" .> silverlight "v5.0" + |> shouldEqual false + +[] +let ``.<= should work for silverlight``() = + silverlight "v4.0" .<= silverlight "v3.0" + |> shouldEqual false + silverlight "v4.0" .<= silverlight "v4.0" + |> shouldEqual true + silverlight "v4.0" .<= silverlight "v5.0" + |> shouldEqual true + +[] +let ``.< should work for silverlight``() = + silverlight "v4.0" .< silverlight "v3.0" + |> shouldEqual false + silverlight "v4.0" .< silverlight "v4.0" + |> shouldEqual false + silverlight "v4.0" .< silverlight "v5.0" + |> shouldEqual true + +[] +let ``Same framework can be detected``() = + FrameworkIdentifier.IsSameFramework (silverlight "v4.0") (silverlight "v3.0") + |> shouldEqual true + FrameworkIdentifier.IsSameFramework (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V1) + |> shouldEqual true + FrameworkIdentifier.IsSameFramework (dotnet FrameworkVersion.V4) (silverlight "v4.0") + |> shouldEqual false + +[] +let ``Min works for dotnet``() = + FrameworkIdentifier.Min (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V1) + |> shouldEqual (dotnet FrameworkVersion.V1) + FrameworkIdentifier.Min (dotnet FrameworkVersion.V1) (dotnet FrameworkVersion.V4) + |> shouldEqual (dotnet FrameworkVersion.V1) + FrameworkIdentifier.Min (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V4) + |> shouldEqual (dotnet FrameworkVersion.V4) + +[] +let ``Max works for dotnet``() = + FrameworkIdentifier.Max (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V1) + |> shouldEqual (dotnet FrameworkVersion.V4) + FrameworkIdentifier.Max (dotnet FrameworkVersion.V1) (dotnet FrameworkVersion.V4) + |> shouldEqual (dotnet FrameworkVersion.V4) + FrameworkIdentifier.Max (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V4) + |> shouldEqual (dotnet FrameworkVersion.V4) + +[] +let ``Min works for silverlight``() = + FrameworkIdentifier.Min (silverlight "v4.0") (silverlight "v3.0") + |> shouldEqual (silverlight "v3.0") + FrameworkIdentifier.Min (silverlight "v3.0") (silverlight "v4.0") + |> shouldEqual (silverlight "v3.0") + FrameworkIdentifier.Min (silverlight "v4.0") (silverlight "v4.0") + |> shouldEqual (silverlight "v4.0") + +[] +let ``Max works for silverlight``() = + FrameworkIdentifier.Max (silverlight "v4.0") (silverlight "v3.0") + |> shouldEqual (silverlight "v4.0") + FrameworkIdentifier.Max (silverlight "v3.0") (silverlight "v4.0") + |> shouldEqual (silverlight "v4.0") + FrameworkIdentifier.Max (silverlight "v4.0") (silverlight "v4.0") + |> shouldEqual (silverlight "v4.0") + +[] +let ``Max throw for mixed framework``() = + FrameworkIdentifier.Max (silverlight "v4.0") (dotnet FrameworkVersion.V4) + |> ignore + +[] +let ``Min throw for mixed framework``() = + FrameworkIdentifier.Min (silverlight "v4.0") (dotnet FrameworkVersion.V4) + |> ignore \ No newline at end of file diff --git a/tests/Paket.Tests/Paket.Tests.fsproj b/tests/Paket.Tests/Paket.Tests.fsproj index ea36ef233c..7c98ce8846 100644 --- a/tests/Paket.Tests/Paket.Tests.fsproj +++ b/tests/Paket.Tests/Paket.Tests.fsproj @@ -90,8 +90,6 @@ - - Always @@ -310,6 +308,9 @@ + + + diff --git a/tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs b/tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs new file mode 100644 index 0000000000..56dbb2eebc --- /dev/null +++ b/tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs @@ -0,0 +1,83 @@ +module Paket.Requirements.RestrictionApplicationSpecs + +open Paket +open FsUnit +open NUnit.Framework +open Paket.Requirements + +let dotnet x = SinglePlatform(DotNetFramework(x)) + +module TestTargetProfiles = + let DotNetFrameworkVersions = + [FrameworkVersion.V1 + FrameworkVersion.V1_1 + FrameworkVersion.V2 + FrameworkVersion.V3 + FrameworkVersion.V3_5 + FrameworkVersion.V4_Client + FrameworkVersion.V4 + FrameworkVersion.V4_5 + FrameworkVersion.V4_5_1 + FrameworkVersion.V4_5_2 + FrameworkVersion.V4_5_3 + FrameworkVersion.V4_6] + + let DotNetFrameworkProfiles = DotNetFrameworkVersions |> List.map dotnet + + let WindowsProfiles = + [SinglePlatform(Windows "v4.5") + SinglePlatform(Windows "v4.5.1")] + + let SilverlightProfiles = + [SinglePlatform(Silverlight "v3.0") + SinglePlatform(Silverlight "v4.0") + SinglePlatform(Silverlight "v5.0")] + + let WindowsPhoneSilverlightProfiles = + [SinglePlatform(WindowsPhoneSilverlight "v7.0") + SinglePlatform(WindowsPhoneSilverlight "v7.1") + SinglePlatform(WindowsPhoneSilverlight "v8.0") + SinglePlatform(WindowsPhoneSilverlight "v8.1")] + + let AllProfiles = + DotNetFrameworkProfiles @ + WindowsProfiles @ + SilverlightProfiles @ + WindowsPhoneSilverlightProfiles @ + [SinglePlatform(MonoAndroid) + SinglePlatform(MonoTouch) + SinglePlatform(XamariniOS) + SinglePlatform(XamarinMac) + SinglePlatform(WindowsPhoneApp "v8.1") + ] + +[] +let ``>= net10 contains all but only dotnet versions (#1124)`` () = + /// https://github.com/fsprojects/Paket/issues/1124 + let restrictions = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V1))] + let restricted = applyRestrictionsToTargets restrictions TestTargetProfiles.AllProfiles + + restricted |> shouldEqual TestTargetProfiles.DotNetFrameworkProfiles + +[] +let ``>= net452 contains 4.5.2 and following versions`` () = + let restrictions = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_5_2))] + let restricted = applyRestrictionsToTargets restrictions TestTargetProfiles.AllProfiles + let expected = [FrameworkVersion.V4_5_2; FrameworkVersion.V4_5_3; FrameworkVersion.V4_6] |> List.map dotnet + + restricted |> shouldEqual expected + +[] +let ``>= net40 < net451 contains 4.0 and 4.5`` () = + let restrictions = [FrameworkRestriction.Between(DotNetFramework(FrameworkVersion.V4), DotNetFramework(FrameworkVersion.V4_5_1))] + let restricted = applyRestrictionsToTargets restrictions TestTargetProfiles.AllProfiles + let expected = [FrameworkVersion.V4; FrameworkVersion.V4_5] |> List.map dotnet + + restricted |> shouldEqual expected + +[] +let ``>= sl30 contains all but only silverlight versions`` () = + let restrictions = [FrameworkRestriction.AtLeast(Silverlight "v3.0")] + let restricted = applyRestrictionsToTargets restrictions TestTargetProfiles.AllProfiles + + restricted |> shouldEqual TestTargetProfiles.SilverlightProfiles \ No newline at end of file diff --git a/tests/Paket.Tests/RestrictionFilterSpecs.fs b/tests/Paket.Tests/Requirements/RestrictionFilterSpecs.fs similarity index 95% rename from tests/Paket.Tests/RestrictionFilterSpecs.fs rename to tests/Paket.Tests/Requirements/RestrictionFilterSpecs.fs index 286db01655..6e060ef002 100644 --- a/tests/Paket.Tests/RestrictionFilterSpecs.fs +++ b/tests/Paket.Tests/Requirements/RestrictionFilterSpecs.fs @@ -1,4 +1,4 @@ -module Paket.RestrictionFilterSpecs +module Paket.Requirements.RestrictionFilterSpecs open System.IO open Paket diff --git a/tests/Paket.Tests/RestrictionApplicationSpecs.fs b/tests/Paket.Tests/RestrictionApplicationSpecs.fs deleted file mode 100644 index 16fa95ca5b..0000000000 --- a/tests/Paket.Tests/RestrictionApplicationSpecs.fs +++ /dev/null @@ -1,19 +0,0 @@ -module Packet.RestrictionApplicationSpecs - -open System.IO -open Paket -open Paket.Domain -open Chessie.ErrorHandling -open FsUnit -open NUnit.Framework -open TestHelpers -open Paket.Requirements - -[] -let ``>= net40 does not include silverlight (#1124)`` () = - /// https://github.com/fsprojects/Paket/issues/1124 - let restrictions = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4))] - let targets = KnownTargetProfiles.DotNetFrameworkProfiles @ KnownTargetProfiles.SilverlightProfiles - let restricted = applyRestrictionsToTargets restrictions targets - - restricted |> shouldEqual KnownTargetProfiles.DotNetFrameworkProfiles \ No newline at end of file From 57730463dfd54c38a049e1e793526b81beda43e5 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 12 Oct 2015 18:29:16 +0200 Subject: [PATCH 4/6] Linting --- src/Paket.Core/PublicAPI.fs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Paket.Core/PublicAPI.fs b/src/Paket.Core/PublicAPI.fs index 676fea3fa7..239b0a741b 100644 --- a/src/Paket.Core/PublicAPI.fs +++ b/src/Paket.Core/PublicAPI.fs @@ -17,7 +17,7 @@ type Dependencies(dependenciesFileName: string) = let listPackages (packages: System.Collections.Generic.KeyValuePair seq) = packages |> Seq.map (fun kv -> - let groupName,packageName = kv.Key + let groupName,packageName = kv.Key groupName.ToString(),packageName.ToString(),kv.Value.Version.ToString()) |> Seq.toList @@ -33,13 +33,13 @@ type Dependencies(dependenciesFileName: string) = path else let parent = dir.Parent - if parent = null then + match parent with + | null -> if withError then failwithf "Could not find '%s'. To use Paket with this solution, please run 'paket init' first." Constants.DependenciesFileName else Constants.DependenciesFileName - else - findInPath(parent, withError) + | _ -> findInPath(parent, withError) let dependenciesFileName = findInPath(DirectoryInfo path,true) verbosefn "found: %s" dependenciesFileName @@ -404,7 +404,9 @@ type Dependencies(dependenciesFileName: string) = let cancellationToken = defaultArg cancellationToken (System.Threading.CancellationToken()) let maxResults = defaultArg maxResults 1000 let sources = this.GetSources() |> Seq.map (fun kv -> kv.Value) |> List.concat |> List.distinct - if sources = [] then [PackageSources.DefaultNugetSource] else sources + match sources with + | [] -> [PackageSources.DefaultNugetSource] + | _ -> sources |> List.choose (fun x -> match x with | Nuget s -> Some s.Url | _ -> None) |> Seq.distinct |> Seq.map (fun url -> From 054b61c9730df6e8fabd6841d1d52898bc5c2303 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 12 Oct 2015 18:48:58 +0200 Subject: [PATCH 5/6] Handle silverlight framework identifiers --- src/Paket.Core/FrameworkHandling.fs | 65 +------- src/Paket.Core/InstallModel.fs | 6 +- src/Paket.Core/PackageResolver.fs | 10 +- src/Paket.Core/Requirements.fs | 68 +++++---- .../FrameworkIdentifierSpecs.fs | 140 ------------------ tests/Paket.Tests/Paket.Tests.fsproj | 7 +- .../RestrictionApplicationSpecs.fs | 4 +- .../RestrictionFilterSpecs.fs | 2 +- 8 files changed, 55 insertions(+), 247 deletions(-) delete mode 100644 tests/Paket.Tests/FrameworkHandling/FrameworkIdentifierSpecs.fs rename tests/Paket.Tests/{Requirements => }/RestrictionFilterSpecs.fs (95%) diff --git a/src/Paket.Core/FrameworkHandling.fs b/src/Paket.Core/FrameworkHandling.fs index f21764908d..471ae81232 100644 --- a/src/Paket.Core/FrameworkHandling.fs +++ b/src/Paket.Core/FrameworkHandling.fs @@ -68,6 +68,7 @@ module KnownAliases = ".", "" ] |> List.map (fun (p,r) -> p.ToLower(),r.ToLower()) + /// Framework Identifier type. type FrameworkIdentifier = | DotNetFramework of FrameworkVersion @@ -83,68 +84,7 @@ type FrameworkIdentifier = | WindowsPhoneSilverlight of string | Silverlight of string - static member private ParseVersion(s:string) = - if s.Length > 0 && s.[0] = 'v' then - match Version.TryParse(s.Substring(1)) with - | true, v -> v - | false, _ -> failwith ("Invalid version syntax: " + s) - else - failwith ("Invalid version syntax: " + s) - - member private x.ApplyOperator y compareFramework compareVersion = - let compareVersion' a b = - let va = FrameworkIdentifier.ParseVersion(a) - let vb = FrameworkIdentifier.ParseVersion(b) - compareVersion va vb - - match x,y with - | DotNetFramework a, DotNetFramework b -> compareFramework a b - | DNX a, DNX b -> compareFramework a b - | DNXCore a, DNXCore b -> compareFramework a b - | MonoAndroid, MonoAndroid -> false - | MonoTouch, MonoTouch -> false - | MonoMac, MonoMac -> false - | XamariniOS, XamariniOS -> false - | XamarinMac, XamarinMac -> false - | Windows a, Windows b -> compareVersion' a b - | WindowsPhoneApp a, WindowsPhoneApp b -> compareVersion' a b - | WindowsPhoneSilverlight a, WindowsPhoneSilverlight b -> compareVersion' a b - | Silverlight a, Silverlight b -> compareVersion' a b - | _ -> false - - /// Is x considered supperior to y - static member (.>) (x:FrameworkIdentifier, y:FrameworkIdentifier) = - x.ApplyOperator y (>) (>) - - /// Is x considered supperior or equal to y - static member (.>=) (x:FrameworkIdentifier, y:FrameworkIdentifier) = - x = y || x .> y - - /// Is x considered inferior to y - static member (.<) (x:FrameworkIdentifier, y:FrameworkIdentifier) = - x.ApplyOperator y (<) (<) - - /// Is x considered inferior or equal to y - static member (.<=) (x:FrameworkIdentifier, y:FrameworkIdentifier) = - x = y || x .< y - - static member IsSameFramework (x:FrameworkIdentifier) y = - x = y || x .< y || x .> y - - static member Min (x:FrameworkIdentifier) y = - match x .<= y, y .<= x with - | true, true -> x - | true, false -> x - | false, true -> y - | false, false -> failwith (sprintf "Not the same framework '%O' and '%O'" x y) - - static member Max (x:FrameworkIdentifier) y = - match x .>= y, y .>= x with - | true, true -> x - | true, false -> x - | false, true -> y - | false, false -> failwith (sprintf "Not the same framework '%O' and '%O'" x y) - + override x.ToString() = match x with | DotNetFramework v -> "net" + v.ShortString() @@ -160,6 +100,7 @@ type FrameworkIdentifier = | WindowsPhoneSilverlight v -> "wp" + v | Silverlight v -> "sl" + v.Replace("v","").Replace(".","") + // returns a list of compatible platforms that this platform also supports member x.SupportedPlatforms = match x with diff --git a/src/Paket.Core/InstallModel.fs b/src/Paket.Core/InstallModel.fs index 476a0d0cfa..f200698ed5 100644 --- a/src/Paket.Core/InstallModel.fs +++ b/src/Paket.Core/InstallModel.fs @@ -241,10 +241,10 @@ type InstallModel = |> List.exists (fun t -> t = target) | FrameworkRestriction.AtLeast target -> folder.GetSinglePlatforms() - |> List.exists (fun t -> t .>= target) + |> List.exists (fun t -> t >= target) | FrameworkRestriction.Between(min,max) -> folder.GetSinglePlatforms() - |> List.exists (fun t -> t .>= min && t .< max) ) + |> List.exists (fun t -> t >= min && t < max) ) this.MapFolders(fun folder -> if referenceApplies folder then @@ -299,7 +299,7 @@ type InstallModel = TargetsFileFolders = this.TargetsFileFolders |> List.map applRestriction - |> List.filter (fun folder -> folder.Targets <> []) } + |> List.filter (fun folder -> folder.Targets <> []) } member this.GetFrameworkAssembliesLazy = lazy ([ for lib in this.ReferenceFileFolders do diff --git a/src/Paket.Core/PackageResolver.fs b/src/Paket.Core/PackageResolver.fs index cd0c5439a9..51ed22a965 100644 --- a/src/Paket.Core/PackageResolver.fs +++ b/src/Paket.Core/PackageResolver.fs @@ -21,16 +21,16 @@ module DependencySetFilter = |> Seq.exists (fun r2 -> match r2 with | FrameworkRestriction.Exactly v2 when v1 = v2 -> true - | FrameworkRestriction.AtLeast v2 when v1 .>= v2 -> true - | FrameworkRestriction.Between(v2,v3) when v1 .>= v2 && v1 .< v3 -> true + | FrameworkRestriction.AtLeast v2 when v1 >= v2 -> true + | FrameworkRestriction.Between(v2,v3) when v1 >= v2 && v1 < v3 -> true | _ -> false) | FrameworkRestriction.AtLeast v1 -> restrictions |> Seq.exists (fun r2 -> match r2 with - | FrameworkRestriction.Exactly v2 when v1 .<= v2 -> true - | FrameworkRestriction.AtLeast v2 when v1 .<= v2 -> true - | FrameworkRestriction.Between(v2,v3) when v1 .<= v2 && v1 .< v3 -> true + | FrameworkRestriction.Exactly v2 when v1 <= v2 -> true + | FrameworkRestriction.AtLeast v2 when v1 <= v2 -> true + | FrameworkRestriction.Between(v2,v3) when v1 <= v2 && v1 < v3 -> true | _ -> false) | _ -> true diff --git a/src/Paket.Core/Requirements.fs b/src/Paket.Core/Requirements.fs index 2d08aaaeac..5b7e12e28b 100644 --- a/src/Paket.Core/Requirements.fs +++ b/src/Paket.Core/Requirements.fs @@ -53,15 +53,15 @@ let private minRestriction = FrameworkRestriction.Exactly(DotNetFramework(Framew let findMaxDotNetRestriction restrictions = minRestriction :: restrictions - |> List.choose (fun (r:FrameworkRestriction) -> + |> List.filter (fun (r:FrameworkRestriction) -> match r with - | FrameworkRestriction.Exactly i -> - match i with - | DotNetFramework f -> Some(f) - | _ -> None - | _ -> None) + | FrameworkRestriction.Exactly r -> r.ToString().StartsWith("net") + | _ -> false) |> List.max - |> DotNetFramework + |> fun r -> + match r with + | FrameworkRestriction.Exactly r -> r + | _ -> failwith "error" let rec optimizeRestrictions restrictions = match restrictions with @@ -178,36 +178,29 @@ let combineRestrictions x y = match y with | FrameworkRestriction.Exactly r' -> if r = r' then [FrameworkRestriction.Exactly r] else [] | FrameworkRestriction.Portable _ -> [] - | FrameworkRestriction.AtLeast r' -> if r' .<= r then [FrameworkRestriction.Exactly r] else [] - | FrameworkRestriction.Between(min,max) -> if min .<= r && r .<= max then [FrameworkRestriction.Exactly r] else [] + | FrameworkRestriction.AtLeast r' -> if r' <= r then [FrameworkRestriction.Exactly r] else [] + | FrameworkRestriction.Between(min,max) -> if min <= r && r <= max then [FrameworkRestriction.Exactly r] else [] | FrameworkRestriction.Portable r -> match y with | FrameworkRestriction.Portable r' -> if r = r' then [FrameworkRestriction.Portable r] else [] | _ -> [] | FrameworkRestriction.AtLeast r -> match y with - | FrameworkRestriction.Exactly r' -> if r .<= r' then [FrameworkRestriction.Exactly r'] else [] + | FrameworkRestriction.Exactly r' -> if r <= r' then [FrameworkRestriction.Exactly r'] else [] | FrameworkRestriction.Portable _ -> [] - | FrameworkRestriction.AtLeast r' -> - if FrameworkIdentifier.IsSameFramework r r' then - [FrameworkRestriction.AtLeast (FrameworkIdentifier.Max r r')] - else - [] - | FrameworkRestriction.Between(min,max) -> if min .<= r && r .<= max then [FrameworkRestriction.Between(r,max)] else [] + | FrameworkRestriction.AtLeast r' -> [FrameworkRestriction.AtLeast (max r r')] + | FrameworkRestriction.Between(min,max) -> if min <= r && r <= max then [FrameworkRestriction.Between(r,max)] else [] | FrameworkRestriction.Between(min1,max1) -> match y with - | FrameworkRestriction.Exactly r -> if min1 .<= r && r .<= max1 then [FrameworkRestriction.Exactly r] else [] + | FrameworkRestriction.Exactly r -> if min1 <= r && r <= max1 then [FrameworkRestriction.Exactly r] else [] | FrameworkRestriction.Portable _ -> [] - | FrameworkRestriction.AtLeast r -> if min1 .<= r && r .<= max1 then [FrameworkRestriction.Between(r,max1)] else [] - | FrameworkRestriction.Between(min2, max2) -> - if FrameworkIdentifier.IsSameFramework min1 min2 && FrameworkIdentifier.IsSameFramework max1 max2 then - let min' = FrameworkIdentifier.Max min1 min2 - let max' = FrameworkIdentifier.Min max1 max2 - if min' .< max' then [FrameworkRestriction.Between(min',max')] else - if min' = max' then [FrameworkRestriction.Exactly(min')] else - [] - else - [] + | FrameworkRestriction.AtLeast r -> if min1 <= r && r <= max1 then [FrameworkRestriction.Between(r,max1)] else [] + | FrameworkRestriction.Between(min2,max2) -> + let min' = max min1 min2 + let max' = min max1 max2 + if min' < max' then [FrameworkRestriction.Between(min',max')] else + if min' = max' then [FrameworkRestriction.Exactly(min')] else + [] let filterRestrictions (list1:FrameworkRestrictions) (list2:FrameworkRestrictions) = match list1,list2 with @@ -220,6 +213,22 @@ let filterRestrictions (list1:FrameworkRestrictions) (list2:FrameworkRestriction if c <> [] then yield! c] |> optimizeRestrictions +let inline frameworkCategory (fw:FrameworkIdentifier) = + match fw with + | DotNetFramework _ -> ".NET" + | Silverlight _ -> "Silverlight" + | DNX _ -> "DNX" + | DNXCore _ -> "DNXCore" + | MonoAndroid _ -> "MonoAndroid" + | MonoMac _ -> "MonoMac" + | MonoTouch _ -> "MonoTouch" + | Windows _ -> "Windows" + | WindowsPhoneApp _ -> "WindowsPhoneApp" + | WindowsPhoneSilverlight _ -> "WindowsPhoneSilverlight" + | XamarinMac _ -> "XamarinMac" + | XamariniOS _ -> "XamariniOS" + + /// Get if a target should be considered with the specified restrictions let isTargetMatchingRestrictions (restrictions:FrameworkRestrictions) = function | SinglePlatform pf -> @@ -228,8 +237,8 @@ let isTargetMatchingRestrictions (restrictions:FrameworkRestrictions) = function match restriction with | FrameworkRestriction.Exactly fw -> pf = fw | FrameworkRestriction.Portable _ -> false - | FrameworkRestriction.AtLeast fw -> pf .>= fw - | FrameworkRestriction.Between(min,max) -> pf .>= min && pf .< max) + | FrameworkRestriction.AtLeast fw -> pf >= fw && frameworkCategory pf = frameworkCategory fw + | FrameworkRestriction.Between(min,max) -> pf >= min && pf < max && frameworkCategory pf = frameworkCategory min) | PortableProfile(_,_) -> restrictions |> List.exists (fun restriction -> @@ -242,7 +251,6 @@ let applyRestrictionsToTargets (restrictions:FrameworkRestrictions) (targets: Ta let result = targets |> List.filter (isTargetMatchingRestrictions restrictions) result - type ContentCopySettings = | Omit | Overwrite diff --git a/tests/Paket.Tests/FrameworkHandling/FrameworkIdentifierSpecs.fs b/tests/Paket.Tests/FrameworkHandling/FrameworkIdentifierSpecs.fs deleted file mode 100644 index c1021cdfc4..0000000000 --- a/tests/Paket.Tests/FrameworkHandling/FrameworkIdentifierSpecs.fs +++ /dev/null @@ -1,140 +0,0 @@ -module Paket.FrameworkHandling.FrameworkIdentifierSpecs - -open System.IO -open Paket -open Paket.Domain -open Chessie.ErrorHandling -open FsUnit -open NUnit.Framework -open TestHelpers -open Paket.Requirements - -let silverlight x = FrameworkIdentifier.Silverlight(x) -let dotnet x = FrameworkIdentifier.DotNetFramework(x) - -[] -let ``.>= should work for dotnet``() = - dotnet FrameworkVersion.V4 .>= dotnet FrameworkVersion.V1 - |> shouldEqual true - dotnet FrameworkVersion.V4 .>= dotnet FrameworkVersion.V4 - |> shouldEqual true - dotnet FrameworkVersion.V4 .>= dotnet FrameworkVersion.V4_5 - |> shouldEqual false - -[] -let ``.> should work for dotnet``() = - dotnet FrameworkVersion.V4 .> dotnet FrameworkVersion.V1 - |> shouldEqual true - dotnet FrameworkVersion.V4 .> dotnet FrameworkVersion.V4 - |> shouldEqual false - dotnet FrameworkVersion.V4 .> dotnet FrameworkVersion.V4_5 - |> shouldEqual false - -[] -let ``.<= should work for dotnet``() = - dotnet FrameworkVersion.V4 .<= dotnet FrameworkVersion.V1 - |> shouldEqual false - dotnet FrameworkVersion.V4 .<= dotnet FrameworkVersion.V4 - |> shouldEqual true - dotnet FrameworkVersion.V4 .<= dotnet FrameworkVersion.V4_5 - |> shouldEqual true - -[] -let ``.< should work for dotnet``() = - dotnet FrameworkVersion.V4 .< dotnet FrameworkVersion.V1 - |> shouldEqual false - dotnet FrameworkVersion.V4 .< dotnet FrameworkVersion.V4 - |> shouldEqual false - dotnet FrameworkVersion.V4 .< dotnet FrameworkVersion.V4_5 - |> shouldEqual true - -[] -let ``.>= should work for silverlight``() = - silverlight "v4.0" .>= silverlight "v3.0" - |> shouldEqual true - silverlight "v4.0" .>= silverlight "v4.0" - |> shouldEqual true - silverlight "v4.0" .>= silverlight "v5.0" - |> shouldEqual false - -[] -let ``.> should work for silverlight``() = - silverlight "v4.0" .> silverlight "v3.0" - |> shouldEqual true - silverlight "v4.0" .> silverlight "v4.0" - |> shouldEqual false - silverlight "v4.0" .> silverlight "v5.0" - |> shouldEqual false - -[] -let ``.<= should work for silverlight``() = - silverlight "v4.0" .<= silverlight "v3.0" - |> shouldEqual false - silverlight "v4.0" .<= silverlight "v4.0" - |> shouldEqual true - silverlight "v4.0" .<= silverlight "v5.0" - |> shouldEqual true - -[] -let ``.< should work for silverlight``() = - silverlight "v4.0" .< silverlight "v3.0" - |> shouldEqual false - silverlight "v4.0" .< silverlight "v4.0" - |> shouldEqual false - silverlight "v4.0" .< silverlight "v5.0" - |> shouldEqual true - -[] -let ``Same framework can be detected``() = - FrameworkIdentifier.IsSameFramework (silverlight "v4.0") (silverlight "v3.0") - |> shouldEqual true - FrameworkIdentifier.IsSameFramework (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V1) - |> shouldEqual true - FrameworkIdentifier.IsSameFramework (dotnet FrameworkVersion.V4) (silverlight "v4.0") - |> shouldEqual false - -[] -let ``Min works for dotnet``() = - FrameworkIdentifier.Min (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V1) - |> shouldEqual (dotnet FrameworkVersion.V1) - FrameworkIdentifier.Min (dotnet FrameworkVersion.V1) (dotnet FrameworkVersion.V4) - |> shouldEqual (dotnet FrameworkVersion.V1) - FrameworkIdentifier.Min (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V4) - |> shouldEqual (dotnet FrameworkVersion.V4) - -[] -let ``Max works for dotnet``() = - FrameworkIdentifier.Max (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V1) - |> shouldEqual (dotnet FrameworkVersion.V4) - FrameworkIdentifier.Max (dotnet FrameworkVersion.V1) (dotnet FrameworkVersion.V4) - |> shouldEqual (dotnet FrameworkVersion.V4) - FrameworkIdentifier.Max (dotnet FrameworkVersion.V4) (dotnet FrameworkVersion.V4) - |> shouldEqual (dotnet FrameworkVersion.V4) - -[] -let ``Min works for silverlight``() = - FrameworkIdentifier.Min (silverlight "v4.0") (silverlight "v3.0") - |> shouldEqual (silverlight "v3.0") - FrameworkIdentifier.Min (silverlight "v3.0") (silverlight "v4.0") - |> shouldEqual (silverlight "v3.0") - FrameworkIdentifier.Min (silverlight "v4.0") (silverlight "v4.0") - |> shouldEqual (silverlight "v4.0") - -[] -let ``Max works for silverlight``() = - FrameworkIdentifier.Max (silverlight "v4.0") (silverlight "v3.0") - |> shouldEqual (silverlight "v4.0") - FrameworkIdentifier.Max (silverlight "v3.0") (silverlight "v4.0") - |> shouldEqual (silverlight "v4.0") - FrameworkIdentifier.Max (silverlight "v4.0") (silverlight "v4.0") - |> shouldEqual (silverlight "v4.0") - -[] -let ``Max throw for mixed framework``() = - FrameworkIdentifier.Max (silverlight "v4.0") (dotnet FrameworkVersion.V4) - |> ignore - -[] -let ``Min throw for mixed framework``() = - FrameworkIdentifier.Min (silverlight "v4.0") (dotnet FrameworkVersion.V4) - |> ignore \ No newline at end of file diff --git a/tests/Paket.Tests/Paket.Tests.fsproj b/tests/Paket.Tests/Paket.Tests.fsproj index 7c98ce8846..733c157d23 100644 --- a/tests/Paket.Tests/Paket.Tests.fsproj +++ b/tests/Paket.Tests/Paket.Tests.fsproj @@ -1,4 +1,4 @@ - + @@ -90,6 +90,7 @@ + Always @@ -307,10 +308,8 @@ - - - + diff --git a/tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs b/tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs index 56dbb2eebc..04237c032d 100644 --- a/tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs +++ b/tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs @@ -1,4 +1,4 @@ -module Paket.Requirements.RestrictionApplicationSpecs +module Paket.Requirements.RestrictionApplicationSpecs open Paket open FsUnit @@ -45,7 +45,7 @@ module TestTargetProfiles = SilverlightProfiles @ WindowsPhoneSilverlightProfiles @ [SinglePlatform(MonoAndroid) - SinglePlatform(MonoTouch) + SinglePlatform(MonoTouch) SinglePlatform(XamariniOS) SinglePlatform(XamarinMac) SinglePlatform(WindowsPhoneApp "v8.1") diff --git a/tests/Paket.Tests/Requirements/RestrictionFilterSpecs.fs b/tests/Paket.Tests/RestrictionFilterSpecs.fs similarity index 95% rename from tests/Paket.Tests/Requirements/RestrictionFilterSpecs.fs rename to tests/Paket.Tests/RestrictionFilterSpecs.fs index 6e060ef002..286db01655 100644 --- a/tests/Paket.Tests/Requirements/RestrictionFilterSpecs.fs +++ b/tests/Paket.Tests/RestrictionFilterSpecs.fs @@ -1,4 +1,4 @@ -module Paket.Requirements.RestrictionFilterSpecs +module Paket.RestrictionFilterSpecs open System.IO open Paket From f2a2794786beaa0e934ec0d6ea799b4a94fa84b0 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 13 Oct 2015 10:10:02 +0200 Subject: [PATCH 6/6] Linting --- src/Paket.Core/Requirements.fs | 90 ++++++++++++++++------------------ 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/src/Paket.Core/Requirements.fs b/src/Paket.Core/Requirements.fs index 5b7e12e28b..6aeeac5aa6 100644 --- a/src/Paket.Core/Requirements.fs +++ b/src/Paket.Core/Requirements.fs @@ -13,7 +13,7 @@ type FrameworkRestriction = | Between of FrameworkIdentifier * FrameworkIdentifier override this.ToString() = - match this with + match this with | FrameworkRestriction.Exactly r -> r.ToString() | FrameworkRestriction.Portable r -> r | FrameworkRestriction.AtLeast r -> ">= " + r.ToString() @@ -72,7 +72,7 @@ let rec optimizeRestrictions restrictions = let newRestrictions' = restrictions |> List.distinct - |> List.sort + |> List.sort let newRestrictions = match newRestrictions' |> Seq.tryFind (function | FrameworkRestriction.AtLeast r -> true | _ -> false) with @@ -81,14 +81,15 @@ let rec optimizeRestrictions restrictions = let currentVersion = match r with | FrameworkRestriction.AtLeast(DotNetFramework(x)) -> x - | x -> failwithf "Unknown .NET moniker %O" x + | x -> failwithf "Unknown .NET moniker %O" x let isLowerVersion x = let isMatching x = if x = FrameworkVersion.V3_5 && currentVersion = FrameworkVersion.V4 then true else if x = FrameworkVersion.V4_Client && currentVersion = FrameworkVersion.V4_5 then true else - let hasFrameworksBetween = KnownTargetProfiles.DotNetFrameworkVersions |> Seq.exists (fun p -> p > x && p < currentVersion) - not hasFrameworksBetween + KnownTargetProfiles.DotNetFrameworkVersions + |> Seq.exists (fun p -> p > x && p < currentVersion) + |> not match x with | FrameworkRestriction.Exactly(DotNetFramework(x)) -> isMatching x @@ -102,7 +103,7 @@ let rec optimizeRestrictions restrictions = match n with | FrameworkRestriction.Exactly(DotNetFramework(x)) -> x | FrameworkRestriction.AtLeast(DotNetFramework(x)) -> x - | x -> failwithf "Unknown .NET moniker %O" x + | x -> failwithf "Unknown .NET moniker %O" x (newRestrictions' |> List.filter (fun x -> x <> r && x <> n)) @ [FrameworkRestriction.AtLeast(DotNetFramework(newLowest))] @@ -111,8 +112,6 @@ let rec optimizeRestrictions restrictions = let optimizeDependencies packages = - let grouped = packages |> List.groupBy (fun (n,v,_) -> n,v) - let invertedRestrictions = let expanded = [for (n,vr,r:FrameworkRestrictions) in packages do @@ -136,71 +135,66 @@ let optimizeDependencies packages = let emptyRestrictions = [for (n,vr,r:FrameworkRestrictions) in packages do - if r = [] then + if List.isEmpty r then yield n,vr] |> Set.ofList + let grouped = packages |> List.filter (fun (name,_,_) -> name <> PackageName "") |> List.groupBy (fun (n,v,_) -> n,v) [for (name,versionRequirement:VersionRequirement),group in grouped do - if name <> PackageName "" then - if not (Set.isEmpty emptyRestrictions) && Set.contains (name,versionRequirement) emptyRestrictions then - yield name,versionRequirement,[] - else - let plain = - group - |> List.map (fun (_,_,res) -> res) - |> List.concat - |> List.distinct - |> List.sort - - let localMaxDotNetRestriction = findMaxDotNetRestriction plain - let globalMax = defaultArg globalMax localMaxDotNetRestriction + if not (Set.isEmpty emptyRestrictions) && Set.contains (name,versionRequirement) emptyRestrictions then + yield name,versionRequirement,[] + else + let plain = + group + |> List.map (fun (_,_,res) -> res) + |> List.concat + |> List.distinct + |> List.sort - let dotnetRestrictions,others = List.partition (function | FrameworkRestriction.Exactly(DotNetFramework(_)) -> true | FrameworkRestriction.AtLeast(DotNetFramework(_)) -> true | _ -> false) plain + let localMaxDotNetRestriction = findMaxDotNetRestriction plain + let globalMax = defaultArg globalMax localMaxDotNetRestriction - let restrictions' = - dotnetRestrictions - |> List.map (fun restriction -> - match restriction with - | FrameworkRestriction.Exactly r -> - if r = localMaxDotNetRestriction && r = globalMax then - FrameworkRestriction.AtLeast r - else - restriction - | _ -> restriction) + let dotnetRestrictions,others = List.partition (function | FrameworkRestriction.Exactly(DotNetFramework(_)) -> true | FrameworkRestriction.AtLeast(DotNetFramework(_)) -> true | _ -> false) plain - let restrictions = optimizeRestrictions restrictions' + let restrictions' = + dotnetRestrictions + |> List.map (fun restriction -> + match restriction with + | FrameworkRestriction.Exactly r when r = localMaxDotNetRestriction && r = globalMax -> + FrameworkRestriction.AtLeast r + | _ -> restriction) - yield name,versionRequirement,others @ restrictions] + yield name,versionRequirement,others @ optimizeRestrictions restrictions'] let combineRestrictions x y = match x with | FrameworkRestriction.Exactly r -> match y with - | FrameworkRestriction.Exactly r' -> if r = r' then [FrameworkRestriction.Exactly r] else [] - | FrameworkRestriction.Portable _ -> [] - | FrameworkRestriction.AtLeast r' -> if r' <= r then [FrameworkRestriction.Exactly r] else [] - | FrameworkRestriction.Between(min,max) -> if min <= r && r <= max then [FrameworkRestriction.Exactly r] else [] + | FrameworkRestriction.Exactly r' when r = r' -> [FrameworkRestriction.Exactly r] + | FrameworkRestriction.AtLeast r' when r' <= r -> [FrameworkRestriction.Exactly r] + | FrameworkRestriction.Between(min,max) when min <= r && r <= max -> [FrameworkRestriction.Exactly r] + | _ -> [] | FrameworkRestriction.Portable r -> match y with - | FrameworkRestriction.Portable r' -> if r = r' then [FrameworkRestriction.Portable r] else [] + | FrameworkRestriction.Portable r' when r = r' ->[FrameworkRestriction.Portable r] | _ -> [] | FrameworkRestriction.AtLeast r -> match y with - | FrameworkRestriction.Exactly r' -> if r <= r' then [FrameworkRestriction.Exactly r'] else [] - | FrameworkRestriction.Portable _ -> [] + | FrameworkRestriction.Exactly r' when r <= r' -> [FrameworkRestriction.Exactly r'] | FrameworkRestriction.AtLeast r' -> [FrameworkRestriction.AtLeast (max r r')] - | FrameworkRestriction.Between(min,max) -> if min <= r && r <= max then [FrameworkRestriction.Between(r,max)] else [] + | FrameworkRestriction.Between(min,max) when min <= r && r <= max -> [FrameworkRestriction.Between(r,max)] + | _ -> [] | FrameworkRestriction.Between(min1,max1) -> match y with - | FrameworkRestriction.Exactly r -> if min1 <= r && r <= max1 then [FrameworkRestriction.Exactly r] else [] - | FrameworkRestriction.Portable _ -> [] - | FrameworkRestriction.AtLeast r -> if min1 <= r && r <= max1 then [FrameworkRestriction.Between(r,max1)] else [] - | FrameworkRestriction.Between(min2,max2) -> + | FrameworkRestriction.Exactly r when min1 <= r && r <= max1 -> [FrameworkRestriction.Exactly r] + | FrameworkRestriction.AtLeast r when min1 <= r && r <= max1 -> [FrameworkRestriction.Between(r,max1)] + | FrameworkRestriction.Between(min2,max2) -> let min' = max min1 min2 let max' = min max1 max2 if min' < max' then [FrameworkRestriction.Between(min',max')] else if min' = max' then [FrameworkRestriction.Exactly(min')] else [] + | _ -> [] let filterRestrictions (list1:FrameworkRestrictions) (list2:FrameworkRestrictions) = match list1,list2 with @@ -239,7 +233,7 @@ let isTargetMatchingRestrictions (restrictions:FrameworkRestrictions) = function | FrameworkRestriction.Portable _ -> false | FrameworkRestriction.AtLeast fw -> pf >= fw && frameworkCategory pf = frameworkCategory fw | FrameworkRestriction.Between(min,max) -> pf >= min && pf < max && frameworkCategory pf = frameworkCategory min) - | PortableProfile(_,_) -> + | PortableProfile(_) -> restrictions |> List.exists (fun restriction -> match restriction with