Skip to content

Commit

Permalink
Merge pull request #1696 from shortsn/feature/excludedgroups
Browse files Browse the repository at this point in the history
Feature/excludedgroups
  • Loading branch information
forki committed May 23, 2016
2 parents 7a39fb6 + eaf6ebe commit 36edd22
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
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
25 changes: 21 additions & 4 deletions src/Paket.Core/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,17 @@ let addDependency (templateFile : TemplateFile) (dependency : PackageName * Vers
{ FileName = templateFile.FileName
Contents = CompleteInfo(core, { opt with Dependencies = newDeps }) }
| IncompleteTemplate ->
failwith "You should only try to add dependencies to template files with complete metadata."
failwith (sprintf "You should only try to add dependencies to template files with complete metadata.%sFile: %s" Environment.NewLine templateFile.FileName)

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 (sprintf "You should only try to exclude dependencies to template files with complete metadata.%sFile: %s" Environment.NewLine templateFile.FileName)

let toFile config platform (p : ProjectFile) =
Path.Combine(Path.GetDirectoryName p.FileName, p.GetOutputDirectory config platform, p.GetAssemblyName())
Expand All @@ -120,7 +130,7 @@ let addFile (source : string) (target : string) (templateFile : TemplateFile) =
{ FileName = templateFile.FileName
Contents = CompleteInfo(core, { opt with Files = (source,target) :: opt.Files }) }
| IncompleteTemplate ->
failwith "You should only try and add files to template files with complete metadata."
failwith (sprintf "You should only try and add files to template files with complete metadata.%sFile: %s" Environment.NewLine templateFile.FileName)

let findDependencies (dependenciesFile : DependenciesFile) config platform (template : TemplateFile) (project : ProjectFile) lockDependencies minimumFromLockFile (map : Map<string, TemplateFile * ProjectFile>) includeReferencedProjects (version :SemVerInfo option) specificVersions =
let targetDir =
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

0 comments on commit 36edd22

Please sign in to comment.