From da7a52d502e9f42fd2dc2d9a9834b18148a8d729 Mon Sep 17 00:00:00 2001 From: shortsn Date: Fri, 20 May 2016 21:41:50 +0200 Subject: [PATCH 1/5] ExcludedGroups --- src/Paket.Core/TemplateFile.fs | 15 +++++++++++++++ tests/Paket.Tests/TemplateFileParsing.fs | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/Paket.Core/TemplateFile.fs b/src/Paket.Core/TemplateFile.fs index 7d9c23d58e..042532f4c7 100644 --- a/src/Paket.Core/TemplateFile.fs +++ b/src/Paket.Core/TemplateFile.fs @@ -132,6 +132,7 @@ type OptionalPackagingInfo = DevelopmentDependency : bool Dependencies : (PackageName * VersionRequirement) list ExcludedDependencies : Set + ExcludedGroups : Set References : string list FrameworkAssemblyReferences : string list Files : (string * string) list @@ -152,6 +153,7 @@ type OptionalPackagingInfo = DevelopmentDependency = false Dependencies = [] ExcludedDependencies = Set.empty + ExcludedGroups = Set.empty References = [] FrameworkAssemblyReferences = [] Files = [] @@ -286,6 +288,17 @@ module internal TemplateFile = PackageName reg.Groups.["id"].Value) |> Array.toList + let private getExcludedGroups (fileName, lockFile:LockFile, info : Map,currentVersion:SemVerInfo option) = + match Map.tryFind "excludedgroups" info with + | None -> [] + | Some d -> + d.Split '\n' + |> Array.map (fun d -> + let reg = Regex(@"(?\S+)").Match d + GroupName reg.Groups.["id"].Value) + |> Array.toList + + let private fromReg = Regex("from (?.*)", RegexOptions.Compiled) let private toReg = Regex("to (?.*)", RegexOptions.Compiled) let private isExclude = Regex("\s*!\S", RegexOptions.Compiled) @@ -353,6 +366,7 @@ module internal TemplateFile = let dependencies = getDependencies(fileName,lockFile,map,currentVersion,specificVersions) let excludedDependencies = getExcludedDependencies(fileName,lockFile,map,currentVersion) + let excludedGroups = getExcludedGroups(fileName,lockFile,map,currentVersion) let includePdbs = match get "include-pdbs" with @@ -373,6 +387,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 diff --git a/tests/Paket.Tests/TemplateFileParsing.fs b/tests/Paket.Tests/TemplateFileParsing.fs index 089e674fbd..c9195eec1b 100644 --- a/tests/Paket.Tests/TemplateFileParsing.fs +++ b/tests/Paket.Tests/TemplateFileParsing.fs @@ -170,6 +170,8 @@ dependencies excludeddependencies Newtonsoft.Json Chessie +excludedgroups + build description Railway-oriented programming for .NET""" @@ -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") [] let Dependency1 = """type file From c6a05cf6bc0c2e1b22ed671ccf00889b04c43b0d Mon Sep 17 00:00:00 2001 From: shortsn Date: Fri, 20 May 2016 23:31:39 +0200 Subject: [PATCH 2/5] translate excluded groups to excluded dependencies --- src/Paket.Core/PackageMetaData.fs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Paket.Core/PackageMetaData.fs b/src/Paket.Core/PackageMetaData.fs index 937f02bf7c..f603b8fbc9 100644 --- a/src/Paket.Core/PackageMetaData.fs +++ b/src/Paket.Core/PackageMetaData.fs @@ -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." + let toFile config platform (p : ProjectFile) = Path.Combine(Path.GetDirectoryName p.FileName, p.GetOutputDirectory config platform, p.GetAssemblyName()) @@ -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 = @@ -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 = @@ -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 | _ -> From aed2df18a7830f66bbdee42f5bf6a6c4d4fe47da Mon Sep 17 00:00:00 2001 From: shortsn Date: Sat, 21 May 2016 00:08:35 +0200 Subject: [PATCH 3/5] removed unused arguments --- src/Paket.Core/TemplateFile.fs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Paket.Core/TemplateFile.fs b/src/Paket.Core/TemplateFile.fs index 042532f4c7..ac64383b4d 100644 --- a/src/Paket.Core/TemplateFile.fs +++ b/src/Paket.Core/TemplateFile.fs @@ -278,7 +278,7 @@ module internal TemplateFile = |> Array.toList - let private getExcludedDependencies (fileName, lockFile:LockFile, info : Map,currentVersion:SemVerInfo option) = + let private getExcludedDependencies (info : Map) = match Map.tryFind "excludeddependencies" info with | None -> [] | Some d -> @@ -288,7 +288,7 @@ module internal TemplateFile = PackageName reg.Groups.["id"].Value) |> Array.toList - let private getExcludedGroups (fileName, lockFile:LockFile, info : Map,currentVersion:SemVerInfo option) = + let private getExcludedGroups (info : Map) = match Map.tryFind "excludedgroups" info with | None -> [] | Some d -> @@ -365,8 +365,9 @@ module internal TemplateFile = | _ -> false let dependencies = getDependencies(fileName,lockFile,map,currentVersion,specificVersions) - let excludedDependencies = getExcludedDependencies(fileName,lockFile,map,currentVersion) - let excludedGroups = getExcludedGroups(fileName,lockFile,map,currentVersion) + + let excludedDependencies = map |> getExcludedDependencies + let excludedGroups = map |> getExcludedGroups let includePdbs = match get "include-pdbs" with From 37f18a09757d12f62296e568d36fab0322bb7afb Mon Sep 17 00:00:00 2001 From: shortsn Date: Sat, 21 May 2016 00:16:58 +0200 Subject: [PATCH 4/5] docs --- docs/content/template-files.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/content/template-files.md b/docs/content/template-files.md index 429b25a50f..8635e001d4 100644 --- a/docs/content/template-files.md +++ b/docs/content/template-files.md @@ -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. From eaf6ebe67c1349124bdaa0f6faaa813f608809e8 Mon Sep 17 00:00:00 2001 From: shortsn Date: Sat, 21 May 2016 22:21:02 +0200 Subject: [PATCH 5/5] #1696 mentioned filename in error message --- src/Paket.Core/PackageMetaData.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Paket.Core/PackageMetaData.fs b/src/Paket.Core/PackageMetaData.fs index f603b8fbc9..9d1890d99e 100644 --- a/src/Paket.Core/PackageMetaData.fs +++ b/src/Paket.Core/PackageMetaData.fs @@ -109,7 +109,7 @@ 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 @@ -119,7 +119,7 @@ let excludeDependency (templateFile : TemplateFile) (exclude : PackageName) = { 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." + 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()) @@ -130,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) includeReferencedProjects (version :SemVerInfo option) specificVersions = let targetDir =