From dc380150078e92b5126a0de147dcc86e67af0169 Mon Sep 17 00:00:00 2001 From: DavidHayden87 Date: Tue, 1 Dec 2015 13:22:47 +0000 Subject: [PATCH] #868 Added option to create symbols packages Symbol/source packages can now be created by passing the symbols argument to the pack command --- Paket.sln | 1 + src/Paket.Core/PackageMetaData.fs | 5 ++- src/Paket.Core/PackageProcess.fs | 60 +++++++++++++++++++------- src/Paket.Core/ProjectFile.fs | 18 ++++++++ src/Paket.Core/PublicAPI.fs | 5 ++- src/Paket.Core/TemplateFile.fs | 20 ++++++--- src/Paket/Commands.fs | 2 + src/Paket/Paket.fsproj | 3 +- src/Paket/Program.fs | 3 +- tests/Paket.Tests/NuspecWriterSpecs.fs | 15 ++++--- 10 files changed, 100 insertions(+), 32 deletions(-) diff --git a/Paket.sln b/Paket.sln index 89f0e11826..31d29f5cff 100644 --- a/Paket.sln +++ b/Paket.sln @@ -69,6 +69,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "commands", "commands", "{44 docs\content\commands\find-packages.md = docs\content\commands\find-packages.md docs\content\commands\find-refs.md = docs\content\commands\find-refs.md docs\content\commands\outdated.md = docs\content\commands\outdated.md + docs\content\commands\pack.md = docs\content\commands\pack.md docs\content\commands\remove.md = docs\content\commands\remove.md docs\content\commands\show-installed-packages.md = docs\content\commands\show-installed-packages.md docs\content\commands\simplify.md = docs\content\commands\simplify.md diff --git a/src/Paket.Core/PackageMetaData.fs b/src/Paket.Core/PackageMetaData.fs index 74d4f79cac..5d5c33d22c 100644 --- a/src/Paket.Core/PackageMetaData.fs +++ b/src/Paket.Core/PackageMetaData.fs @@ -110,11 +110,12 @@ let loadAssemblyAttributes fileName (assembly:Assembly) = let (|Valid|Invalid|) md = match md with - | { ProjectCoreInfo.Id = Some id'; Version = Some v; Authors = Some a; Description = Some d } -> + | { ProjectCoreInfo.Id = Some id'; Version = Some v; Authors = Some a; Description = Some d; Symbols = s } -> Valid { CompleteCoreInfo.Id = id' Version = Some v Authors = a - Description = d } + Description = d + Symbols = s } | _ -> Invalid let addDependency (templateFile : TemplateFile) (dependency : PackageName * VersionRequirement) = diff --git a/src/Paket.Core/PackageProcess.fs b/src/Paket.Core/PackageProcess.fs index 859e6e6643..1e10aa9ec3 100644 --- a/src/Paket.Core/PackageProcess.fs +++ b/src/Paket.Core/PackageProcess.fs @@ -33,7 +33,8 @@ let private merge buildConfig version projectFile templateFile = { Id = md.Id Version = md.Version ++ getVersion assembly attribs Authors = md.Authors ++ getAuthors attribs - Description = md.Description ++ getDescription attribs } + Description = md.Description ++ getDescription attribs + Symbols = md.Symbols } match merged with | Invalid -> @@ -53,7 +54,28 @@ let private merge buildConfig version projectFile templateFile = | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) } | _ -> templateFile -let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, version, releaseNotes, templateFile, lockDependencies) = +let private convertToSymbols (projectFile : ProjectFile) templateFile = + let sourceFiles = + let getTarget compileItem = + match compileItem.Link with + | Some link -> link + | None -> compileItem.Include + |> Path.GetDirectoryName + |> (fun d -> Path.Combine("src", d)) + + projectFile.GetCompileItems() + |> Seq.map (fun c -> c.Include, getTarget c) + |> Seq.toList + + match templateFile.Contents with + | CompleteInfo(core, optional) -> + let augmentedFiles = optional.Files |> List.append sourceFiles + { templateFile with Contents = CompleteInfo({ core with Symbols = true }, { optional with Files = augmentedFiles }) } + | ProjectInfo(core, optional) -> + let augmentedFiles = optional.Files |> List.append sourceFiles + { templateFile with Contents = ProjectInfo({ core with Symbols = true }, { optional with Files = augmentedFiles }) } + +let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, version, releaseNotes, templateFile, lockDependencies, symbols) = let buildConfig = defaultArg buildConfig "Release" let packageOutputPath = if Path.IsPathRooted(packageOutputPath) then packageOutputPath else Path.Combine(workingDir,packageOutputPath) Utils.createDir packageOutputPath |> returnOrFail @@ -99,22 +121,30 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon // add dependencies let allTemplates = + let optWithSymbols projectFile templateFile = + seq { yield templateFile; if symbols then yield templateFile |> convertToSymbols projectFile } + + let convertRemainingTemplate fileName = + let templateFile = TemplateFile.Load(fileName,lockFile,version) + match templateFile with + | { Contents = ProjectInfo(_) } -> + let fi = FileInfo(fileName) + let allProjectFiles = ProjectFile.FindAllProjects(fi.Directory.FullName) |> Array.toList + + match allProjectFiles with + | [ projectFile ] -> + merge buildConfig version projectFile templateFile + |> optWithSymbols projectFile + | [] -> failwithf "There was no project file found for template file %s" fileName + | _ -> failwithf "There was more than one project file found for template file %s" fileName + | _ -> seq { yield templateFile } + projectTemplates |> Map.map (fun _ (t, p) -> p,findDependencies dependencies buildConfig t p lockDependencies projectTemplates) |> Map.toList - |> List.map (fun (_,(_,x)) -> x) - |> List.append [for fileName in allTemplateFiles -> - let templateFile = TemplateFile.Load(fileName,lockFile,version) - match templateFile with - | { Contents = ProjectInfo(_) } -> - let fi = FileInfo(fileName) - let allProjectFiles = ProjectFile.FindAllProjects(fi.Directory.FullName) |> Array.toList - - match allProjectFiles with - | [ projectFile ] -> merge buildConfig version projectFile templateFile - | [] -> failwithf "There was no project file found for template file %s" fileName - | _ -> failwithf "There was more than one project file found for template file %s" fileName - | _ -> templateFile ] + |> Seq.collect (fun (_,(p,t)) -> t |> optWithSymbols p) + |> Seq.append (allTemplateFiles |> Seq.collect convertRemainingTemplate) + |> Seq.toList // set version let templatesWithVersion = diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index 206815a9f8..716ec62808 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -22,6 +22,11 @@ type ProjectReference = Name : string GUID : Guid } +/// Compile items inside of project files. +type CompileItem = + { Include : string + Link : string option } + /// Project output type. [] type ProjectOutputType = @@ -1005,6 +1010,19 @@ type ProjectFile = sprintf "%s.%s" assemblyName (this.OutputType |> function ProjectOutputType.Library -> "dll" | ProjectOutputType.Exe -> "exe") + member this.GetCompileItems () = + let getCompileItem (compileNode : XmlNode) = + let includePath = compileNode |> getAttribute "Include" |> fun a -> a.Value + compileNode + |> getDescendants "Link" + |> function + | [] -> { Include = includePath; Link = None } + | [link] | link::_ -> { Include = includePath; Link = Some link.InnerText } + + this.Document + |> getDescendants "Compile" + |> Seq.map getCompileItem + static member LoadFromStream(fullName:string, stream:Stream) = let doc = new XmlDocument() doc.Load stream diff --git a/src/Paket.Core/PublicAPI.fs b/src/Paket.Core/PublicAPI.fs index e972c321df..d66e901a96 100644 --- a/src/Paket.Core/PublicAPI.fs +++ b/src/Paket.Core/PublicAPI.fs @@ -456,11 +456,12 @@ type Dependencies(dependenciesFileName: string) = FindReferences.FindReferencesForPackage (GroupName group) (PackageName package) |> this.Process // Packs all paket.template files. - member this.Pack(outputPath, ?buildConfig, ?version, ?releaseNotes, ?templateFile, ?workingDir, ?lockDependencies) = + member this.Pack(outputPath, ?buildConfig, ?version, ?releaseNotes, ?templateFile, ?workingDir, ?lockDependencies, ?symbols) = let dependenciesFile = DependenciesFile.ReadFromFile dependenciesFileName let workingDir = defaultArg workingDir (dependenciesFile.FileName |> Path.GetDirectoryName) let lockDependencies = defaultArg lockDependencies false - PackageProcess.Pack(workingDir, dependenciesFile, outputPath, buildConfig, version, releaseNotes, templateFile, lockDependencies) + let symbols = defaultArg symbols false + PackageProcess.Pack(workingDir, dependenciesFile, outputPath, buildConfig, version, releaseNotes, templateFile, lockDependencies, symbols) /// Pushes a nupkg file. static member Push(packageFileName, ?url, ?apiKey, (?endPoint: string), ?maxTrials) = diff --git a/src/Paket.Core/TemplateFile.fs b/src/Paket.Core/TemplateFile.fs index 0044eb77f2..a555a89941 100644 --- a/src/Paket.Core/TemplateFile.fs +++ b/src/Paket.Core/TemplateFile.fs @@ -93,10 +93,14 @@ type CompleteCoreInfo = { Id : string Version : SemVerInfo option Authors : string list - Description : string } + Description : string + Symbols : bool } member this.PackageFileName = match this.Version with - | Some v -> sprintf "%s.%O.nupkg" this.Id v + | Some v -> + if this.Symbols + then sprintf "%s.%O.symbols.nupkg" this.Id v + else sprintf "%s.%O.nupkg" this.Id v | None -> failwithf "No version given for %s" this.Id member this.NuspecFileName = this.Id + ".nuspec" @@ -104,12 +108,14 @@ type ProjectCoreInfo = { Id : string option Version : SemVerInfo option Authors : string list option - Description : string option } + Description : string option + Symbols : bool } static member Empty = { Id = None Authors = None Version = None - Description = None } + Description = None + Symbols = false } type OptionalPackagingInfo = { Title : string option @@ -376,7 +382,8 @@ module internal TemplateFile = s.Split(',') |> Array.map (fun s -> s.Trim()) |> Array.toList) - Description = Map.tryFind "description" map } + Description = Map.tryFind "description" map + Symbols = false } let optionalInfo = getOptionalInfo(file,lockFile,map,currentVersion) return ProjectInfo(core, optionalInfo) @@ -388,7 +395,8 @@ module internal TemplateFile = { Id = id' Version = Map.tryFind "version" map |> Option.map SemVer.Parse Authors = authors - Description = description } + Description = description + Symbols = false } let optionalInfo = getOptionalInfo(file,lockFile,map,currentVersion) return CompleteInfo(core, optionalInfo) diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index a10451dcc6..c01500e423 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -296,6 +296,7 @@ type PackArgs = | [] TemplateFile of string | [] ReleaseNotes of string | [] LockDependencies + | [] Symbols with interface IArgParserTemplate with member this.Usage = @@ -306,6 +307,7 @@ with | TemplateFile(_) -> "Allows to specify a single template file." | ReleaseNotes(_) -> "Specify relase notes for the package." | LockDependencies -> "Get the version requirements from paket.lock instead of paket.dependencies." + | Symbols -> "Build symbol/source package." type PushArgs = | [][] Url of string diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index bd10c5bdd7..be4ca8b5b6 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -37,7 +37,7 @@ update group Build pack output D:\code\paketbug\output install - update + pack buildconfig Debug output . symbols Project paket.exe c:\code\Paketkopie @@ -46,6 +46,7 @@ d:\code\paketbug d:\code\paketrepro D:\code\Paket\integrationtests\scenarios\i001270-net461\temp + D:\Repositories\frameworks\platform-test-service\ pdbonly diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index 16b1ac9e6d..6a8fde01fd 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -219,7 +219,8 @@ let pack (results : ParseResults<_>) = ?releaseNotes = results.TryGetResult <@ PackArgs.ReleaseNotes @>, ?templateFile = results.TryGetResult <@ PackArgs.TemplateFile @>, workingDir = Environment.CurrentDirectory, - lockDependencies = results.Contains <@ PackArgs.LockDependencies @>) + lockDependencies = results.Contains <@ PackArgs.LockDependencies @>, + symbols = results.Contains <@ PackArgs.Symbols @>) let findPackages (results : ParseResults<_>) = let maxResults = defaultArg (results.TryGetResult <@ FindPackagesArgs.MaxResults @>) 10000 diff --git a/tests/Paket.Tests/NuspecWriterSpecs.fs b/tests/Paket.Tests/NuspecWriterSpecs.fs index ff10a831c6..87e797fb85 100644 --- a/tests/Paket.Tests/NuspecWriterSpecs.fs +++ b/tests/Paket.Tests/NuspecWriterSpecs.fs @@ -23,7 +23,8 @@ let ``should serialize core info``() = { Id = "Paket.Tests" Version = SemVer.Parse "1.0.0.0" |> Some Authors = [ "Two"; "Authors" ] - Description = "A description" } + Description = "A description" + Symbols = false } let doc = NupkgWriter.nuspecDoc (core, OptionalPackagingInfo.Epmty) doc.ToString() @@ -50,7 +51,8 @@ let ``should serialize dependencies``() = { Id = "Paket.Tests" Version = SemVer.Parse "1.0.0.0" |> Some Authors = [ "Two"; "Authors" ] - Description = "A description" } + Description = "A description" + Symbols = false } let optional = { OptionalPackagingInfo.Epmty with @@ -85,7 +87,8 @@ let ``should serialize frameworkAssemblues``() = { Id = "Paket.Tests" Version = SemVer.Parse "1.0.0.0" |> Some Authors = [ "Two"; "Authors" ] - Description = "A description" } + Description = "A description" + Symbols = false } let optional = { OptionalPackagingInfo.Epmty with @@ -114,7 +117,8 @@ let ``should not serialize files``() = { Id = "Paket.Core" Version = SemVer.Parse "4.2" |> Some Authors = [ "Michael"; "Steffen" ] - Description = "A description" } + Description = "A description" + Symbols = false } let optional = { OptionalPackagingInfo.Epmty with @@ -160,7 +164,8 @@ second line { Id = "Paket.Core" Version = SemVer.Parse "4.2" |> Some Authors = [ "Michael"; "Steffen" ] - Description = "A description" } + Description = "A description" + Symbols = false } let optional = { OptionalPackagingInfo.Epmty with