diff --git a/src/Paket.Core/Dependencies/PackageResolver.fs b/src/Paket.Core/Dependencies/PackageResolver.fs index cc848f2e86..752570ce6b 100644 --- a/src/Paket.Core/Dependencies/PackageResolver.fs +++ b/src/Paket.Core/Dependencies/PackageResolver.fs @@ -57,6 +57,7 @@ module DependencySetFilter = let _,_,restrictions = dependency let restrictions = restrictions |> getRestrictionList if Seq.isEmpty restrictions then true else + // TODO: fix broken logic match restriction with | FrameworkRestriction.Exactly v1 -> restrictions diff --git a/src/Paket.Core/PaketConfigFiles/ProjectFile.fs b/src/Paket.Core/PaketConfigFiles/ProjectFile.fs index 0a9b687af8..d2215a4bf9 100644 --- a/src/Paket.Core/PaketConfigFiles/ProjectFile.fs +++ b/src/Paket.Core/PaketConfigFiles/ProjectFile.fs @@ -736,8 +736,8 @@ module ProjectFile = // I don't think there is anyone actually using this part, but it's there for backwards compat. let netCoreRestricted = model.ApplyFrameworkRestrictions - [ FrameworkRestriction.AtLeast (FrameworkIdentifier.DotNetStandard DotNetStandardVersion.V1_0); - FrameworkRestriction.AtLeast (FrameworkIdentifier.DotNetCore DotNetCoreVersion.V1_0) ] + ((List.map DotNetCore KnownTargetProfiles.DotNetCoreVersions @ List.map DotNetStandard KnownTargetProfiles.DotNetStandardVersions) + |> List.map FrameworkRestriction.Exactly) // handle legacy conditions let conditions = diff --git a/src/Paket.Core/Versioning/FrameworkHandling.fs b/src/Paket.Core/Versioning/FrameworkHandling.fs index 52bdd945ad..56d3a0c26e 100644 --- a/src/Paket.Core/Versioning/FrameworkHandling.fs +++ b/src/Paket.Core/Versioning/FrameworkHandling.fs @@ -341,42 +341,59 @@ type FrameworkIdentifier = | XamariniOS _, XamariniOS _ -> true | Native _, Native _ -> true | _ -> false - - /// TODO: some notion of an increasing/decreasing sequence of FrameworkIdentitifers, so that Between(bottom, top) constraints can enumerate the list - - member x.IsCompatible y = - x = y || - (x.SupportedPlatforms |> Seq.exists (fun x' -> x' = y && not (x'.IsSameCategoryAs x))) || - (y.SupportedPlatforms |> Seq.exists (fun y' -> y' = x && not (y'.IsSameCategoryAs y))) - - member x.IsAtLeast y = - if x.IsSameCategoryAs y then - x >= y - else - let isCompatible() = - y.SupportedPlatforms - |> Seq.exists x.IsAtLeast - - match x,y with - | DotNetStandard _, DotNetFramework _ -> isCompatible() - | DotNetFramework _, DotNetStandard _ -> isCompatible() - | _ -> false - - member x.IsAtMost y = - if x.IsSameCategoryAs y then - x < y - else - let isCompatible() = - y.SupportedPlatforms - |> Seq.exists x.IsAtMost - - match x,y with - | DotNetStandard _, DotNetFramework _ -> isCompatible() - | DotNetFramework _, DotNetStandard _ -> isCompatible() - | _ -> false - - member x.IsBetween(a,b) = x.IsAtLeast a && x.IsAtMost b + // TODO: some notion of an increasing/decreasing sequence of FrameworkIdentitifers, so that Between(bottom, top) constraints can enumerate the list + /// true when x is supported by y, for example netstandard15 is supported by netcore10 + member x.IsSupportedBy y = + x = y || + (y.SupportedPlatforms |> Seq.exists (fun s -> x.IsSupportedBy s)) + //x = y || + // (x.SupportedPlatforms |> Seq.exists (fun x' -> x' = y && not (x'.IsSameCategoryAs x))) || + // (y.SupportedPlatforms |> Seq.exists (fun y' -> y' = x && not (y'.IsSameCategoryAs y))) + + /// true when x is at least (>=) y ie when y is supported by x, for example netcore10 >= netstandard15 as netstandard15 is supported by netcore10. + /// Note that this relation is not complete, for example for WindowsPhoneSilverlightv7.0 and Windowsv4.5 both <= and >= are false from this definition as + /// no platform supports the other. + member x.IsAtLeast (y:FrameworkIdentifier) = + y.IsSupportedBy x + //if x.IsSameCategoryAs y then + // x >= y + //else + // let isCompatible() = + // y.SupportedPlatforms + // |> Seq.exists x.IsAtLeast + // + // match x,y with + // | DotNetStandard _, DotNetFramework _ -> isCompatible() + // | DotNetFramework _, DotNetStandard _ -> isCompatible() + // | _ -> false + + /// Get all platforms y for which x >= y holds + member x.SupportedPlatformsTransitive = + let findNewPlats (known:FrameworkIdentifier list) (lastStep:FrameworkIdentifier list) = + lastStep + |> List.collect (fun k -> k.SupportedPlatforms) + |> List.filter (fun k -> known |> Seq.contains k |> not) + + Seq.initInfinite (fun _ -> 1) + |> Seq.scan (fun state _ -> + match state with + | Some (known, lastStep) -> + match findNewPlats known lastStep with + | [] -> None + | items -> Some (known @ items, items) + | None -> None) (Some ([x], [x])) + |> Seq.takeWhile (fun i -> i.IsSome) + |> Seq.choose id + |> Seq.last + |> fst + + /// x < y, see y >= x && x <> y + member x.IsSmallerThan y = + x.IsSupportedBy y && x <> y + + /// Note that this returns true only when a >= x and x < b holds. + member x.IsBetween(a,b) = x.IsAtLeast a && x.IsSmallerThan b module FrameworkDetection = @@ -727,7 +744,7 @@ module KnownTargetProfiles = SinglePlatform(WindowsPhoneApp "v8.1")] @ (AllPortableProfiles |> List.map PortableProfile) - let AllDotNetStandardProfiles = + let AllDotNetStandardAndCoreProfiles = DotNetStandardProfiles @ DotNetCoreProfiles // only used in "should understand aot in runtimes" test @@ -749,7 +766,7 @@ module KnownTargetProfiles = let AllProfiles = (AllNativeProfiles |> List.map SinglePlatform) @ - AllDotNetStandardProfiles @ + AllDotNetStandardAndCoreProfiles @ AllDotNetProfiles let FindPortableProfile name = diff --git a/src/Paket.Core/Versioning/Requirements.fs b/src/Paket.Core/Versioning/Requirements.fs index ee0177c8ac..e17bae7f74 100644 --- a/src/Paket.Core/Versioning/Requirements.fs +++ b/src/Paket.Core/Versioning/Requirements.fs @@ -20,6 +20,7 @@ type FrameworkRestriction = | FrameworkRestriction.AtLeast r -> ">= " + r.ToString() | FrameworkRestriction.Between(min,max) -> sprintf ">= %O < %O" min max + // TODO: remove broken api member x.GetOneIdentifier = match x with | Exactly r -> Some r @@ -27,6 +28,7 @@ type FrameworkRestriction = | AtLeast r -> Some r | Between(r, _) -> Some r + // TODO: remove broken api /// Return if the parameter is a restriction of the same framework category (dotnet, windows phone, silverlight, ...) member x.IsSameCategoryAs (y : FrameworkRestriction) = match (x.GetOneIdentifier, y.GetOneIdentifier) with @@ -85,9 +87,13 @@ let parseRestrictions failImmediatly (text:string) = else yield FrameworkRestriction.Exactly x] +// TODO: remove broken api let private minRestriction = FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V1)) + +// TODO: remove broken api let private minStandardRestriction = FrameworkRestriction.Exactly(DotNetStandard(DotNetStandardVersion.V1_0)) +// TODO: remove broken api let findMaxDotNetRestriction restrictions = minRestriction :: restrictions |> List.filter (fun (r:FrameworkRestriction) -> @@ -100,6 +106,7 @@ let findMaxDotNetRestriction restrictions = | FrameworkRestriction.Exactly r -> r | _ -> failwith "error" +// TODO: remove broken api let findMaxStandardRestriction restrictions = minStandardRestriction :: restrictions |> List.filter (fun (r:FrameworkRestriction) -> @@ -377,26 +384,26 @@ let optimizeDependencies originalDependencies = newRestictions else newRestictions - |> List.map (fun (name,vr,rs) -> - let newRs = - rs - |> List.collect (function - | FrameworkRestriction.Exactly(DotNetStandard(r)) -> - let compatible = - KnownTargetProfiles.DotNetFrameworkIdentifiers - |> List.filter (fun p -> p.IsCompatible(DotNetStandard r)) - |> List.map (fun p -> FrameworkRestriction.Exactly p) - FrameworkRestriction.AtLeast(DotNetStandard(r)) :: compatible - | FrameworkRestriction.AtLeast(DotNetStandard(r)) -> - let compatible = - KnownTargetProfiles.DotNetFrameworkIdentifiers - |> List.filter (fun p -> p.IsCompatible(DotNetStandard r)) - |> List.map (fun p -> FrameworkRestriction.AtLeast p) - FrameworkRestriction.AtLeast(DotNetStandard(r)) :: compatible - | r -> [r]) - |> optimizeRestrictions - - name,vr,newRs) + //|> List.map (fun (name,vr,rs) -> + // let newRs = + // rs + // |> List.collect (function + // | FrameworkRestriction.Exactly(DotNetStandard(r)) -> + // let compatible = + // KnownTargetProfiles.DotNetFrameworkIdentifiers + // |> List.filter (fun p -> p.IsCompatible(DotNetStandard r)) + // |> List.map (fun p -> FrameworkRestriction.Exactly p) + // FrameworkRestriction.AtLeast(DotNetStandard(r)) :: compatible + // | FrameworkRestriction.AtLeast(DotNetStandard(r)) -> + // let compatible = + // KnownTargetProfiles.DotNetFrameworkIdentifiers + // |> List.filter (fun p -> p.IsCompatible(DotNetStandard r)) + // |> List.map (fun p -> FrameworkRestriction.AtLeast p) + // FrameworkRestriction.AtLeast(DotNetStandard(r)) :: compatible + // | r -> [r]) + // |> optimizeRestrictions + // + // name,vr,newRs) newRestictions @@ -511,22 +518,13 @@ let isTargetMatchingRestrictions = match pf with | Native(_) -> true | _ -> false - | FrameworkRestriction.Exactly fw -> - match fw, pf with - | DotNetFramework _, DotNetStandard _ -> false - | DotNetStandard _, DotNetFramework _ -> false - | _ -> pf.IsCompatible(fw) + | FrameworkRestriction.Exactly fw -> + pf = fw | FrameworkRestriction.Portable _ -> false | FrameworkRestriction.AtLeast fw -> - match fw, pf with - | DotNetFramework _, DotNetStandard _ -> false - | DotNetStandard _, DotNetFramework _ -> false - | _ -> pf.IsAtLeast(fw) + pf.IsAtLeast(fw) | FrameworkRestriction.Between(min,max) -> - match min, pf with - | DotNetFramework _, DotNetStandard _ -> false - | DotNetStandard _, DotNetFramework _ -> false - | _ -> pf.IsBetween(min,max)) + pf.IsBetween(min,max)) | _ -> restrictions |> List.exists (fun restriction -> diff --git a/tests/Paket.Tests/InstallModel/Xml/System.Security.Cryptography.Algorithms.fs b/tests/Paket.Tests/InstallModel/Xml/System.Security.Cryptography.Algorithms.fs index cb5741535c..751aeef144 100644 --- a/tests/Paket.Tests/InstallModel/Xml/System.Security.Cryptography.Algorithms.fs +++ b/tests/Paket.Tests/InstallModel/Xml/System.Security.Cryptography.Algorithms.fs @@ -97,4 +97,5 @@ let ``should generate Xml for System.Security.Cryptography.Algorithms in CSharp ctx.ChooseNodes |> (fun n -> n.Head.OuterXml) |> normalizeXml - result |> shouldEqual (normalizeXml expected) + let expectedXml = normalizeXml expected + result |> shouldEqual expectedXml diff --git a/tests/Paket.Tests/Versioning/FrameworkCompatibilitySpecs.fs b/tests/Paket.Tests/Versioning/FrameworkCompatibilitySpecs.fs index 19100c5e63..f43de1c97b 100644 --- a/tests/Paket.Tests/Versioning/FrameworkCompatibilitySpecs.fs +++ b/tests/Paket.Tests/Versioning/FrameworkCompatibilitySpecs.fs @@ -30,6 +30,12 @@ open Paket.Requirements [] let ``net46 should be compatible with netstandard13``() = - (DotNetFramework FrameworkVersion.V4_6).IsCompatible (DotNetStandard DotNetStandardVersion.V1_3) + (DotNetFramework FrameworkVersion.V4_6).IsAtLeast (DotNetStandard DotNetStandardVersion.V1_3) + |> shouldEqual true + + (DotNetStandard DotNetStandardVersion.V1_3).IsSupportedBy (DotNetFramework FrameworkVersion.V4_6) + |> shouldEqual true + + (DotNetStandard DotNetStandardVersion.V1_3).IsSmallerThan (DotNetFramework FrameworkVersion.V4_6) |> shouldEqual true