Skip to content

Commit

Permalink
setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudRoutine committed Apr 14, 2017
1 parent 3a17495 commit c8f8e2b
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 81 deletions.
179 changes: 107 additions & 72 deletions src/Paket.Core/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,68 @@
open System.IO
open System


/// The .NET Standard version.
// Each time a new version is added NuGetPackageCache.CurrentCacheVersion should be bumped.
[<RequireQualifiedAccess>]
type DotNetStandardVersion =
| V1_0
| V1_1
| V1_2
| V1_3
| V1_4
| V1_5
| V1_6
| V2_0
member private this.NumKey =
match this with
| V1_0 -> 0
| V1_1 -> 1
| V1_2 -> 2
| V1_3 -> 3
| V1_4 -> 4
| V1_5 -> 5
| V1_6 -> 6
| V2_0 -> 7
static member private FromNum num =
match num with
| 0 -> V1_0
| 1 -> V1_1
| 2 -> V1_2
| 3 -> V1_3
| 4 -> V1_4
| 5 -> V1_5
| 6 -> V1_6
| 7 -> V2_0
| _ -> failwithf "'%i' has no corresponding framework version" num

static member (<->) (lower:DotNetStandardVersion,upper:DotNetStandardVersion) =
if lower.NumKey < upper.NumKey then
[ lower.NumKey .. upper.NumKey ] |> List.map DotNetStandardVersion.FromNum
else
[ lower.NumKey .. -1 .. upper.NumKey ] |> List.map DotNetStandardVersion.FromNum

override this.ToString() =
match this with
| V1_0 -> "v1.0"
| V1_1 -> "v1.1"
| V1_2 -> "v1.2"
| V1_3 -> "v1.3"
| V1_4 -> "v1.4"
| V1_5 -> "v1.5"
| V1_6 -> "v1.6"
| V2_0 -> "v2.0"
member this.ShortString() =
match this with
| DotNetStandardVersion.V1_0 -> "10"
| DotNetStandardVersion.V1_1 -> "11"
| DotNetStandardVersion.V1_2 -> "12"
| DotNetStandardVersion.V1_3 -> "13"
| DotNetStandardVersion.V1_4 -> "14"
| DotNetStandardVersion.V1_5 -> "15"
| DotNetStandardVersion.V1_6 -> "16"
| DotNetStandardVersion.V2_0 -> "20"

[<RequireQualifiedAccess>]
/// The Framework version.
// Each time a new version is added NuGetPackageCache.CurrentCacheVersion should be bumped.
Expand Down Expand Up @@ -110,66 +172,28 @@ type FrameworkVersion =
| FrameworkVersion.V4_7 -> "47"
| FrameworkVersion.V5_0 -> "50"

[<RequireQualifiedAccess>]
/// The .NET Standard version.
// Each time a new version is added NuGetPackageCache.CurrentCacheVersion should be bumped.
type DotNetStandardVersion =
| V1_0
| V1_1
| V1_2
| V1_3
| V1_4
| V1_5
| V1_6
| V2_0
member private this.NumKey =
member this.NetStandardCompatible =
match this with
| V1_0 -> 0
| V1_1 -> 1
| V1_2 -> 2
| V1_3 -> 3
| V1_4 -> 4
| V1_5 -> 5
| V1_6 -> 6
| V2_0 -> 7
static member private FromNum num =
match num with
| 0 -> V1_0
| 1 -> V1_1
| 2 -> V1_2
| 3 -> V1_3
| 4 -> V1_4
| 5 -> V1_5
| 6 -> V1_6
| 7 -> V2_0
| _ -> failwithf "'%i' has no corresponding framework version" num
| FrameworkVersion.V1
| FrameworkVersion.V1_1
| FrameworkVersion.V2
| FrameworkVersion.V3
| FrameworkVersion.V3_5
| FrameworkVersion.V4_Client
| FrameworkVersion.V4 -> []
| FrameworkVersion.V4_5 -> [ DotNetStandardVersion.V1_1 ]
| FrameworkVersion.V4_5_1 -> DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V1_2
| FrameworkVersion.V4_5_2 -> DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V1_2
| FrameworkVersion.V4_5_3 -> DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V1_2
| FrameworkVersion.V4_6 -> DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V1_3
| FrameworkVersion.V4_6_1 -> (DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V1_4) @ [DotNetStandardVersion.V2_0]
| FrameworkVersion.V4_6_2 -> (DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V1_5) @ [DotNetStandardVersion.V2_0]
| FrameworkVersion.V4_6_3 -> DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V2_0
| FrameworkVersion.V4_7 -> DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V2_0
| FrameworkVersion.V5_0 -> DotNetStandardVersion.V1_1 <-> DotNetStandardVersion.V1_3


