Skip to content

Commit

Permalink
fsprojects#868 Added option to create symbols packages
Browse files Browse the repository at this point in the history
Symbol/source packages can now be created by passing the symbols
argument to the pack command
  • Loading branch information
Haydabase committed Dec 1, 2015
1 parent 9e84306 commit dc38015
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 32 deletions.
1 change: 1 addition & 0 deletions Paket.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Paket.Core/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
60 changes: 45 additions & 15 deletions src/Paket.Core/PackageProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
18 changes: 18 additions & 0 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
[<RequireQualifiedAccess>]
type ProjectOutputType =
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
20 changes: 14 additions & 6 deletions src/Paket.Core/TemplateFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,29 @@ 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"

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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ type PackArgs =
| [<CustomCommandLine("templatefile")>] TemplateFile of string
| [<CustomCommandLine("releaseNotes")>] ReleaseNotes of string
| [<CustomCommandLine("lock-dependencies")>] LockDependencies
| [<CustomCommandLine("symbols")>] Symbols
with
interface IArgParserTemplate with
member this.Usage =
Expand All @@ -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 =
| [<CustomCommandLine("url")>][<Mandatory>] Url of string
Expand Down
3 changes: 2 additions & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<StartArguments>update group Build</StartArguments>
<StartArguments>pack output D:\code\paketbug\output</StartArguments>
<StartArguments>install</StartArguments>
<StartArguments>update</StartArguments>
<StartArguments>pack buildconfig Debug output . symbols</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>c:\code\Paketkopie</StartWorkingDirectory>
Expand All @@ -46,6 +46,7 @@
<StartWorkingDirectory>d:\code\paketbug</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\paketrepro</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\Paket\integrationtests\scenarios\i001270-net461\temp</StartWorkingDirectory>
<StartWorkingDirectory>D:\Repositories\frameworks\platform-test-service\</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
3 changes: 2 additions & 1 deletion src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions tests/Paket.Tests/NuspecWriterSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -160,7 +164,8 @@ second line</releaseNotes>
{ 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
Expand Down

0 comments on commit dc38015

Please sign in to comment.