Skip to content

Commit

Permalink
Can understand Fantomas
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 8, 2014
1 parent fe0a212 commit 3dc8bc0
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Paket.ProjectFile.InstallationModelpecs
module Paket.InstallModelSpecs

open Paket
open NUnit.Framework
Expand All @@ -24,20 +24,30 @@ type InstallModell =
Frameworks = List.fold (fun map f -> Map.add f Set.empty map) Map.empty frameworks }

member this.GetFrameworks() = this.Frameworks |> Seq.map (fun kv -> kv.Key)
member this.GetFiles(framework) = this.Frameworks.[framework]

member this.Add(framework,lib) : InstallModell =
member this.GetFiles(framework) =
match this.Frameworks.TryFind framework with
| Some libs -> libs
| None -> Set.empty

member this.Add(framework,lib:string,references) : InstallModell =
let install =
match references with
| Nuspec.References.All -> true
| Nuspec.References.Explicit list -> list |> List.exists lib.EndsWith

if not install then this else
{ this with Frameworks =
match Map.tryFind framework this.Frameworks with
| Some files -> Map.add framework (Set.add lib files) this.Frameworks
| None -> Map.add framework (Set.singleton lib) this.Frameworks }

member this.Add (libs) : InstallModell =
member this.Add (libs,references) : InstallModell =
libs |> List.fold (fun model lib ->
match FrameworkIdentifier.DetectFromPathNew lib with
| Some framework -> model.Add(framework,lib)
| Some framework -> model.Add(framework,lib,references)
| _ -> model) this

member this.Add libs = this.Add(libs, Nuspec.References.All)

member this.FilterBlackList() =
{ this with Frameworks =
Expand All @@ -46,6 +56,20 @@ type InstallModell =
(fun frameworks f -> Map.map (fun _ files -> files |> Set.filter (f >> not)) frameworks)
this.Frameworks }

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

let model =
if Set.isEmpty newFiles then this else

let target = DotNetFramework(Framework "v1.0",Full)
match Map.tryFind target this.Frameworks with
| Some files when Set.isEmpty files |> not -> this
| _ -> { this with Frameworks = Map.add target newFiles this.Frameworks }

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

member this.UseLowerVersionLibIfEmpty() =
KnownDotNetFrameworks
|> List.rev
Expand All @@ -68,23 +92,26 @@ type InstallModell =
(fun (model : InstallModell) kv ->
let newFiles = kv.Value

if Set.isEmpty newFiles then model else

let otherProfiles =
match kv.Key with
| PortableFramework(_, f) ->
f.Split([| '+' |], System.StringSplitOptions.RemoveEmptyEntries)
|> Array.map (FrameworkIdentifier.Extract false)
|> Array.choose id
| _ -> [||]
if Set.isEmpty newFiles || Array.isEmpty otherProfiles then model
else
otherProfiles
|> Array.fold (fun (model : InstallModell) framework ->
match Map.tryFind framework model.Frameworks with
| Some files when Set.isEmpty files |> not -> model
| _ -> { model with Frameworks = Map.add framework newFiles model.Frameworks }) model) this

if Array.isEmpty otherProfiles then model else
otherProfiles
|> Array.fold (fun (model : InstallModell) framework ->
match Map.tryFind framework model.Frameworks with
| Some files when Set.isEmpty files |> not -> model
| _ -> { model with Frameworks = Map.add framework newFiles model.Frameworks }) model) this

member this.Process() =
this
.UseGenericFrameworkVersionIfEmpty()
.UsePortableVersionLibIfEmpty()
.UseLowerVersionLibIfEmpty()
.FilterBlackList()
Expand Down Expand Up @@ -411,13 +438,58 @@ let ``should handle lib install of Microsoft.Bcl 1.1.9``() =
model.GetFiles(Silverlight("v5.0")) |> shouldContain @"..\Microsoft.Bcl\lib\sl5\System.Threading.Tasks.dll"


[<Test>]
let ``should handle lib install of Fantomas 1.5``() =
let model =
emptymodel.Add(
[ @"..\Fantomas\lib\FantomasLib.dll"
@"..\Fantomas\lib\FSharp.Core.dll"
@"..\Fantomas\lib\Fantomas.exe" ])
.UseGenericFrameworkVersionIfEmpty()
.UseLowerVersionLibIfEmpty()

