Skip to content

Commit

Permalink
Allow to override install settings in paket.dependencies with values …
Browse files Browse the repository at this point in the history
…from paket.references - fixes #836
  • Loading branch information
forki committed May 23, 2015
1 parent e476edd commit 2387796
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 55 deletions.
4 changes: 2 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#### 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.2 - 23.05.2015
* Allow to override install settings 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
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ module DependenciesFileParser =
| 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 = Some mode }}, sources, packages, sourceFiles
| ParserOptions(ParserOption.ImportTargets mode) -> lineNo, { options with Settings = { options.Settings with ImportTargets = mode }}, sources, packages, sourceFiles
| ParserOptions(ParserOption.ImportTargets mode) -> lineNo, { options with Settings = { options.Settings with ImportTargets = Some 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
| ParserOptions(ParserOption.OmitContent omit) -> lineNo, { options with Settings = { options.Settings with OmitContent = Some omit }}, sources, packages, sourceFiles
| Package(name,version,rest) ->
let package = parsePackage(sources,DependenciesFile fileName,name,version,rest)

Expand Down
22 changes: 18 additions & 4 deletions src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open System.Diagnostics

let private findPackagesWithContent (root,usedPackages:Map<PackageName,PackageInstallSettings>) =
usedPackages
|> Seq.filter (fun kv -> not kv.Value.Settings.OmitContent)
|> Seq.filter (fun kv -> defaultArg kv.Value.Settings.OmitContent false |> not)
|> Seq.map (fun kv ->
let (PackageName name) = kv.Key
DirectoryInfo(Path.Combine(root, Constants.PackagesFolderName, name)))
Expand Down Expand Up @@ -166,8 +166,15 @@ let InstallIntoProjects(sources,force, hard, withBindingRedirects, lockFile:Lock
Settings =
{ 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 =
ImportTargets =
match package.Settings.ImportTargets with
| Some x -> Some x
| _ -> match lockFile.Options.Settings.ImportTargets with
| Some x -> Some x
| None -> match u.Value.Settings.ImportTargets with
| Some x -> Some x
| _ -> None
CopyLocal =
match package.Settings.CopyLocal with
| Some x -> Some x
| _ -> match lockFile.Options.Settings.CopyLocal with
Expand All @@ -176,7 +183,14 @@ let InstallIntoProjects(sources,force, hard, withBindingRedirects, lockFile:Lock
| Some x -> Some x
| _ -> None

OmitContent = u.Value.Settings.OmitContent || lockFile.Options.Settings.OmitContent || package.Settings.OmitContent }})
OmitContent =
match package.Settings.OmitContent with
| Some x -> Some x
| _ -> match lockFile.Options.Settings.OmitContent with
| Some x -> Some x
| None -> match u.Value.Settings.OmitContent with
| Some x -> Some x
| _ -> None }})
|> Map.ofSeq

let usedPackageSettings =
Expand Down
16 changes: 12 additions & 4 deletions src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ module LockFileSerializer =
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.ImportTargets with
| Some x -> yield "IMPORT-TARGETS: " + x.ToString().ToUpper()
| None -> ()

match options.Settings.OmitContent with
| Some true -> yield "CONTENT: NONE"
| Some false -> yield "CONTENT: TRUE"
| None -> ()

match options.Settings.FrameworkRestrictions with
| [] -> ()
| _ -> yield "FRAMEWORK: " + (String.Join(", ",options.Settings.FrameworkRestrictions)).ToUpper()
Expand Down Expand Up @@ -171,10 +179,10 @@ module LockFileParser =
| Blank -> state
| 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 (ImportTargets(mode)) -> { state with Options = {state.Options with Settings = { state.Options.Settings with ImportTargets = Some 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} }}
| InstallOption (OmitContent(omit)) -> { state with Options = {state.Options with Settings = { state.Options.Settings with OmitContent = Some omit} }}
| RepositoryType repoType -> { state with RepositoryType = Some repoType }
| NugetPackage details ->
match state.RemoteUrl with
Expand Down
4 changes: 3 additions & 1 deletion src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ type ProjectFile =
.RemoveIfCompletelyEmpty()

let copyLocal = defaultArg installSettings.Settings.CopyLocal true
this.GenerateXml(projectModel,copyLocal,installSettings.Settings.ImportTargets))
let importTargets = defaultArg installSettings.Settings.ImportTargets true

