Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/excludedgroups #1696

Merged
merged 5 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/content/template-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ If you need to exclude dependencies from the automatic discovery then you can us
FSharp.Core
Other.Dep

Another way to exclude dependencies is to exclude a whole dependency group with the `excludedgroups` block:

excludedgroups
build
test

#### Pdb files

With the include-pdbs switch you can tell Paket to pack pdbs into the package.
Expand Down
21 changes: 19 additions & 2 deletions src/Paket.Core/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ let addDependency (templateFile : TemplateFile) (dependency : PackageName * Vers
| IncompleteTemplate ->
failwith "You should only try to add dependencies to template files with complete metadata."

let excludeDependency (templateFile : TemplateFile) (exclude : PackageName) =
match templateFile with
| CompleteTemplate(core, opt) ->
let newExcludes =
opt.ExcludedDependencies |> Set.add exclude
{ FileName = templateFile.FileName
Contents = CompleteInfo(core, { opt with ExcludedDependencies = newExcludes }) }
| IncompleteTemplate ->
failwith "You should only try to exclude dependencies to template files with complete metadata."
Copy link
Member

Choose a reason for hiding this comment

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

can you please extend this message to include the filename?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


let toFile config platform (p : ProjectFile) =
Path.Combine(Path.GetDirectoryName p.FileName, p.GetOutputDirectory config platform, p.GetAssemblyName())

Expand Down Expand Up @@ -188,6 +198,13 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp

additionalFiles
|> Array.fold (fun template file -> addFile file.FullName targetDir template) template

let templateWithOutputAndExcludes =
match template.Contents with
| CompleteInfo(core, optional) -> optional.ExcludedGroups
| ProjectInfo(core, optional) -> optional.ExcludedGroups
|> Seq.collect dependenciesFile.GetDependenciesInGroup
|> Seq.fold (fun templatefile package -> excludeDependency templatefile package.Key) templateWithOutput

// If project refs will also be packaged, add dependency
let withDeps =
Expand All @@ -202,7 +219,7 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
| None -> failwithf "There was no version given for %s." templateFile.FileName
| IncompleteTemplate ->
failwithf "You cannot create a dependency on a template file (%s) with incomplete metadata." templateFile.FileName)
|> List.fold addDependency templateWithOutput
|> List.fold addDependency templateWithOutputAndExcludes

// If project refs will not be packaged, add the assembly to the package
let withDepsAndIncluded =
Expand Down Expand Up @@ -267,7 +284,7 @@ let findDependencies (dependenciesFile : DependenciesFile) config platform (temp
group.Packages |> List.exists (fun p -> p.Name = settings.Name) ||
isDependencyOfAnyOtherDependency settings.Name |> not)
|> List.sortByDescending (fun (group, settings) -> settings.Name)

match refs with
| [] -> withDepsAndIncluded
| _ ->
Expand Down
20 changes: 18 additions & 2 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type OptionalPackagingInfo =
DevelopmentDependency : bool
Dependencies : (PackageName * VersionRequirement) list
ExcludedDependencies : Set<PackageName>
ExcludedGroups : Set<GroupName>
References : string list
FrameworkAssemblyReferences : string list
Files : (string * string) list
Expand All @@ -152,6 +153,7 @@ type OptionalPackagingInfo =
DevelopmentDependency = false
Dependencies = []
ExcludedDependencies = Set.empty
ExcludedGroups = Set.empty
References = []
FrameworkAssemblyReferences = []
Files = []
Expand Down Expand Up @@ -276,7 +278,7 @@ module internal TemplateFile =
|> Array.toList


let private getExcludedDependencies (fileName, lockFile:LockFile, info : Map<string, string>,currentVersion:SemVerInfo option) =
let private getExcludedDependencies (info : Map<string, string>) =
match Map.tryFind "excludeddependencies" info with
| None -> []
| Some d ->
Expand All @@ -286,6 +288,17 @@ module internal TemplateFile =
PackageName reg.Groups.["id"].Value)
|> Array.toList

let private getExcludedGroups (info : Map<string, string>) =
match Map.tryFind "excludedgroups" info with
| None -> []
| Some d ->
d.Split '\n'
|> Array.map (fun d ->
let reg = Regex(@"(?<id>\S+)").Match d
GroupName reg.Groups.["id"].Value)
|> Array.toList


let private fromReg = Regex("from (?<from>.*)", RegexOptions.Compiled)
let private toReg = Regex("to (?<to>.*)", RegexOptions.Compiled)
let private isExclude = Regex("\s*!\S", RegexOptions.Compiled)
Expand Down Expand Up @@ -352,7 +365,9 @@ module internal TemplateFile =
| _ -> false

let dependencies = getDependencies(fileName,lockFile,map,currentVersion,specificVersions)
let excludedDependencies = getExcludedDependencies(fileName,lockFile,map,currentVersion)

let excludedDependencies = map |> getExcludedDependencies
let excludedGroups = map |> getExcludedGroups

let includePdbs =
match get "include-pdbs" with
Expand All @@ -373,6 +388,7 @@ module internal TemplateFile =
DevelopmentDependency = developmentDependency
Dependencies = dependencies
ExcludedDependencies = Set.ofList excludedDependencies
ExcludedGroups = Set.ofList excludedGroups
References = getReferences map
FrameworkAssemblyReferences = getFrameworkReferences map
Files = getFiles map
Expand Down
3 changes: 3 additions & 0 deletions tests/Paket.Tests/TemplateFileParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ dependencies
excludeddependencies
Newtonsoft.Json
Chessie
excludedgroups
build
description
Railway-oriented programming for .NET"""

Expand Down Expand Up @@ -203,6 +205,7 @@ let ``Optional fields are read`` (fileContent : string) =
sut.Dependencies |> shouldContain (PackageName "FSharp.Core",VersionRequirement.Parse("[4.3.1]"))
sut.ExcludedDependencies |> shouldContain (PackageName "Newtonsoft.Json")
sut.ExcludedDependencies |> shouldContain (PackageName "Chessie")
sut.ExcludedGroups |> shouldContain (GroupName "build")

[<Literal>]
let Dependency1 = """type file
Expand Down