Skip to content

Commit

Permalink
Merge pull request #269 from theimowski/handle_net11_framework
Browse files Browse the repository at this point in the history
add net11 to framework handling - references #266
  • Loading branch information
forki committed Oct 21, 2014
2 parents 3c3e4d2 + 876b8f8 commit cd6eeb8
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 182 deletions.
83 changes: 37 additions & 46 deletions src/Paket.Core/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
open System.IO
open System

/// The Framework profile.
type FrameworkProfile =
| Client
| Full

[<RequireQualifiedAccess>]
type FrameworkVersionNo =
/// The Framework version.
type FrameworkVersion =
| V1
| V1_1
| V2
| V3_5
| V4_Client
| V4
| V4_5
| V4_5_1
Expand All @@ -25,36 +22,32 @@ type FrameworkVersionNo =
| V1_1 -> "v1.1"
| V2 -> "v2.0"
| V3_5 -> "v3.5"
| V4_Client -> "v4.0"
| V4 -> "v4.0"
| V4_5 -> "v4.5"
| V4_5_1 -> "v4.5.1"
| V4_5_2 -> "v4.5.2"
| V4_5_3 -> "v4.5.3"

/// The Framework version.
type FrameworkVersion =
| All
| Framework of FrameworkVersionNo

static member KnownDotNetFrameworks =
[ FrameworkVersionNo.V1, Full
FrameworkVersionNo.V1_1, Full
FrameworkVersionNo.V2, Full
FrameworkVersionNo.V3_5, Full
FrameworkVersionNo.V4, Client
FrameworkVersionNo.V4, Full
FrameworkVersionNo.V4_5, Full
FrameworkVersionNo.V4_5_1, Full
FrameworkVersionNo.V4_5_2, Full
FrameworkVersionNo.V4_5_3, Full ]
[ FrameworkVersion.V1
FrameworkVersion.V1_1
FrameworkVersion.V2
FrameworkVersion.V3_5
FrameworkVersion.V4_Client
FrameworkVersion.V4
FrameworkVersion.V4_5
FrameworkVersion.V4_5_1
FrameworkVersion.V4_5_2
FrameworkVersion.V4_5_3 ]

type PlatformVersion = string

type PortableFrameworkProfile = string

/// Framework Identifier type.
type FrameworkIdentifier =
| DotNetFramework of FrameworkVersion * FrameworkProfile
| DotNetFramework of FrameworkVersion
| PortableFramework of PlatformVersion * PortableFrameworkProfile
| MonoAndroid
| MonoTouch
Expand Down Expand Up @@ -90,24 +83,25 @@ type FrameworkIdentifier =
|> List.fold (fun (path:string) (pattern,replacement) -> path.Replace(pattern.ToLower(),replacement.ToLower())) (path.ToLower())

