Skip to content

Commit

Permalink
Allow to override copy_local in paket.dependencies with values from p…
Browse files Browse the repository at this point in the history
…aket.references - fixes #836
  • Loading branch information
forki committed May 23, 2015
1 parent 41e3f08 commit 3d73f90
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 32 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 1.5.1 - 23.05.2015
* Allow to override 'copy_local' in 'paket.dependencies' with values from 'paket.references' - https://github.com/fsprojects/Paket/issues/836

#### 1.5.0 - 21.05.2015
* Property tests for dependencies files parser - https://github.com/fsprojects/Paket/pull/807
* EXPERIMENTAL: Query NuGet feeds in parallel
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module DependenciesFileParser =
| Remote(newSource) -> lineNo, options, sources @ [newSource], packages, sourceFiles
| ParserOptions(ParserOption.ReferencesMode mode) -> lineNo, { options with Strict = mode }, sources, packages, sourceFiles
| ParserOptions(ParserOption.Redirects mode) -> lineNo, { options with Redirects = mode }, sources, packages, sourceFiles
| ParserOptions(ParserOption.CopyLocal mode) -> lineNo, { options with Settings = { options.Settings with CopyLocal = mode }}, sources, packages, sourceFiles
| ParserOptions(ParserOption.CopyLocal mode) -> lineNo, { options with Settings = { options.Settings with CopyLocal = Some mode }}, sources, packages, sourceFiles
| ParserOptions(ParserOption.ImportTargets mode) -> lineNo, { options with Settings = { options.Settings with ImportTargets = mode }}, sources, packages, sourceFiles
| ParserOptions(ParserOption.FrameworkRestrictions r) -> lineNo, { options with Settings = { options.Settings with FrameworkRestrictions = r }}, sources, packages, sourceFiles
| ParserOptions(ParserOption.OmitContent omit) -> lineNo, { options with Settings = { options.Settings with OmitContent = omit }}, sources, packages, sourceFiles
Expand Down
10 changes: 9 additions & 1 deletion src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ let InstallIntoProjects(sources,force, hard, withBindingRedirects, lockFile:Lock
{ u.Value.Settings with
FrameworkRestrictions = u.Value.Settings.FrameworkRestrictions @ lockFile.Options.Settings.FrameworkRestrictions @ package.Settings.FrameworkRestrictions // TODO: This should filter
ImportTargets = u.Value.Settings.ImportTargets && lockFile.Options.Settings.ImportTargets && package.Settings.ImportTargets
CopyLocal = u.Value.Settings.CopyLocal && lockFile.Options.Settings.CopyLocal && package.Settings.CopyLocal
CopyLocal =
match package.Settings.CopyLocal with
| Some x -> Some x
| _ -> match lockFile.Options.Settings.CopyLocal with
| Some x -> Some x
| None -> match u.Value.Settings.CopyLocal with
| Some x -> Some x
| _ -> None

OmitContent = u.Value.Settings.OmitContent || lockFile.Options.Settings.OmitContent || package.Settings.OmitContent }})
|> Map.ofSeq