static member (<->) (lower:DotNetStandardVersion,upper:DotNetStandardVersion) =
if lower.NumKey < upper.NumKey then
[ lower.NumKey .. upper.NumKey ] |> List.map DotNetStandardVersion.FromNum
else
[ lower.NumKey .. -1 .. upper.NumKey ] |> List.map DotNetStandardVersion.FromNum

override this.ToString() =
match this with
| V1_0 -> "v1.0"
| V1_1 -> "v1.1"
| V1_2 -> "v1.2"
| V1_3 -> "v1.3"
| V1_4 -> "v1.4"
| V1_5 -> "v1.5"
| V1_6 -> "v1.6"
| V2_0 -> "v2.0"
member this.ShortString() =
match this with
| DotNetStandardVersion.V1_0 -> "10"
| DotNetStandardVersion.V1_1 -> "11"
| DotNetStandardVersion.V1_2 -> "12"
| DotNetStandardVersion.V1_3 -> "13"
| DotNetStandardVersion.V1_4 -> "14"
| DotNetStandardVersion.V1_5 -> "15"
| DotNetStandardVersion.V1_6 -> "16"
| DotNetStandardVersion.V2_0 -> "20"

[<RequireQualifiedAccess>]
/// The UAP version.
Expand Down Expand Up @@ -282,20 +306,6 @@ type FrameworkIdentifier =
| WindowsPhoneApp v -> "wpa" + v
| Silverlight v -> "sl" + v.Replace("v","").Replace(".","")

member private x.CompatibleUpto (?topFramework, ?topStandard, ?topCore) =
[ match topFramework with
| None -> () | Some framework -> yield! framework <-> FrameworkVersion.V1 |> List.map DotNetFramework
match topStandard with
| None -> () | Some standard -> yield! standard <-> DotNetStandardVersion.V1_0 |> List.map DotNetStandard
match topCore with
| None -> () | Some core -> yield! core <-> DotNetCoreVersion.V1_0 |> List.map DotNetCore
]

member private x.CompatibleUpto (topStandard) =
[ yield! topStandard <-> DotNetStandardVersion.V1_0 |> List.map DotNetStandard ]

member private x.CompatibleUpto (topCore) =
[ yield! topCore <-> DotNetCoreVersion.V1_0 |> List.map DotNetCore ]

// returns a list of compatible platforms that this platform also supports
member x.SupportedPlatforms =
Expand Down Expand Up @@ -378,6 +388,31 @@ type FrameworkIdentifier =

/// TODO: some notion of an increasing/decreasing sequence of FrameworkIdentitifers, so that Between(bottom, top) constraints can enumerate the list
member private x.CompatibleUpto (?topFramework, ?topStandard, ?topCore) =
[ match topFramework with
| None -> () | Some framework -> yield! framework <-> FrameworkVersion.V1 |> List.map DotNetFramework
match topStandard with
| None -> () | Some standard -> yield! standard <-> DotNetStandardVersion.V1_0 |> List.map DotNetStandard
match topCore with
| None -> () | Some core -> yield! core <-> DotNetCoreVersion.V1_0 |> List.map DotNetCore
]

member private x.CompatibleUpto (topStandard) =
[ yield! topStandard <-> DotNetStandardVersion.V1_0 |> List.map DotNetStandard ]

member private x.CompatibleUpto (topCore) =
[ yield! topCore <-> DotNetCoreVersion.V1_0 |> List.map DotNetCore ]


member private self.ExpandSupportedPlatforms (xs:FrameworkIdentifier list) =
let expand frameworkId =
match frameworkId with
| DotNetFramework x -> self.CompatibleUpto x
| DotNetStandard x -> self.CompatibleUpto x
| DotNetCore x -> self.CompatibleUpto x
| _ -> []
xs |> List.collect expand

