Skip to content

Commit

Permalink
include symbols and src from referenced projects
Browse files Browse the repository at this point in the history
* include source files for referenced projects in symbols nupkg's
* ensure pdb's for referenced projects are included in nupkg's
* add command line option for pack (include-referenced-projects)
* create some tests for some of the above
  • Loading branch information
Paul Saunders committed Jan 11, 2016
1 parent 354c8ba commit 4d549cc
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 30 deletions.
28 changes: 17 additions & 11 deletions src/Paket.Core/PackageMetaData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,25 @@ let findDependencies (dependencies : DependenciesFile) config platform (template

// Add the assembly + pdb + dll from this project
let templateWithOutput =
let assemblyFileName = toFile config platform project
let fi = FileInfo(assemblyFileName)
let name = Path.GetFileNameWithoutExtension fi.Name
let additionalFiles =
let referencedProjects = seq{yield project; yield! project.GetInterProjectDependencies() |> Seq.map(fun proj -> ProjectFile.TryLoad(proj.Path).Value)}
let assemblyNames = referencedProjects
|> Seq.map (fun proj -> proj.GetAssemblyName())
assemblyNames
|> Seq.collect (fun assemblyFileName ->
let fi = FileInfo(assemblyFileName)
let name = Path.GetFileNameWithoutExtension fi.Name

let additionalFiles =
fi.Directory.GetFiles(name + ".*")
|> Array.filter (fun f ->
let isSameFileName = Path.GetFileNameWithoutExtension f.Name = name
let isValidExtension =
[".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"]
|> List.exists ((=) (f.Extension.ToLower()))
fi.Directory.GetFiles(Path.Combine(project.GetOutputDirectory config platform, name + ".*"))
|> Array.filter (fun f ->
let isSameFileName = (Path.GetFileNameWithoutExtension f.Name) = name
let isValidExtension =
[".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"]
|> List.exists ((=) (f.Extension.ToLower()))

isSameFileName && isValidExtension)
isSameFileName && isValidExtension)
)
|> Seq.toArray

additionalFiles
|> Array.fold (fun template file -> addFile file.FullName targetDir template) template
Expand Down
10 changes: 5 additions & 5 deletions src/Paket.Core/PackageProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let private merge buildConfig buildPlatform versionFromAssembly specificVersions
| Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, mergedOpt) }
| _ -> templateFile

let private convertToSymbols (projectFile : ProjectFile) templateFile =
let private convertToSymbols (projectFile : ProjectFile) (includeReferencedProjects : bool) templateFile =
let sourceFiles =
let getTarget compileItem =
match compileItem.Link with
Expand All @@ -73,7 +73,7 @@ let private convertToSymbols (projectFile : ProjectFile) templateFile =
|> Path.GetDirectoryName
|> (fun d -> Path.Combine("src", d))

projectFile.GetCompileItems()
projectFile.GetCompileItems(includeReferencedProjects)
|> Seq.map (fun c -> c.Include, getTarget c)
|> Seq.toList

Expand All @@ -85,7 +85,7 @@ let private convertToSymbols (projectFile : ProjectFile) templateFile =
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, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols) =
let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols, includeReferencedProjects) =
let buildConfig = defaultArg buildConfig "Release"
let buildPlatform = defaultArg buildPlatform ""
let packageOutputPath = if Path.IsPathRooted(packageOutputPath) then packageOutputPath else Path.Combine(workingDir,packageOutputPath)
Expand Down Expand Up @@ -134,7 +134,7 @@ 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 }
seq { yield templateFile; if symbols then yield templateFile |> convertToSymbols projectFile includeReferencedProjects }

