Skip to content

Commit

Permalink
Handle silverlight framework identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 12, 2015
1 parent 5773046 commit 633251f
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 21 deletions.
22 changes: 2 additions & 20 deletions src/Paket.Core/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -317,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
Expand Down
38 changes: 38 additions & 0 deletions src/Paket.Core/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,44 @@ 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 ->
restrictions
|> List.exists (fun restriction ->
match restriction with
| FrameworkRestriction.Exactly fw -> pf = fw
| 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(_,_) ->
restrictions
|> List.exists (fun restriction ->
match restriction with
| FrameworkRestriction.Portable _ -> 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
Expand Down
3 changes: 2 additions & 1 deletion tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -308,6 +308,7 @@
<Compile Include="InstallModel\Penalty\FrameworkConditionsSpecs.fs" />
<Compile Include="InstallModel\AnalyzerSpecs.fs" />
<Compile Include="DependencyModel\ProjectDependencySpecs.fs" />
<Compile Include="Requirements\RestrictionApplicationSpecs.fs" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
Expand Down
83 changes: 83 additions & 0 deletions tests/Paket.Tests/Requirements/RestrictionApplicationSpecs.fs
Original file line number Diff line number Diff line change
@@ -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")
]

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

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

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

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

0 comments on commit 633251f

Please sign in to comment.