member x.IsCompatible y =
x = y ||
(x.SupportedPlatforms |> Seq.exists (fun x' -> x' = y && not (x'.IsSameCategoryAs x))) ||
Expand Down Expand Up @@ -414,7 +449,7 @@ type FrameworkIdentifier =

module FrameworkDetection =
open Logging

/// parse a string to construct a Netframework, NetCore, NetStandard, or other dotnet identifier
let Extract =
memoize
(fun (path:string) ->
Expand Down
8 changes: 4 additions & 4 deletions src/Paket.Core/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,23 @@ module InstallModel =
match restrictions with
| [] -> installModel
| restrictions ->
let applRestriction folder =
let applyRestriction folder =
{ folder with Targets = applyRestrictionsToTargets restrictions folder.Targets}

{ installModel with
LegacyReferenceFileFolders =
installModel.LegacyReferenceFileFolders
|> List.map applRestriction
|> List.map applyRestriction
|> List.filter (fun folder -> folder.Targets <> [])

NewReferenceFileFolders =
installModel.NewReferenceFileFolders
|> List.map applRestriction
|> List.map applyRestriction
|> List.filter (fun folder -> folder.Targets <> [])

TargetsFileFolders =
installModel.TargetsFileFolders
|> List.map applRestriction
|> List.map applyRestriction
|> List.filter (fun folder -> folder.Targets <> []) }

let rec addTargetsFiles (targetsFiles:string list) (this:InstallModel) : InstallModel =
Expand Down
10 changes: 5 additions & 5 deletions src/Paket.Core/PlatformMatching.fs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ let getCondition (referenceCondition:string option) (allTargets: TargetProfile l
let grouped,targets =
([],targets)
|> CheckIfFullyInGroup "true" (fun _ -> true)
|> CheckIfFullyInGroup ".NETFramework" (fun x -> match x with | SinglePlatform(DotNetFramework(_)) -> true | _ -> false)
|> CheckIfFullyInGroup ".NETCore" (fun x -> match x with | SinglePlatform(Windows(_)) -> true | _ -> false)
|> CheckIfFullyInGroup "Silverlight" (fun x -> match x with |SinglePlatform(Silverlight(_)) -> true | _ -> false)
|> CheckIfFullyInGroup "WindowsPhoneApp" (fun x -> match x with | SinglePlatform(WindowsPhoneApp(_)) -> true | _ -> false)
|> CheckIfFullyInGroup "WindowsPhone" (fun x -> match x with | SinglePlatform(WindowsPhoneSilverlight(_)) -> true | _ -> false)
|> CheckIfFullyInGroup ".NETFramework" (function SinglePlatform (DotNetFramework _) -> true | _ -> false)
|> CheckIfFullyInGroup ".NETCore" (function SinglePlatform (Windows _) -> true | _ -> false)
|> CheckIfFullyInGroup "Silverlight" (function SinglePlatform (Silverlight _) -> true | _ -> false)
|> CheckIfFullyInGroup "WindowsPhoneApp" (function SinglePlatform (WindowsPhoneApp _) -> true | _ -> false)
|> CheckIfFullyInGroup "WindowsPhone" (function SinglePlatform (WindowsPhoneSilverlight _) -> true | _ -> false)

let targets =
targets
Expand Down
35 changes: 35 additions & 0 deletions tests/Paket.Tests/FrameworkCompatibilitySpecs.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Paket.FrameworkCompatibilitySpecs

open System.IO
open Paket
open Paket.Domain
open Chessie.ErrorHandling
open FsUnit
open NUnit.Framework
open TestHelpers
open Paket.Requirements


(*
Ensure that projects targeting NETFramework can properly add netstandard references in
accordance with this chart
---------------------------------------------------------------------------------
| Platform Name | Alias |
|-------------------------------------------------------------------------------|
| .NET Standard | netstandard | 1.0 | 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 2.0 |
|-------------------------------------------------------------------------------|
| .NET Core | netcoreapp | → | → | → | → | → | → | 1.0 | 2.0 |
|-------------------------------------------------------------------------------|
| .NET Framework | net | → | 4.5 |4.5.1| 4.6 |4.6.1|4.6.2|vNext|4.6.1|
---------------------------------------------------------------------------------
- https://docs.microsoft.com/en-us/dotnet/articles/standard/library
*)


[<Test>]
let ``net46 should be compatible with netstandard13``() =
(DotNetFramework FrameworkVersion.V4_6).IsCompatible (DotNetStandard DotNetStandardVersion.V1_3)
|> shouldEqual true

1 change: 1 addition & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="UtilsSpecs.fs" />
<Compile Include="TemplateFileParsing.fs" />
<Compile Include="NuspecWriterSpecs.fs" />
<Compile Include="FrameworkCompatibilitySpecs.fs" />
<Compile Include="RestrictionFilterSpecs.fs" />
<Compile Include="RestrictionApplicationSpecs.fs" />
<Compile Include="PackageProcessSpecs.fs" />
Expand Down

0 comments on commit c8f8e2b

Please sign in to comment.