Skip to content

Commit

Permalink
start fixing #2317 because #2333 shows that its relevant.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed May 13, 2017
1 parent 91f5c1f commit 80e94ed
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 74 deletions.
1 change: 1 addition & 0 deletions src/Paket.Core/Dependencies/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/PaketConfigFiles/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
91 changes: 54 additions & 37 deletions src/Paket.Core/Versioning/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

Expand Down Expand Up @@ -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
Expand All @@ -749,7 +766,7 @@ module KnownTargetProfiles =

let AllProfiles =
(AllNativeProfiles |> List.map SinglePlatform) @
AllDotNetStandardProfiles @
AllDotNetStandardAndCoreProfiles @
AllDotNetProfiles

let FindPortableProfile name =
Expand Down
64 changes: 31 additions & 33 deletions src/Paket.Core/Versioning/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ 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
| Portable _ -> None
| 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
Expand Down Expand Up @@ -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) ->
Expand All @@ -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) ->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion tests/Paket.Tests/Versioning/FrameworkCompatibilitySpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ open Paket.Requirements

[<Test>]
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

0 comments on commit 80e94ed

Please sign in to comment.