Skip to content

Commit

Permalink
Allow to opt-out of targets import via global switch in paket.depende…
Browse files Browse the repository at this point in the history
…ncies - references #615
  • Loading branch information
forki committed Feb 17, 2015
1 parent 392cd40 commit 739d900
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 3 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.28.7 - 17.02.2015
* Allow to opt-out of targets import via global switch in `paket.dependencies` - https://github.com/fsprojects/Paket/issues/615

#### 0.28.6 - 17.02.2015
* Allow to restrict content files in `paket.references` - https://github.com/fsprojects/Paket/issues/587

Expand Down
10 changes: 10 additions & 0 deletions docs/content/dependencies-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ This option disables the installation of any content files.
nuget jQuery >= 0 // we don't install jQuery content files
nuget UnionArgParser ~> 0.7

## import_targets settings

If you don't want to import `.targets` and `.props` files you can disable it via the `import_targets` switch:

import_targets false
source https://nuget.org/api/v2

nuget Microsoft.Bcl.Build // we don't import .targets and .props
nuget UnionArgParser ~> 0.7

## Redirects option

This option tells paket to create [Assembly Binding Redirects](https://msdn.microsoft.com/en-us/library/433ysdt1(v=vs.110).aspx) for all referenced libraries.
Expand Down
7 changes: 6 additions & 1 deletion src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ open Paket.PackageSources
type InstallOptions =
{ Strict : bool
Redirects : bool
ImportTargets : bool
OmitContent : bool }

static member Default = { Strict = false; OmitContent = false; Redirects = false}
static member Default = { Strict = false; OmitContent = false; Redirects = false; ImportTargets = true}

/// [omit]
module DependenciesFileParser =
Expand Down Expand Up @@ -132,6 +133,7 @@ module DependenciesFileParser =
type private ParserOption =
| ReferencesMode of bool
| OmitContent of bool
| ImportTargets of bool
| Redirects of bool

let private (|Remote|Package|Comment|ParserOptions|SourceFile|) (line:string) =
Expand Down Expand Up @@ -161,6 +163,7 @@ module DependenciesFileParser =
| String.StartsWith "references" trimmed -> ParserOptions(ParserOption.ReferencesMode(trimmed.Trim() = "strict"))
| String.StartsWith "redirects" trimmed -> ParserOptions(ParserOption.Redirects(trimmed.Trim() = "on"))
| String.StartsWith "content" trimmed -> ParserOptions(ParserOption.OmitContent(trimmed.Trim() = "none"))
| String.StartsWith "import_targets" trimmed -> ParserOptions(ParserOption.ImportTargets(trimmed.Trim() = "true"))
| String.StartsWith "gist" _ as trimmed ->
SourceFile(``parse git source`` trimmed SingleSourceFileOrigin.GistLink "gist")
| String.StartsWith "github" _ as trimmed ->
Expand All @@ -181,6 +184,7 @@ module DependenciesFileParser =
| Comment(line) -> lineNo, options, sources, packages, sourceFiles, if line <> "" then (lineNo,line)::comments else comments
| ParserOptions(ParserOption.ReferencesMode mode) -> lineNo, { options with Strict = mode }, sources, packages, sourceFiles, comments
| ParserOptions(ParserOption.Redirects mode) -> lineNo, { options with Redirects = mode }, sources, packages, sourceFiles, comments
| ParserOptions(ParserOption.ImportTargets mode) -> lineNo, { options with ImportTargets = mode }, sources, packages, sourceFiles, comments
| ParserOptions(ParserOption.OmitContent omit) -> lineNo, { options with OmitContent = omit }, sources, packages, sourceFiles, comments
| Package(name,version,rest) ->
let prereleases,kvPairs =
Expand Down Expand Up @@ -419,6 +423,7 @@ type DependenciesFile(fileName,options,sources,packages : PackageRequirement lis
let hasReportedFirst = ref false
let hasReportedSecond = ref false
[ if options.Strict then yield "references strict"
if not options.ImportTargets then yield "import_targets false"
if options.OmitContent then yield "content none"
for sources, packages in sources do
for source in sources do
Expand Down
4 changes: 3 additions & 1 deletion src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ let InstallIntoProjects(sources,force, hard, withBindingRedirects, lockFile:Lock

let usedPackageSettings =
usedPackages
|> Seq.map (fun u -> NormalizedPackageName u.Key,u.Value)
|> Seq.map (fun u -> NormalizedPackageName u.Key,
{ u.Value
with ImportTargets = u.Value.ImportTargets && lockFile.Options.ImportTargets })
|> Map.ofSeq

project.UpdateReferences(model,usedPackageSettings,hard)
Expand Down
6 changes: 5 additions & 1 deletion src/Paket.Core/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module LockFileSerializer =
[ if options.Strict then yield "REFERENCES: STRICT"
if options.OmitContent then yield "CONTENT: NONE"
if options.Redirects then yield "REDIRECTS: ON"
if not options.ImportTargets then yield "IMPORT-TARGETS: FALSE"
for (source, _), packages in sources do
if not !hasReported then
yield "NUGET"
Expand Down Expand Up @@ -117,6 +118,7 @@ module LockFileParser =
type private ParserOption =
| ReferencesMode of bool
| OmitContent of bool
| ImportTargets of bool
| Redirects of bool

let private (|Remote|NugetPackage|NugetDependency|SourceFile|RepositoryType|Blank|InstallOption|) (state, line:string) =
Expand All @@ -130,6 +132,7 @@ module LockFileParser =
| _, String.StartsWith "specs:" _ -> Blank
| _, String.StartsWith "REFERENCES:" trimmed -> InstallOption(ReferencesMode(trimmed.Trim() = "STRICT"))
| _, String.StartsWith "REDIRECTS:" trimmed -> InstallOption(Redirects(trimmed.Trim() = "ON"))
| _, String.StartsWith "IMPORT-TARGETS:" trimmed -> InstallOption(ImportTargets(trimmed.Trim() = "TRUE"))
| _, String.StartsWith "CONTENT:" trimmed -> InstallOption(OmitContent(trimmed.Trim() = "NONE"))
| _, trimmed when line.StartsWith " " ->
if trimmed.Contains("(") then
Expand All @@ -154,6 +157,7 @@ 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 ImportTargets = mode} }
| InstallOption (OmitContent(omit)) -> { state with Options = {state.Options with OmitContent = omit} }
| RepositoryType repoType -> { state with RepositoryType = Some repoType }
| NugetPackage details ->
Expand Down Expand Up @@ -248,7 +252,7 @@ module LockFileParser =


/// Allows to parse and analyze paket.lock files.
type LockFile(fileName:string,options,resolution:PackageResolution,remoteFiles:ResolvedSourceFile list) =
type LockFile(fileName:string,options:InstallOptions,resolution:PackageResolution,remoteFiles:ResolvedSourceFile list) =

let dependenciesByPackageLazy = lazy (
let allDependenciesOf package =
Expand Down
16 changes: 16 additions & 0 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ nuget "Microsoft.SqlServer.Types"
let ``should read content none config``() =
let cfg = DependenciesFile.FromCode(noneContentConfig)
cfg.Options.OmitContent |> shouldEqual true
cfg.Options.ImportTargets |> shouldEqual true

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

let noTargetsImportConfig = """
import_targets false
source "http://nuget.org/api/v2" // first source
nuget "Microsoft.SqlServer.Types"
"""

[<Test>]
let ``should read no targets import config``() =
let cfg = DependenciesFile.FromCode(noTargetsImportConfig)
cfg.Options.ImportTargets |> shouldEqual false
cfg.Options.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
13 changes: 13 additions & 0 deletions tests/Paket.Tests/DependenciesFile/SaveSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ let ``should serialize content none config``() =
cfg.ToString()
|> shouldEqual (normalizeLineEndings contentNoneConfig)

let noTargetsConfig = """import_targets false
source http://nuget.org/api/v2
nuget FAKE ~> 3.0"""


[<Test>]
let ``should serialize no targets config``() =
let cfg = DependenciesFile.FromCode(noTargetsConfig)

cfg.ToString()
|> shouldEqual (normalizeLineEndings noTargetsConfig)

let simplestConfig = """nuget FAKE ~> 3.0"""

[<Test>]
Expand Down
2 changes: 2 additions & 0 deletions tests/Paket.Tests/Lockfile/GenerateWithOptionsSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let ``should generate strict lock file``() =

let configWithContent = """
content none
import_targets false
source "http://nuget.org/api/v2"
nuget "Microsoft.SqlServer.Types"
Expand All @@ -42,6 +43,7 @@ let graph2 = [
]

let expected2 = """CONTENT: NONE
IMPORT-TARGETS: FALSE
NUGET
remote: http://nuget.org/api/v2
specs:
Expand Down
5 changes: 5 additions & 0 deletions tests/Paket.Tests/Lockfile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let ``should parse lock file``() =
let packages = List.rev lockFile.Packages
packages.Length |> shouldEqual 6
lockFile.Options.Strict |> shouldEqual false
lockFile.Options.ImportTargets |> shouldEqual true

packages.[0].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[0].Name |> shouldEqual (PackageName "Castle.Windsor")
Expand Down Expand Up @@ -70,6 +71,7 @@ let ``should parse lock file``() =
sourceFiles.[0].ToString() |> shouldEqual "fsharp/FAKE:7699e40e335f3cc54ab382a8969253fecc1e08a9 src/app/FAKE/Cli.fs"

let strictLockFile = """REFERENCES: STRICT
IMPORT-TARGETS: FALSE
NUGET
remote: https://nuget.org/api/v2
specs:
Expand All @@ -92,13 +94,15 @@ let ``should parse strict lock file``() =
packages.Length |> shouldEqual 6
lockFile.Options.Strict |> shouldEqual true
lockFile.Options.Redirects |> shouldEqual false
lockFile.Options.ImportTargets |> shouldEqual false

packages.[5].Source |> shouldEqual PackageSources.DefaultNugetSource
packages.[5].Name |> shouldEqual (PackageName "log4net")
packages.[5].Version |> shouldEqual (SemVer.Parse "1.1")
packages.[5].Dependencies |> shouldEqual (Set.ofList [PackageName "log", VersionRequirement.AllReleases, []])

let redirectsLockFile = """REDIRECTS: ON
IMPORT-TARGETS: TRUE
NUGET
remote: https://nuget.org/api/v2
specs:
Expand All @@ -112,6 +116,7 @@ let ``should parse redirects lock file``() =
packages.Length |> shouldEqual 1
lockFile.Options.Strict |> shouldEqual false
lockFile.Options.Redirects |> shouldEqual true
lockFile.Options.ImportTargets |> shouldEqual true

let dogfood = """NUGET
remote: https://nuget.org/api/v2
Expand Down

0 comments on commit 739d900

Please sign in to comment.