Skip to content

Commit

Permalink
Allow to use basic framework restrictions in NuGet packages -fixes #307
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Nov 19, 2014
1 parent 0f16c4b commit 82865ab
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 10 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.15.0 - 19.11.2014
* Allow to use basic framework restrictions in NuGet packages - https://github.com/fsprojects/Paket/issues/307

#### 0.14.6 - 18.11.2014
* BUGFIX: Use Nuget v2 as fallback

Expand Down
15 changes: 14 additions & 1 deletion src/Paket.Core/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System.IO
open System.Collections.Generic

open Paket.Domain
open Paket.Requirements

[<RequireQualifiedAccess>]
type Reference =
Expand Down Expand Up @@ -254,6 +255,17 @@ type InstallModel =
|> Seq.fold (fun (group : FrameworkGroup) framework ->
if framework.Value.References <> fallbacks.References then group
else { group with Frameworks = Map.remove framework.Key group.Frameworks }) group)

member this.ApplyFrameworkRestriction(restriction:FrameworkRestriction) =
match restriction with
| None -> this
| Some fw ->
{this with DefaultFallback = InstallFiles.empty }
.MapGroups(fun _ group ->
group.Frameworks
|> Seq.fold (fun (group : FrameworkGroup) framework ->
if framework.Key = fw then group
else { group with Frameworks = Map.remove framework.Key group.Frameworks }) { group with Fallbacks = InstallFiles.empty })

member this.UsePortableVersionLibIfEmpty() =
this.GetFrameworks()
Expand Down Expand Up @@ -301,9 +313,10 @@ type InstallModel =
|> List.map (fun lib -> lib.ReferenceName)
|> Set.ofList)

static member CreateFromLibs(packageName, packageVersion, libs, nuspec : Nuspec) =
static member CreateFromLibs(packageName, packageVersion, frameworkRestriction:FrameworkRestriction, libs, nuspec : Nuspec) =
InstallModel
.EmptyModel(packageName, packageVersion)
.AddReferences(libs, nuspec.References)
.AddFrameworkAssemblyReferences(nuspec.FrameworkAssemblyReferences)
.BuildUnfilteredModel()
.ApplyFrameworkRestriction(frameworkRestriction)
2 changes: 1 addition & 1 deletion src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let CreateInstallModel(root, sources, force, package) =
let nuspec = FileInfo(sprintf "%s/packages/%s/%s.nuspec" root name name)
let nuspec = Nuspec.Load nuspec.FullName
let files = files |> Seq.map (fun fi -> fi.FullName)
return package, InstallModel.CreateFromLibs(package.Name, package.Version, files, nuspec)
return package, InstallModel.CreateFromLibs(package.Name, package.Version, package.FrameworkRestriction, files, nuspec)
}