Expand Down
6 changes: 4 additions & 2 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module LockFileSerializer =
let hasReported = ref false
[ if options.Strict then yield "REFERENCES: STRICT"
if options.Redirects then yield "REDIRECTS: ON"
if not options.Settings.CopyLocal then yield "COPY-LOCAL: FALSE"
match options.Settings.CopyLocal with
| Some x -> yield "COPY-LOCAL: " + x.ToString().ToUpper()
| None -> ()
if not options.Settings.ImportTargets then yield "IMPORT-TARGETS: FALSE"
if options.Settings.OmitContent then yield "CONTENT: NONE"
match options.Settings.FrameworkRestrictions with
Expand Down Expand Up @@ -170,7 +172,7 @@ module LockFileParser =
| InstallOption (ReferencesMode(mode)) -> { state with Options = {state.Options with Strict = mode} }
| InstallOption (Redirects(mode)) -> { state with Options = {state.Options with Redirects = mode} }
| InstallOption (ImportTargets(mode)) -> { state with Options = {state.Options with Settings = { state.Options.Settings with ImportTargets = mode} } }
| InstallOption (CopyLocal(mode)) -> { state with Options = {state.Options with Settings = { state.Options.Settings with CopyLocal = mode}} }
| InstallOption (CopyLocal(mode)) -> { state with Options = {state.Options with Settings = { state.Options.Settings with CopyLocal = Some mode}} }
| InstallOption (FrameworkRestrictions(r)) -> { state with Options = {state.Options with Settings = { state.Options.Settings with FrameworkRestrictions = r}} }
| InstallOption (OmitContent(omit)) -> { state with Options = {state.Options with Settings = { state.Options.Settings with OmitContent = omit} }}
| RepositoryType repoType -> { state with RepositoryType = Some repoType }
Expand Down
3 changes: 2 additions & 1 deletion src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ type ProjectFile =
.ApplyFrameworkRestrictions(installSettings.Settings.FrameworkRestrictions)
.RemoveIfCompletelyEmpty()

this.GenerateXml(projectModel,installSettings.Settings.CopyLocal,installSettings.Settings.ImportTargets))
let copyLocal = defaultArg installSettings.Settings.CopyLocal true
this.GenerateXml(projectModel,copyLocal,installSettings.Settings.ImportTargets))
|> Seq.iter (fun (propertyNameNodes,chooseNode,propertyChooseNode) ->
if chooseNode.ChildNodes.Count > 0 then
this.ProjectNode.AppendChild chooseNode |> ignore
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/ReferencesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type ReferencesFile =
this
else
tracefn "Adding %s to %s" referenceName (this.FileName)
{ this with NugetPackages = this.NugetPackages @ [{ Name = packageName; Settings = { CopyLocal = copyLocal; ImportTargets = importTargets; FrameworkRestrictions = frameworkRestrictions; OmitContent = omitContent }}] }
{ this with NugetPackages = this.NugetPackages @ [{ Name = packageName; Settings = { CopyLocal = Some copyLocal; ImportTargets = importTargets; FrameworkRestrictions = frameworkRestrictions; OmitContent = omitContent }}] }

member this.AddNuGetReference(packageName : PackageName) = this.AddNuGetReference(packageName, true, true, [], false)

Expand Down
14 changes: 9 additions & 5 deletions src/Paket.Core/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,20 @@ type InstallSettings =
{ ImportTargets : bool
FrameworkRestrictions: FrameworkRestrictions
OmitContent : bool
CopyLocal : bool }
CopyLocal : bool option }

static member Default =
{ CopyLocal = true
{ CopyLocal = None
ImportTargets = true
FrameworkRestrictions = []
OmitContent = false }

member this.ToString(asLines) =
let options =
[ if not this.CopyLocal then yield "copy_local: false"
[
match this.CopyLocal with
| Some x -> yield "copy_local: " + x.ToString().ToLower()
| None -> ()
if not this.ImportTargets then yield "import_targets: false"
if this.OmitContent then yield "content: none"
match this.FrameworkRestrictions with
Expand Down Expand Up @@ -165,8 +168,9 @@ type InstallSettings =
| _ -> false
CopyLocal =
match kvPairs.TryGetValue "copy_local" with
| true, "false" -> false
| _ -> true }
| true, "false" -> Some false
| true, "true" -> Some true
| _ -> None }

type PackageRequirementSource =
| DependenciesFile of string
Expand Down
12 changes: 6 additions & 6 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ nuget "Microsoft.SqlServer.Types"
let ``should read content none config``() =
let cfg = DependenciesFile.FromCode(noneContentConfig)
cfg.Options.Settings.OmitContent |> shouldEqual true
cfg.Options.Settings.CopyLocal |> shouldEqual true
cfg.Options.Settings.CopyLocal |> shouldEqual None
cfg.Options.Settings.ImportTargets |> shouldEqual true

(cfg.Packages |> List.find (fun p -> p.Name = PackageName "Microsoft.SqlServer.Types")).Sources |> shouldEqual [PackageSource.NugetSource "http://nuget.org/api/v2"]
Expand All @@ -188,7 +188,7 @@ nuget "Microsoft.SqlServer.Types"
let ``should read config with specific framework``() =
let cfg = DependenciesFile.FromCode(specificFrameworkConfig)
cfg.Options.Settings.OmitContent |> shouldEqual false
cfg.Options.Settings.CopyLocal |> shouldEqual true
cfg.Options.Settings.CopyLocal |> shouldEqual None
cfg.Options.Settings.ImportTargets |> shouldEqual true

(cfg.Packages |> List.find (fun p -> p.Name = PackageName "Microsoft.SqlServer.Types")).Sources |> shouldEqual [PackageSource.NugetSource "http://nuget.org/api/v2"]
Expand All @@ -205,7 +205,7 @@ nuget "Microsoft.SqlServer.Types"
let ``should read no targets import config``() =
let cfg = DependenciesFile.FromCode(noTargetsImportConfig)
cfg.Options.Settings.ImportTargets |> shouldEqual false
cfg.Options.Settings.CopyLocal |> shouldEqual false
cfg.Options.Settings.CopyLocal |> shouldEqual (Some false)
cfg.Options.Settings.OmitContent |> shouldEqual false

(cfg.Packages |> List.find (fun p -> p.Name = PackageName "Microsoft.SqlServer.Types")).Sources |> shouldEqual [PackageSource.NugetSource "http://nuget.org/api/v2"]
Expand Down Expand Up @@ -561,7 +561,7 @@ let ``should read config with framework restriction``() =
p.VersionRequirement.Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "1.2.3"))
p.Settings.FrameworkRestrictions |> shouldEqual [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V3_5)); FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_Client))]
p.Settings.ImportTargets |> shouldEqual true
p.Settings.CopyLocal |> shouldEqual true
p.Settings.CopyLocal |> shouldEqual None