this.GenerateXml(projectModel,copyLocal,importTargets))
|> Seq.iter (fun (propertyNameNodes,chooseNode,propertyChooseNode) ->
if chooseNode.ChildNodes.Count > 0 then
this.ProjectNode.AppendChild chooseNode |> ignore
Expand Down
7 changes: 5 additions & 2 deletions src/Paket.Core/ReferencesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ type ReferencesFile =
let lines = File.ReadAllLines(fileName)
{ ReferencesFile.FromLines lines with FileName = fileName }

member this.AddNuGetReference(packageName : PackageName, copyLocal: bool, importTargets: bool, frameworkRestrictions, omitContent) =
member this.AddNuGetReference(packageName : PackageName, copyLocal: bool, importTargets: bool, frameworkRestrictions, omitContent : bool) =
let (PackageName referenceName) = packageName
let normalized = NormalizedPackageName packageName
if this.NugetPackages |> Seq.exists (fun p -> NormalizedPackageName p.Name = normalized) then
this
else
tracefn "Adding %s to %s" referenceName (this.FileName)
{ this with NugetPackages = this.NugetPackages @ [{ Name = packageName; Settings = { CopyLocal = Some copyLocal; ImportTargets = importTargets; FrameworkRestrictions = frameworkRestrictions; OmitContent = omitContent }}] }
let copyLocal = if not copyLocal then Some copyLocal else None
let importTargets = if not importTargets then Some importTargets else None
let omitContent = if omitContent then Some omitContent else None
{ this with NugetPackages = this.NugetPackages @ [{ Name = packageName; Settings = { CopyLocal = copyLocal; ImportTargets = importTargets; FrameworkRestrictions = frameworkRestrictions; OmitContent = omitContent }}] }

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

Expand Down
27 changes: 17 additions & 10 deletions src/Paket.Core/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,30 @@ let optimizeRestrictions packages =
yield name,versionRequirement,restrictions]

type InstallSettings =
{ ImportTargets : bool
{ ImportTargets : bool option
FrameworkRestrictions: FrameworkRestrictions
OmitContent : bool
OmitContent : bool option
CopyLocal : bool option }

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

member this.ToString(asLines) =
let options =
[
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.ImportTargets with
| Some x -> yield "import_targets: " + x.ToString().ToLower()
| None -> ()
match this.OmitContent with
| Some true -> yield "content: none"
| Some false -> yield "content: true"
| None -> ()
match this.FrameworkRestrictions with
| [] -> ()
| _ -> yield "framework: " + (String.Join(", ",this.FrameworkRestrictions))]
Expand All @@ -156,16 +161,18 @@ type InstallSettings =

{ ImportTargets =
match kvPairs.TryGetValue "import_targets" with
| true, "false" -> false
| _ -> true
| true, "false" -> Some false
| true, "true" -> Some true
| _ -> None
FrameworkRestrictions =
match kvPairs.TryGetValue "framework" with
| true, s -> parseRestrictions s
| _ -> []
OmitContent =
match kvPairs.TryGetValue "content" with
| true, "none" -> true
| _ -> false
| true, "none" -> Some true
| true, "true" -> Some false
| _ -> None
CopyLocal =
match kvPairs.TryGetValue "copy_local" with
| true, "false" -> Some false
Expand Down
24 changes: 12 additions & 12 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ nuget "Microsoft.SqlServer.Types"
[<Test>]
let ``should read content none config``() =
let cfg = DependenciesFile.FromCode(noneContentConfig)
cfg.Options.Settings.OmitContent |> shouldEqual true
cfg.Options.Settings.OmitContent |> shouldEqual (Some true)
cfg.Options.Settings.CopyLocal |> shouldEqual None
cfg.Options.Settings.ImportTargets |> shouldEqual true
cfg.Options.Settings.ImportTargets |> shouldEqual None

(cfg.Packages |> List.find (fun p -> p.Name = PackageName "Microsoft.SqlServer.Types")).Sources |> shouldEqual [PackageSource.NugetSource "http://nuget.org/api/v2"]

Expand All @@ -187,9 +187,9 @@ nuget "Microsoft.SqlServer.Types"
[<Test>]
let ``should read config with specific framework``() =
let cfg = DependenciesFile.FromCode(specificFrameworkConfig)
cfg.Options.Settings.OmitContent |> shouldEqual false
cfg.Options.Settings.OmitContent |> shouldEqual None
cfg.Options.Settings.CopyLocal |> shouldEqual None
cfg.Options.Settings.ImportTargets |> shouldEqual true
cfg.Options.Settings.ImportTargets |> shouldEqual None

(cfg.Packages |> List.find (fun p -> p.Name = PackageName "Microsoft.SqlServer.Types")).Sources |> shouldEqual [PackageSource.NugetSource "http://nuget.org/api/v2"]

Expand All @@ -204,9 +204,9 @@ nuget "Microsoft.SqlServer.Types"
[<Test>]
let ``should read no targets import config``() =
let cfg = DependenciesFile.FromCode(noTargetsImportConfig)
cfg.Options.Settings.ImportTargets |> shouldEqual false
cfg.Options.Settings.ImportTargets |> shouldEqual (Some false)
cfg.Options.Settings.CopyLocal |> shouldEqual (Some false)
cfg.Options.Settings.OmitContent |> shouldEqual false
cfg.Options.Settings.OmitContent |> shouldEqual None

(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 @@ -547,7 +547,7 @@ let ``should read config with single framework restriction``() =
let p = cfg.Packages |> List.find (fun x-> x.Name = PackageName "Foobar")
p.VersionRequirement.Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "1.2.3"))
p.Settings.FrameworkRestrictions |> shouldEqual [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_Client))]
p.Settings.ImportTargets |> shouldEqual true
p.Settings.ImportTargets |> shouldEqual None