/// Restores the given packages from the lock file.
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/Fantomas.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let expected = """
[<Test>]
let ``should generate Xml for Fantomas 1.5``() =
let model =
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0",
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0", None,
[ @"..\Fantomas\lib\FantomasLib.dll"
@"..\Fantomas\lib\FSharp.Core.dll"
@"..\Fantomas\lib\Fantomas.exe" ],
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/FantomasLib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let expected = """
[<Test>]
let ``should generate Xml for Fantomas 1.5``() =
let model =
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0",
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0", None,
[ @"..\Fantomas\Lib\FantomasLib.dll"
@"..\Fantomas\Lib\FSharp.Core.dll"
@"..\Fantomas\Lib\Fantomas.exe" ],
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/Fuchu.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let expected = """
[<Test>]
let ``should generate Xml for Fuchu 0.4``() =
let model =
InstallModel.CreateFromLibs(PackageName "Fuchu", SemVer.Parse "0.4.0",
InstallModel.CreateFromLibs(PackageName "Fuchu", SemVer.Parse "0.4.0", None,
[ @"..\Fuchu\lib\Fuchu.dll"
@"..\Fuchu\lib\Fuchu.XML"
@"..\Fuchu\lib\Fuchu.pdb" ],
Expand Down
6 changes: 3 additions & 3 deletions tests/Paket.Tests/InstallModel/Xml/ManualNodes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open Paket.Domain
[<Test>]
let ``should find custom nodes in doc``() =
let model =
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0",
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0", None,
[ @"..\Fantomas\lib\FantomasLib.dll"
@"..\Fantomas\lib\FSharp.Core.dll"
@"..\Fantomas\lib\Fantomas.exe" ],
Expand All @@ -21,7 +21,7 @@ let ``should find custom nodes in doc``() =
[<Test>]
let ``should not find custom nodes if there are none``() =
let model =
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0",
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0", None,
[ @"..\Fantomas\lib\FantomasLib.dll"
@"..\Fantomas\lib\FSharp.Core.dll"
@"..\Fantomas\lib\Fantomas.exe" ],
Expand All @@ -34,7 +34,7 @@ let ``should not find custom nodes if there are none``() =
[<Test>]
let ``should delete custom nodes if there are some``() =
let model =
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0",
InstallModel.CreateFromLibs(PackageName "Fantomas", SemVer.Parse "1.5.0", None,
[ @"..\Fantomas\lib\FantomasLib.dll"
@"..\Fantomas\lib\FSharp.Core.dll"
@"..\Fantomas\lib\Fantomas.exe" ],
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/InstallModel/Xml/SystemNetHttp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ let expected = """
[<Test>]
let ``should generate Xml for System.Net.Http 2.2.8``() =
let model =
InstallModel.CreateFromLibs(PackageName "System.Net.Http", SemVer.Parse "2.2.8",
InstallModel.CreateFromLibs(PackageName "System.Net.Http", SemVer.Parse "2.2.8", None,
[ @"..\Microsoft.Net.Http\lib\monoandroid\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\monoandroid\System.Net.Http.Primitives.dll"

Expand Down
100 changes: 100 additions & 0 deletions tests/Paket.Tests/InstallModel/Xml/SystemNetHttpForNet4.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module Paket.InstallModel.Xml.SystemNetHttpForNet2Specs

open Paket
open NUnit.Framework
open FsUnit
open Paket.TestHelpers
open Paket.Domain

let expected = """
<Choose xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
<Choose>
<When Condition="$(TargetFrameworkVersion) == 'v4.0'">
<ItemGroup>
<Reference Include="System.Net.Http.Extensions">
<HintPath>..\..\..\Microsoft.Net.Http\lib\net40\System.Net.Http.Extensions.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Net.Http.Primitives">
<HintPath>..\..\..\Microsoft.Net.Http\lib\net40\System.Net.Http.Primitives.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Net.Http.WebRequest">
<HintPath>..\..\..\Microsoft.Net.Http\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
<Reference Include="System.Net.Http">
<HintPath>..\..\..\Microsoft.Net.Http\lib\net40\System.Net.Http.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup />
</Otherwise>
</Choose>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETPortable'">
<ItemGroup />
</When>
<When Condition="$(TargetFrameworkIdentifier) == 'MonoAndroid'">
<ItemGroup />
</When>
<When Condition="$(TargetFrameworkIdentifier) == 'MonoTouch'">
<ItemGroup />
</When>
<When Condition="$(TargetFrameworkIdentifier) == 'Silverlight'">
<ItemGroup />
</When>
<When Condition="$(TargetFrameworkIdentifier) == 'Windows'">
<ItemGroup />
</When>
<When Condition="$(TargetFrameworkIdentifier) == 'WindowsPhoneApp'">
<ItemGroup />
</When>
<Otherwise>
<ItemGroup />
</Otherwise>
</Choose>"""

[<Test>]
let ``should generate Xml for System.Net.Http 2.2.8``() =
let model =
InstallModel.CreateFromLibs(PackageName "System.Net.Http", SemVer.Parse "2.2.8", Some(DotNetFramework(FrameworkVersion.V4)),
[ @"..\Microsoft.Net.Http\lib\monoandroid\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\monoandroid\System.Net.Http.Primitives.dll"

@"..\Microsoft.Net.Http\lib\monotouch\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\monotouch\System.Net.Http.Primitives.dll"

@"..\Microsoft.Net.Http\lib\net40\System.Net.Http.dll"
@"..\Microsoft.Net.Http\lib\net40\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\net40\System.Net.Http.Primitives.dll"
@"..\Microsoft.Net.Http\lib\net40\System.Net.Http.WebRequest.dll"

@"..\Microsoft.Net.Http\lib\net45\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\net45\System.Net.Http.Primitives.dll"

@"..\Microsoft.Net.Http\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll"
@"..\Microsoft.Net.Http\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll"

@"..\Microsoft.Net.Http\lib\portable-net45+win8\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\portable-net45+win8\System.Net.Http.Primitives.dll"

@"..\Microsoft.Net.Http\lib\win8\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\win8\System.Net.Http.Primitives.dll"

@"..\Microsoft.Net.Http\lib\wpa81\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\wpa81\System.Net.Http.Primitives.dll" ],
Nuspec.All).FilterFallbacks()

let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model)
chooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ let expected = """
[<Test>]
let ``should generate Xml for System.Net.Http 2.2.8``() =
let model =
InstallModel.CreateFromLibs(PackageName "System.Net.Http", SemVer.Parse "2.2.8",
InstallModel.CreateFromLibs(PackageName "System.Net.Http", SemVer.Parse "2.2.8", None,
[ @"..\Microsoft.Net.Http\lib\net40\System.Net.Http.dll"
@"..\Microsoft.Net.Http\lib\net40\System.Net.Http.Extensions.dll"
@"..\Microsoft.Net.Http\lib\net40\System.Net.Http.Primitives.dll"
Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@
<Compile Include="InstallModel\Xml\FantomasLib.fs" />
<Compile Include="InstallModel\Xml\Fuchu.fs" />
<Compile Include="InstallModel\Xml\SystemNetHttp.fs" />
<Compile Include="InstallModel\Xml\SystemNetHttpForNet4.fs" />
<Compile Include="InstallModel\Xml\SystemNetHttpWithFrameworkReferences.fs" />
<Compile Include="InstallModel\Xml\ManualNodes.fs" />
<Compile Include="DependencyModel\ProjectDependencySpecs.fs" />
Expand Down

0 comments on commit 82865ab

Please sign in to comment.