[<Test>]
let ``should read config with no targets import``() =
Expand All @@ -574,7 +574,7 @@ let ``should read config with no targets import``() =
p.VersionRequirement.Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "1.2.3"))
p.Settings.FrameworkRestrictions |> shouldEqual []
p.Settings.ImportTargets |> shouldEqual false
p.Settings.CopyLocal |> shouldEqual false
p.Settings.CopyLocal |> shouldEqual (Some false)
p.Settings.OmitContent |> shouldEqual false

[<Test>]
Expand All @@ -588,7 +588,7 @@ let ``should read config with content none``() =
p.VersionRequirement.Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "1.2.3"))
p.Settings.FrameworkRestrictions |> shouldEqual []
p.Settings.ImportTargets |> shouldEqual true
p.Settings.CopyLocal |> shouldEqual false
p.Settings.CopyLocal |> shouldEqual (Some false)
p.Settings.OmitContent |> shouldEqual true


Expand Down
12 changes: 6 additions & 6 deletions tests/Paket.Tests/Lockfile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let ``should parse lock file``() =
let packages = List.rev lockFile.Packages
packages.Length |> shouldEqual 6
lockFile.Options.Strict |> shouldEqual false
lockFile.Options.Settings.CopyLocal |> shouldEqual false
lockFile.Options.Settings.CopyLocal |> shouldEqual (Some false)
lockFile.Options.Settings.ImportTargets |> shouldEqual true

packages.[0].Source |> shouldEqual PackageSources.DefaultNugetSource
Expand Down Expand Up @@ -98,7 +98,7 @@ let ``should parse strict lock file``() =
lockFile.Options.Strict |> shouldEqual true
lockFile.Options.Redirects |> shouldEqual false
lockFile.Options.Settings.ImportTargets |> shouldEqual false
lockFile.Options.Settings.CopyLocal |> shouldEqual true
lockFile.Options.Settings.CopyLocal |> shouldEqual None

packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "log4net")
Expand All @@ -123,7 +123,7 @@ let ``should parse redirects lock file``() =
lockFile.Options.Strict |> shouldEqual false
lockFile.Options.Redirects |> shouldEqual true
lockFile.Options.Settings.ImportTargets |> shouldEqual true
lockFile.Options.Settings.CopyLocal |> shouldEqual true
lockFile.Options.Settings.CopyLocal |> shouldEqual (Some true)

packages.Head.Source |> shouldEqual (PackageSource.LocalNuget("D:\code\\temp with space"))

Expand All @@ -143,7 +143,7 @@ let ``should parse lock file with framework restrictions``() =
lockFile.Options.Strict |> shouldEqual false
lockFile.Options.Redirects |> shouldEqual false
lockFile.Options.Settings.ImportTargets |> shouldEqual true
lockFile.Options.Settings.CopyLocal |> shouldEqual true
lockFile.Options.Settings.CopyLocal |> shouldEqual None