let convertRemainingTemplate fileName =
let templateFile = TemplateFile.Load(fileName,lockFile,version,specificVersions)
Expand Down Expand Up @@ -180,7 +180,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon
async {
match templateFile with
| CompleteTemplate(core, optional) ->
NupkgWriter.Write core optional (Path.GetDirectoryName templateFile.FileName) packageOutputPath
NupkgWriter.Write core optional (Path.GetDirectoryName (Path.GetDirectoryName templateFile.FileName)) packageOutputPath
|> NuGetV2.fixDatesInArchive
tracefn "Packed: %s" templateFile.FileName
| IncompleteTemplate ->
Expand Down
19 changes: 14 additions & 5 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,18 +1078,27 @@ type ProjectFile =

sprintf "%s.%s" assemblyName (this.OutputType |> function ProjectOutputType.Library -> "dll" | ProjectOutputType.Exe -> "exe")

member this.GetCompileItems () =
let getCompileItem (compileNode : XmlNode) =
member this.GetCompileItems (includeReferencedProjects:bool) =
let getCompileItem (projfile: ProjectFile, compileNode: XmlNode) =
let includePath = compileNode |> getAttribute "Include" |> fun a -> a.Value
let includePath = Path.Combine(Path.GetFileName(Path.GetDirectoryName(projfile.FileName)), includePath)
compileNode
|> getDescendants "Link"
|> function
| [] -> { Include = includePath; Link = None }
| [link] | link::_ -> { Include = includePath; Link = Some link.InnerText }

this.Document
|> getDescendants "Compile"
|> Seq.map getCompileItem

let referencedProjects = if includeReferencedProjects then
let getProjects = this.GetInterProjectDependencies() |> Seq.map (fun proj -> ProjectFile.TryLoad(proj.Path).Value)
seq{yield this; yield! getProjects}
else seq {yield this}

referencedProjects |> Seq.collect(fun proj ->
proj.Document
|> getDescendants "Compile"
|> Seq.map (fun i -> getCompileItem(proj, i))
)

static member LoadFromStream(fullName:string, stream:Stream) =
let doc = new XmlDocument()
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 @@ -465,13 +465,14 @@ type Dependencies(dependenciesFileName: string) =
FindReferences.FindReferencesForPackage (GroupName group) (PackageName package) |> this.Process

// Packs all paket.template files.
member this.Pack(outputPath, ?buildConfig, ?buildPlatform, ?version, ?specificVersions, ?releaseNotes, ?templateFile, ?workingDir, ?excludedTemplates, ?lockDependencies, ?symbols) =
member this.Pack(outputPath, ?buildConfig, ?buildPlatform, ?version, ?specificVersions, ?releaseNotes, ?templateFile, ?workingDir, ?excludedTemplates, ?lockDependencies, ?symbols, ?includeReferencedProjects) =
let dependenciesFile = DependenciesFile.ReadFromFile dependenciesFileName
let specificVersions = defaultArg specificVersions Seq.empty
let workingDir = defaultArg workingDir (dependenciesFile.FileName |> Path.GetDirectoryName)
let lockDependencies = defaultArg lockDependencies false
let symbols = defaultArg symbols false
PackageProcess.Pack(workingDir, dependenciesFile, outputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols)
let includeReferencedProjects = defaultArg includeReferencedProjects false
PackageProcess.Pack(workingDir, dependenciesFile, outputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols, includeReferencedProjects)

/// Pushes a nupkg file.
static member Push(packageFileName, ?url, ?apiKey, (?endPoint: string), ?maxTrials) =
Expand Down
2 changes: 2 additions & 0 deletions src/Paket/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ type PackArgs =
| [<CustomCommandLine("releaseNotes")>] ReleaseNotes of string
| [<CustomCommandLine("lock-dependencies")>] LockDependencies
| [<CustomCommandLine("symbols")>] Symbols
| [<CustomCommandLine("include-referenced-projects")>] IncludeReferencedProjects
with
interface IArgParserTemplate with
member this.Usage =
Expand All @@ -323,6 +324,7 @@ with
| ReleaseNotes(_) -> "Specify relase notes for the package."
| LockDependencies -> "Get the version requirements from paket.lock instead of paket.dependencies."
| Symbols -> "Build symbol/source packages in addition to library/content packages."
| IncludeReferencedProjects -> "Include symbol/source from referenced projects."

type PushArgs =
| [<CustomCommandLine("url")>][<Mandatory>] Url of string
Expand Down
3 changes: 2 additions & 1 deletion src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ let pack (results : ParseResults<_>) =
excludedTemplates = results.GetResults <@ PackArgs.ExcludedTemplate @>,
workingDir = Environment.CurrentDirectory,
lockDependencies = results.Contains <@ PackArgs.LockDependencies @>,
symbols = results.Contains <@ PackArgs.Symbols @>)
symbols = results.Contains <@ PackArgs.Symbols @>,
includeReferencedProjects = results.Contains <@ PackArgs.IncludeReferencedProjects @>)