model.GetFiles(DotNetFramework(All, Full)) |> shouldBeEmpty
model.GetFiles(DotNetFramework(Framework "v2.0", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll"
model.GetFiles(DotNetFramework(Framework "v2.0", Full)) |> shouldContain @"..\Fantomas\lib\FSharp.Core.dll"

model.GetFiles(DotNetFramework(Framework "v3.5", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll"
model.GetFiles(DotNetFramework(Framework "v3.5", Full)) |> shouldContain @"..\Fantomas\lib\FSharp.Core.dll"

model.GetFiles(DotNetFramework(Framework "v4.0", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll"
model.GetFiles(DotNetFramework(Framework "v4.0", Full)) |> shouldContain @"..\Fantomas\lib\FSharp.Core.dll"

model.GetFiles(DotNetFramework(Framework "v4.5", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll"
model.GetFiles(DotNetFramework(Framework "v4.5", Full)) |> shouldContain @"..\Fantomas\lib\FSharp.Core.dll"

[<Test>]
let ``should handle lib install of Fantomas 1.5.0 with explicit references``() =
let model =
emptymodel.Add(
[ @"..\Fantomas\lib\FantomasLib.dll"
@"..\Fantomas\lib\FSharp.Core.dll"
@"..\Fantomas\lib\Fantomas.exe" ], Nuspec.Explicit ["FantomasLib.dll"])
.Process()

model.GetFiles(DotNetFramework(All, Full)) |> shouldBeEmpty
model.GetFiles(DotNetFramework(Framework "v2.0", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll"
model.GetFiles(DotNetFramework(Framework "v2.0", Full)) |> shouldNotContain @"..\Fantomas\lib\FSharp.Core.dll"

model.GetFiles(DotNetFramework(Framework "v3.5", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll"
model.GetFiles(DotNetFramework(Framework "v3.5", Full)) |> shouldNotContain @"..\Fantomas\lib\FSharp.Core.dll"

model.GetFiles(DotNetFramework(Framework "v4.0", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll"
model.GetFiles(DotNetFramework(Framework "v4.0", Full)) |> shouldNotContain @"..\Fantomas\lib\FSharp.Core.dll"

model.GetFiles(DotNetFramework(Framework "v4.5", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll"
model.GetFiles(DotNetFramework(Framework "v4.5", Full)) |> shouldNotContain @"..\Fantomas\lib\FSharp.Core.dll"

[<Test>]
let ``should not install tools``() =
let model =
emptymodel.Add(
[ @"..\FAKE\tools\FAKE.exe"
@"..\FAKE\tools\FakeLib.exe"
@"..\FAKE\tools\Fake.SQL.exe" ])
@"..\FAKE\tools\FakeLib.dll"
@"..\FAKE\tools\Fake.SQL.dll" ])
.Process()

model.Frameworks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open Paket
open NUnit.Framework
open FsUnit
open Nuspec
open Paket.InstallModelSpecs

[<Test>]
let ``can detect explicit references``() =
Expand Down
22 changes: 10 additions & 12 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Import Project="$(SolutionDir)\.paket\paket.targets" />
<ItemGroup>
<Compile Include="..\..\paket-files\forki\FsUnit\FsUnit.fs">
<Paket>True</Paket>
Expand All @@ -75,7 +83,6 @@
<Content Include="TestFiles\Fantomas.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Compile Include="NuspecSpecs.fs" />
<Compile Include="FilterVersionSpecs.fs" />
<Compile Include="DependenciesFile\VersionRangeSpecs.fs" />
<Compile Include="DependenciesFile\ParserSpecs.fs" />
Expand Down Expand Up @@ -103,8 +110,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Compile Include="ProjectFile\ConditionSpecs.fs" />
<Compile Include="ProjectFile\InstallModelSpecs.fs" />
<Compile Include="ProjectFile\FileBuildActionSpecs.fs" />
<Compile Include="InstallModel\InstallModelSpecs.fs" />
<Compile Include="InstallModel\NuspecSpecs.fs" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
Expand All @@ -115,22 +123,12 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Paket\Paket.fsproj">
<Name>Paket</Name>
<Project>{09b32f18-0c20-4489-8c83-5106d5c04c93}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Import Project="$(SolutionDir)\.paket\paket.targets" />
<Choose>
<When Condition="true">
<ItemGroup>
Expand Down

3 comments on commit 3dc8bc0

@theimowski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks cool, some comments:

  • how about restricting FrameworkVersions etc. strings to DU cases? It could save us one day from a typo or something - for example here
  • how are we gonna go about the content files? put them in the same set of paths as libs? or maybe emphasize in model that its a separate concern (need to remember we support features like content none)

@forki
Copy link
Member Author

@forki forki commented on 3dc8bc0 Oct 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created that DU:
bf8d5ab

Yes we need the ContentFiles in the InstallModel see:
f024696

@theimowski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, keep in mind that in order for the support of Framework-Conditioned Content files from NuGet pkg, we still need to figure out how to deal with referencing files in a project (see #157 and my comment on Include attr on Content node)

Please sign in to comment.