let dogfood = """NUGET
remote: https://nuget.org/api/v2
Expand Down Expand Up @@ -314,15 +314,15 @@ let ``should parse framework restricted lock file in new syntax``() =
packages.[3].Name |> shouldEqual (PackageName "LinqBridge")
packages.[3].Version |> shouldEqual (SemVer.Parse "1.3.0")
packages.[3].Settings.FrameworkRestrictions |> shouldEqual ([FrameworkRestriction.Between(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2),FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))])
packages.[3].Settings.CopyLocal |> shouldEqual true
packages.[3].Settings.CopyLocal |> shouldEqual None
packages.[3].Settings.ImportTargets |> shouldEqual false
packages.[3].Settings.OmitContent |> shouldEqual true

packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "ReadOnlyCollectionInterfaces")
packages.[5].Version |> shouldEqual (SemVer.Parse "1.0.0")
packages.[5].Settings.ImportTargets |> shouldEqual false
packages.[5].Settings.CopyLocal |> shouldEqual false
packages.[5].Settings.CopyLocal |> shouldEqual (Some false)
packages.[5].Settings.OmitContent |> shouldEqual false
packages.[5].Settings.FrameworkRestrictions
|> shouldEqual ([FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2))
Expand Down
18 changes: 9 additions & 9 deletions tests/Paket.Tests/ReferencesFile/ReferencesFileSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ let ``should parse lines with CopyLocal settings correctly``() =
let refFile = ReferencesFile.FromLines(toLines refFileContentWithCopyLocalFalse)
refFile.NugetPackages.Length |> shouldEqual 2
refFile.NugetPackages.Head.Name |> shouldEqual (PackageName "Castle.Windsor")
refFile.NugetPackages.Head.Settings.CopyLocal |> shouldEqual false
refFile.NugetPackages.Head.Settings.CopyLocal |> shouldEqual (Some false)
refFile.NugetPackages.Tail.Head.Name |> shouldEqual (PackageName "Newtonsoft.Json")
refFile.NugetPackages.Tail.Head.Settings.CopyLocal |> shouldEqual true
refFile.NugetPackages.Tail.Head.Settings.CopyLocal |> shouldEqual None

[<Test>]
let ``should serialize CopyLocal correctly``() =
Expand All @@ -119,10 +119,10 @@ let ``should parse lines with import_targets settings correctly``() =
let refFile = ReferencesFile.FromLines(toLines refFileContentWithNoTargetsImport)
refFile.NugetPackages.Length |> shouldEqual 2
refFile.NugetPackages.Head.Name |> shouldEqual (PackageName "Castle.Windsor")
refFile.NugetPackages.Head.Settings.CopyLocal |> shouldEqual true
refFile.NugetPackages.Head.Settings.CopyLocal |> shouldEqual None
refFile.NugetPackages.Head.Settings.ImportTargets |> shouldEqual false
refFile.NugetPackages.Tail.Head.Name |> shouldEqual (PackageName "Newtonsoft.Json")
refFile.NugetPackages.Tail.Head.Settings.CopyLocal |> shouldEqual true
refFile.NugetPackages.Tail.Head.Settings.CopyLocal |> shouldEqual None
refFile.NugetPackages.Tail.Head.Settings.ImportTargets |> shouldEqual true

let refFileContentWithCopyLocalFalseAndNoTargetsImport = """Castle.Windsor copy_local : false, import_targets: false
Expand All @@ -134,10 +134,10 @@ let ``should parse lines with CopyLocal and import_targets settings correctly``(
let refFile = ReferencesFile.FromLines(toLines refFileContentWithCopyLocalFalseAndNoTargetsImport)
refFile.NugetPackages.Length |> shouldEqual 3
refFile.NugetPackages.Head.Name |> shouldEqual (PackageName "Castle.Windsor")
refFile.NugetPackages.Head.Settings.CopyLocal |> shouldEqual false
refFile.NugetPackages.Head.Settings.CopyLocal |> shouldEqual (Some false)
refFile.NugetPackages.Head.Settings.ImportTargets |> shouldEqual false
refFile.NugetPackages.Tail.Head.Name |> shouldEqual (PackageName "Newtonsoft.Json")
refFile.NugetPackages.Tail.Head.Settings.CopyLocal |> shouldEqual true
refFile.NugetPackages.Tail.Head.Settings.CopyLocal |> shouldEqual None
refFile.NugetPackages.Tail.Head.Settings.ImportTargets |> shouldEqual true

[<Test>]
Expand All @@ -161,16 +161,16 @@ let ``should parse and serialize lines with multiple settings settings correctly
let refFile = ReferencesFile.FromLines(toLines refFileContentWithMultipleSettings)
refFile.NugetPackages.Length |> shouldEqual 3
refFile.NugetPackages.Head.Name |> shouldEqual (PackageName "Castle.Windsor")
refFile.NugetPackages.Head.Settings.CopyLocal |> shouldEqual false
refFile.NugetPackages.Head.Settings.CopyLocal |> shouldEqual (Some false)
refFile.NugetPackages.Head.Settings.ImportTargets |> shouldEqual false

refFile.NugetPackages.Tail.Head.Name |> shouldEqual (PackageName "Newtonsoft.Json")
refFile.NugetPackages.Tail.Head.Settings.CopyLocal |> shouldEqual true
refFile.NugetPackages.Tail.Head.Settings.CopyLocal |> shouldEqual None
refFile.NugetPackages.Tail.Head.Settings.ImportTargets |> shouldEqual true
refFile.NugetPackages.Tail.Head.Settings.OmitContent |> shouldEqual true

refFile.NugetPackages.Tail.Tail.Head.Name |> shouldEqual (PackageName "xUnit")
refFile.NugetPackages.Tail.Tail.Head.Settings.CopyLocal |> shouldEqual true
refFile.NugetPackages.Tail.Tail.Head.Settings.CopyLocal |> shouldEqual None
refFile.NugetPackages.Tail.Tail.Head.Settings.ImportTargets |> shouldEqual false
refFile.NugetPackages.Tail.Tail.Head.Settings.OmitContent |> shouldEqual false

Expand Down

0 comments on commit 3d73f90

Please sign in to comment.