match path with
| "net" -> Some(DotNetFramework(All, Full))
| "1.0" -> Some(DotNetFramework(All, Full))
| "1.1" -> Some(DotNetFramework(All, Full))
| "2.0" -> Some(DotNetFramework(All, Full))
| "net20" -> Some(DotNetFramework(Framework FrameworkVersionNo.V2, Full))
| "net20-full" -> Some(DotNetFramework(Framework FrameworkVersionNo.V2, Full))
| "net35" -> Some(DotNetFramework(Framework FrameworkVersionNo.V3_5, Full))
| "net35-full" -> Some(DotNetFramework(Framework FrameworkVersionNo.V3_5, Full))
| "net4" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4, Full))
| "net40" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4, Full))
| "net40-full" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4, Full))
| "net40-client" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4, Client))
| "net45" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4_5, Full))
| "net45-full" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4_5, Full))
| "net451" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4_5_1, Full))
| "35" -> Some(DotNetFramework(Framework FrameworkVersionNo.V3_5, Full))
| "40" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4, Full))
| "45" -> Some(DotNetFramework(Framework FrameworkVersionNo.V4_5, Full))
| "net" -> Some(DotNetFramework(FrameworkVersion.V2)) // not sure here
| "1.0" -> Some(DotNetFramework(FrameworkVersion.V1))
| "1.1" -> Some(DotNetFramework(FrameworkVersion.V1_1))
| "2.0" -> Some(DotNetFramework(FrameworkVersion.V2))
| "net11" -> Some(DotNetFramework(FrameworkVersion.V1_1))
| "net20" -> Some(DotNetFramework(FrameworkVersion.V2))
| "net20-full" -> Some(DotNetFramework(FrameworkVersion.V2))
| "net35" -> Some(DotNetFramework(FrameworkVersion.V3_5))
| "net35-full" -> Some(DotNetFramework(FrameworkVersion.V3_5))
| "net4" -> Some(DotNetFramework(FrameworkVersion.V4))
| "net40" -> Some(DotNetFramework(FrameworkVersion.V4))
| "net40-full" -> Some(DotNetFramework(FrameworkVersion.V4))
| "net40-client" -> Some(DotNetFramework(FrameworkVersion.V4_Client))
| "net45" -> Some(DotNetFramework(FrameworkVersion.V4_5))
| "net45-full" -> Some(DotNetFramework(FrameworkVersion.V4_5))
| "net451" -> Some(DotNetFramework(FrameworkVersion.V4_5_1))
| "35" -> Some(DotNetFramework(FrameworkVersion.V3_5))
| "40" -> Some(DotNetFramework(FrameworkVersion.V4))
| "45" -> Some(DotNetFramework(FrameworkVersion.V4_5))
| "sl3" -> Some(Silverlight "v3.0")
| "sl4" -> Some(Silverlight "v4.0")
| "sl5" -> Some(Silverlight "v5.0")
Expand Down Expand Up @@ -201,7 +195,7 @@ type FrameworkIdentifier =

member x.GetFrameworkProfile() =
match x with
| DotNetFramework(_,Client) -> "$(TargetFrameworkProfile) == 'Client'"
| DotNetFramework(FrameworkVersion.V4_Client) -> "$(TargetFrameworkProfile) == 'Client'"
| PortableFramework(_,profile) ->
match x.GetPortableProfile() with
| None -> sprintf "$(TargetFrameworkProfile) == '%s'" profile
Expand All @@ -228,10 +222,7 @@ type FrameworkIdentifier =
y
else x + " And " + y
match x with
| DotNetFramework(v,_) ->
match v with
| Framework fw -> sprintf "$(TargetFrameworkVersion) == '%s'" (fw.ToString()) ++ x.GetFrameworkProfile()
| All -> "true"
| DotNetFramework(fw) -> sprintf "$(TargetFrameworkVersion) == '%s'" (fw.ToString()) ++ x.GetFrameworkProfile()
| PortableFramework _ -> x.GetFrameworkProfile() ++ x.GetPlatformIdentifier() ++ x.GetPlatformVersion()
| WindowsPhoneApp _ -> x.GetPlatformVersion()
| Windows _ -> x.GetPlatformVersion()
Expand All @@ -248,7 +239,7 @@ type FrameworkIdentifier =
let path = path.Replace("\\", "/").ToLower()
let fi = new FileInfo(path)

if path.Contains("lib/" + fi.Name.ToLower()) then Some(DotNetFramework(All, Full))
if path.Contains("lib/" + fi.Name.ToLower()) then Some(DotNetFramework(FrameworkVersion.V1))
else
let startPos = path.IndexOf("lib/")
let endPos = path.IndexOf(fi.Name.ToLower())
Expand Down
31 changes: 8 additions & 23 deletions src/Paket.Core/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type InstallModel =

static member EmptyModel(packageName, packageVersion) : InstallModel =
let frameworks =
[ for x, p in FrameworkVersion.KnownDotNetFrameworks -> DotNetFramework(Framework x, p) ]
[ for x in FrameworkVersion.KnownDotNetFrameworks -> DotNetFramework(x) ]
{ PackageName = packageName
PackageVersion = packageVersion
Fallbacks = Map.empty
Expand Down Expand Up @@ -97,31 +97,17 @@ type InstallModel =
(fun frameworks f -> Map.map (fun _ files -> {files with References = files.References |> Set.filter (f >> not)}) frameworks)
this.Frameworks }

member this.UseGenericFrameworkVersionIfEmpty() =
let genericFramework = DotNetFramework(All, Full)
let newFiles = this.GetReferences genericFramework

let model =
if Set.isEmpty newFiles then this else