[<Test>]
Expand All @@ -560,7 +560,7 @@ let ``should read config with framework restriction``() =
let p = cfg.Packages |> List.find (fun x-> x.Name = PackageName "Foobar")
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.ImportTargets |> shouldEqual None
p.Settings.CopyLocal |> shouldEqual None

[<Test>]
Expand All @@ -573,9 +573,9 @@ let ``should read config with no targets import``() =
let p = cfg.Packages |> List.find (fun x-> x.Name = PackageName "Foobar")
p.VersionRequirement.Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "1.2.3"))
p.Settings.FrameworkRestrictions |> shouldEqual []
p.Settings.ImportTargets |> shouldEqual false
p.Settings.ImportTargets |> shouldEqual (Some false)
p.Settings.CopyLocal |> shouldEqual (Some false)
p.Settings.OmitContent |> shouldEqual false
p.Settings.OmitContent |> shouldEqual None

[<Test>]
let ``should read config with content none``() =
Expand All @@ -587,9 +587,9 @@ let ``should read config with content none``() =
let p = cfg.Packages |> List.find (fun x-> x.Name = PackageName "Foobar")
p.VersionRequirement.Range |> shouldEqual (VersionRange.Specific (SemVer.Parse "1.2.3"))
p.Settings.FrameworkRestrictions |> shouldEqual []
p.Settings.ImportTargets |> shouldEqual true
p.Settings.ImportTargets |> shouldEqual None
p.Settings.CopyLocal |> shouldEqual (Some false)
p.Settings.OmitContent |> shouldEqual true
p.Settings.OmitContent |> shouldEqual (Some true)


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

packages.[0].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[0].Name |> shouldEqual (PackageName "Castle.Windsor")
Expand Down Expand Up @@ -97,7 +97,7 @@ let ``should parse strict lock file``() =
packages.Length |> shouldEqual 6
lockFile.Options.Strict |> shouldEqual true
lockFile.Options.Redirects |> shouldEqual false
lockFile.Options.Settings.ImportTargets |> shouldEqual false
lockFile.Options.Settings.ImportTargets |> shouldEqual (Some false)
lockFile.Options.Settings.CopyLocal |> shouldEqual None

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

packages.Head.Source |> shouldEqual (PackageSource.LocalNuget("D:\code\\temp with space"))
Expand All @@ -142,7 +142,7 @@ let ``should parse lock file with framework restrictions``() =
packages.Length |> shouldEqual 1
lockFile.Options.Strict |> shouldEqual false
lockFile.Options.Redirects |> shouldEqual false
lockFile.Options.Settings.ImportTargets |> shouldEqual true
lockFile.Options.Settings.ImportTargets |> shouldEqual (Some true)
lockFile.Options.Settings.CopyLocal |> shouldEqual None

let dogfood = """NUGET
Expand Down Expand Up @@ -275,7 +275,7 @@ let ``should parse framework restricted lock file``() =
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.ImportTargets |> shouldEqual true
packages.[3].Settings.ImportTargets |> shouldEqual None

packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "ReadOnlyCollectionInterfaces")
Expand Down Expand Up @@ -315,15 +315,15 @@ let ``should parse framework restricted lock file in new syntax``() =
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 None
packages.[3].Settings.ImportTargets |> shouldEqual false
packages.[3].Settings.OmitContent |> shouldEqual true
packages.[3].Settings.ImportTargets |> shouldEqual (Some false)
packages.[3].Settings.OmitContent |> shouldEqual (Some 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.ImportTargets |> shouldEqual (Some false)
packages.[5].Settings.CopyLocal |> shouldEqual (Some false)
packages.[5].Settings.OmitContent |> shouldEqual false
packages.[5].Settings.OmitContent |> shouldEqual None
packages.[5].Settings.FrameworkRestrictions
|> shouldEqual ([FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V2))
FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V3_5))
Expand Down
Loading

0 comments on commit 2387796

Please sign in to comment.