let findPackages (results : ParseResults<_>) =
let maxResults = defaultArg (results.TryGetResult <@ FindPackagesArgs.MaxResults @>) 10000
Expand Down
24 changes: 20 additions & 4 deletions tests/Paket.Tests/ProjectFile/InterProjectDependencySpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,37 @@ let ``should detect path for dependencies in Project2 proj file``() =
|> List.map (fun p -> p.Path)

paths.[0].EndsWith(normalizePath "src/Paket/Paket.fsproj") |> shouldEqual true
paths.[1].EndsWith(normalizePath "Paket.Core/Paket.Core.fsproj") |> shouldEqual true
paths.[1].EndsWith(normalizePath "src/Paket.Core/Paket.Core.fsproj") |> shouldEqual true

[<Test>]
let ``should detect relative path for dependencies in Project2 proj file``() =
let paths =
ProjectFile.TryLoad("./ProjectFile/TestData/Project2.fsprojtest").Value.GetInterProjectDependencies()
|> List.map (fun p -> p.RelativePath)

paths.[0] |> shouldEqual "..\\..\\src\\Paket\\Paket.fsproj"
paths.[1] |> shouldEqual "..\\Paket.Core\\Paket.Core.fsproj"
paths.[0] |> shouldEqual "..\\..\\..\\..\\src\\Paket\\Paket.fsproj"
paths.[1] |> shouldEqual "..\\..\\..\\..\\src\\Paket.Core\\Paket.Core.fsproj"

[<Test>]
let ``should detect Guids for dependencies in Project2 proj file``() =
let p = ProjectFile.TryLoad("./ProjectFile/TestData/Project2.fsprojtest").Value
p.GetProjectGuid() |> shouldEqual (Guid.Parse "e789c72a-5cfd-436b-8ef1-61aa2852a89f")
p.GetInterProjectDependencies()
|> List.map (fun p -> p.GUID.ToString())
|> shouldEqual ["09b32f18-0c20-4489-8c83-5106d5c04c93"; "7bab0ae2-089f-4761-b138-a717aa2f86c5"]
|> shouldEqual ["09b32f18-0c20-4489-8c83-5106d5c04c93"; "7bab0ae2-089f-4761-b138-a717aa2f86c5"]

[<Test>]
let ``should not add dependencies in referenced projects for GetCompileItems false``() =
let p = ProjectFile.TryLoad("../../ProjectFile/TestData/Project2.fsprojtest").Value
p.GetCompileItems(false)
|> Seq.filter (fun ci -> ci.Include.Contains("Program.fs"))
|> Seq.length
|> shouldEqual 0

[<Test>]
let ``should add dependencies in referenced projects for GetCompileItems true``() =
let p = ProjectFile.TryLoad("../../ProjectFile/TestData/Project2.fsprojtest").Value
p.GetCompileItems(true)
|> Seq.filter (fun ci -> ci.Include.Contains("Program.fs"))
|> Seq.length
|> shouldBeGreaterThan 0
4 changes: 2 additions & 2 deletions tests/Paket.Tests/ProjectFile/TestData/Project2.fsprojtest
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Paket\Paket.fsproj">
<ProjectReference Include="..\..\..\..\src\Paket\Paket.fsproj">
<Name>Paket</Name>
<Project>{09b32f18-0c20-4489-8c83-5106d5c04c93}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\Paket.Core\Paket.Core.fsproj">
<ProjectReference Include="..\..\..\..\src\Paket.Core\Paket.Core.fsproj">
<Name>Paket.Core</Name>
<Project>{7bab0ae2-089f-4761-b138-a717aa2f86c5}</Project>
<Private>True</Private>
Expand Down

0 comments on commit 4d549cc

Please sign in to comment.