let target = DotNetFramework(Framework FrameworkVersionNo.V1,Full)
match Map.tryFind target this.Frameworks with
| Some files when Set.isEmpty files.References |> not -> this
| _ -> { this with Frameworks = Map.add target { References = newFiles; ContentFiles = Set.empty } this.Frameworks }

{ model with Frameworks = model.Frameworks |> Map.remove genericFramework }

member this.UseLowerVersionLibIfEmpty() =
FrameworkVersion.KnownDotNetFrameworks
|> List.rev
|> List.fold (fun (model : InstallModel) (lowerVersion,lowerProfile) ->
let newFiles = model.GetReferences(DotNetFramework(Framework lowerVersion, lowerProfile))
|> List.fold (fun (model : InstallModel) (lowerVersion) ->
let newFiles = model.GetReferences(DotNetFramework(lowerVersion))
if Set.isEmpty newFiles then model
else
FrameworkVersion.KnownDotNetFrameworks
|> List.filter (fun (version,profile) -> (version,profile) > (lowerVersion,lowerProfile))
|> List.fold (fun (model : InstallModel) (upperVersion,upperProfile) ->
let framework = DotNetFramework(Framework upperVersion, upperProfile)
|> List.filter (fun (version) -> (version) > (lowerVersion))
|> List.fold (fun (model : InstallModel) (upperVersion) ->
let framework = DotNetFramework(upperVersion)
match Map.tryFind framework model.Frameworks with
| Some files when Set.isEmpty files.References ->
{ model with Frameworks = Map.add framework { References = newFiles; ContentFiles = Set.empty } model.Frameworks }
Expand Down Expand Up @@ -161,7 +147,6 @@ type InstallModel =

member this.Process() =
this
.UseGenericFrameworkVersionIfEmpty()
.UseLowerVersionLibIfEmpty()
.UsePortableVersionLibIfEmpty()
.UseLowerVersionLibIfEmpty() // because we now might need to use portable
Expand All @@ -178,8 +163,8 @@ type InstallModel =
| _ -> ()]
|> Set.ofList)

static member CreateFromLibs(packageName,packageVersions,libs,nuspec:Nuspec) =
InstallModel.EmptyModel(packageName,packageVersions)
static member CreateFromLibs(packageName,packageVersion,libs,nuspec:Nuspec) =
InstallModel.EmptyModel(packageName,packageVersion)
.AddReferences(libs,nuspec.References)
.AddFrameworkAssemblyReferences(nuspec.FrameworkAssemblyReferences)
.Process()
6 changes: 3 additions & 3 deletions tests/Paket.Tests/InstallModel/NuspecSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ let ``if nuspec is not found we assume no framework references``() =
let ``can detect framework assemblies for Microsoft.Net.Http``() =
Nuspec.Load("TestFiles/Microsoft.Net.Http.nuspec").FrameworkAssemblyReferences
|> shouldEqual
[{ AssemblyName = "System.Net.Http"; TargetFramework = DotNetFramework(FrameworkVersion.Framework(FrameworkVersionNo.V4_5),Full) }
{ AssemblyName = "System.Net.Http.WebRequest"; TargetFramework = DotNetFramework(FrameworkVersion.Framework(FrameworkVersionNo.V4_5),Full) }
[{ AssemblyName = "System.Net.Http"; TargetFramework = DotNetFramework(FrameworkVersion.V4_5) }
{ AssemblyName = "System.Net.Http.WebRequest"; TargetFramework = DotNetFramework(FrameworkVersion.V4_5) }
{ AssemblyName = "System.Net.Http"; TargetFramework = MonoTouch }
{ AssemblyName = "System.Net.Http"; TargetFramework = MonoAndroid } ]

[<Test>]
let ``can detect framework assemblies for Octokit``() =
Nuspec.Load("TestFiles/Octokit.nuspec").FrameworkAssemblyReferences
|> shouldEqual
[{ AssemblyName = "System.Net.Http"; TargetFramework = DotNetFramework(FrameworkVersion.Framework(FrameworkVersionNo.V4_5),Full) }]
[{ AssemblyName = "System.Net.Http"; TargetFramework = DotNetFramework(FrameworkVersion.V4_5) }]
Loading

0 comments on commit cd6eeb8

Please sign in to comment.