Skip to content

Commit

Permalink
Simplify the case where only one targets condition is met
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Feb 7, 2015
1 parent 1ad73c9 commit c6c57e4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### 0.27.0-alpha016 - 07.02.2015
#### 0.27.0-alpha017 - 07.02.2015
* Allow to reference `.props` and `.targets` files - https://github.com/fsprojects/Paket/issues/516
* Create a install function in the api which takes a `paket.dependencies` file as text - https://github.com/fsprojects/Paket/issues/576
* Don't internalize in paket.exe during ILMerge
Expand Down
19 changes: 12 additions & 7 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ type ProjectFile =
node
|> propertyGroup.AppendChild
|> ignore
Some(propertyName,path.Substring(0,path.LastIndexOf("build\\") + 6)))
Some(propertyName,path,path.Substring(0,path.LastIndexOf("build\\") + 6)))
|> Set.ofSeq

propertyNames,propertyGroup
Expand Down Expand Up @@ -301,7 +301,7 @@ type ProjectFile =
let propertyNames,propertyChooseNode =
match targetsFileConditions with
| ["$(TargetFrameworkIdentifier) == 'true'",(propertyNames,propertyGroup)] ->
[propertyNames],propertyGroup
[propertyNames],this.CreateNode("Choose")
| _ ->
let propertyChooseNode = this.CreateNode("Choose")

Expand All @@ -323,13 +323,18 @@ type ProjectFile =

let propertyNameNodes =
propertyNames
|> Set.unionMany
|> Seq.map (fun (propertyName,buildPath) ->
|> Seq.concat
|> Seq.distinctBy (fun (x,_,_) -> x)
|> Seq.map (fun (propertyName,path,buildPath) ->
let fileName =
if propertyName.ToLower().EndsWith "props" then
match propertyName.ToLower() with
| _ when propertyChooseNode.ChildNodes.Count = 0 -> path
| name when name.EndsWith "props" ->
sprintf "%s$(%s).props" buildPath propertyName
else
sprintf "%s$(%s).targets" buildPath propertyName
| name when name.EndsWith "targets" ->
sprintf "%s$(%s).targets" buildPath propertyName
| _ -> failwithf "Unknown .targets filename %s" propertyName

this.CreateNode("Import")
|> addAttribute "Project" fileName
|> addAttribute "Condition" (sprintf "Exists('%s')" fileName))
Expand Down
10 changes: 4 additions & 6 deletions tests/Paket.Tests/InstallModel/Xml/GitInfoPlanter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ open Paket.Requirements
let emptyReferences = """<?xml version="1.0" encoding="utf-16"?>
<Choose xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />"""

let expectedPropertyDefinitionNodes = """<?xml version="1.0" encoding="utf-16"?>
<PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<__paket__GitInfoPlanter_targets>GitInfoPlanter</__paket__GitInfoPlanter_targets>
</PropertyGroup>"""
let emptyPropertyDefinitionNodes = """<?xml version="1.0" encoding="utf-16"?>
<Choose xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />"""

let expectedPropertyNodes = """<?xml version="1.0" encoding="utf-16"?>
<Import Project="..\..\..\GitInfoPlanter\build\$(__paket__GitInfoPlanter_targets).targets" Condition="Exists('..\..\..\GitInfoPlanter\build\$(__paket__GitInfoPlanter_targets).targets')" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />"""
<Import Project="..\..\..\GitInfoPlanter\build\GitInfoPlanter" Condition="Exists('..\..\..\GitInfoPlanter\build\GitInfoPlanter')" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />"""

[<Test>]
let ``should generate Xml for GitInfoPlanter2.0.0``() =
Expand All @@ -33,7 +31,7 @@ let ``should generate Xml for GitInfoPlanter2.0.0``() =

propertyChooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expectedPropertyDefinitionNodes)
|> shouldEqual (normalizeXml emptyPropertyDefinitionNodes)

propertyNodes |> Seq.length |> shouldEqual 1

Expand Down
10 changes: 4 additions & 6 deletions tests/Paket.Tests/InstallModel/Xml/StyleCop.MSBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ open Paket.TestHelpers
open Paket.Domain
open Paket.Requirements

let expected = """<?xml version="1.0" encoding="utf-16"?>
<PropertyGroup xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<__paket__StyleCop_MSBuild_Targets>StyleCop.MSBuild</__paket__StyleCop_MSBuild_Targets>
</PropertyGroup>"""
let emptyPropertyNameNodes = """<?xml version="1.0" encoding="utf-16"?>
<Choose xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />"""

let expectedPropertyNodes = """<?xml version="1.0" encoding="utf-16"?>
<Import Project="..\..\..\StyleCop.MSBuild\build\$(__paket__StyleCop_MSBuild_Targets).targets" Condition="Exists('..\..\..\StyleCop.MSBuild\build\$(__paket__StyleCop_MSBuild_Targets).targets')" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />"""
<Import Project="..\..\..\StyleCop.MSBuild\build\StyleCop.MSBuild" Condition="Exists('..\..\..\StyleCop.MSBuild\build\StyleCop.MSBuild')" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />"""

[<Test>]
let ``should generate Xml for StyleCop.MSBuild``() =
Expand All @@ -28,7 +26,7 @@ let ``should generate Xml for StyleCop.MSBuild``() =

propertyChooseNode.OuterXml
|> normalizeXml
|> shouldEqual (normalizeXml expected)
|> shouldEqual (normalizeXml emptyPropertyNameNodes)

propertyNodes |> Seq.length |> shouldEqual 1

Expand Down

0 comments on commit c6c57e4

Please sign in to comment.