Permalink
Browse files

add support for embedded pdb files #151 (#152)

* add support for embedded pdb files #151

* dogfood

* turn on normal verbosity to see the sourelink task output

* #153 log the directory it is looking in

* toggle off source linking

* xml is hard

* test works

* try b381

* and do sourcelink

* try printing origin

* b384

* b385

* run origin

* build sourcelink-get again

* b388

* git remove -v

* test with passing dir

* remove if (repo.Head.IsTracking)

* try b392

* ship it

* Embedded preferred

* embedded
  • Loading branch information...
ctaggart committed Mar 1, 2017
1 parent 4640db5 commit b1c5b6abedd67b4609f8577c36c142cb1286bec9
@@ -26,7 +26,7 @@ Install by adding this `DotNetCliToolReference` to the project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<DebugType>Portable</DebugType>
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.0.0-*" />
@@ -39,10 +39,11 @@ public override bool Execute()
if (string.IsNullOrEmpty(url))
{
var originCmd = Process.RunAndGetOutput("dotnet", "sourcelink-git origin" + gitOption);
var originArgs = "sourcelink-git origin" + gitOption;
var originCmd = Process.RunAndGetOutput("dotnet", originArgs);
if (originCmd.ExitCode != 0 || originCmd.OutputLines.Count != 1)
{
Log.LogMessage(MessageImportance.High, "unable to get repository origin");
Log.LogMessage(MessageImportance.High, "unable to find repository origin with: dotnet " + originArgs);
return false;
}
var origin = originCmd.OutputLines[0];
@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<DebugType>embedded</DebugType>
<!-- https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target -->
<IncludeBuildOutput>false</IncludeBuildOutput>
@@ -34,10 +35,7 @@
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="$(OutputPath)SourceLink.Create.GitHub.pdb">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
</ItemGroup>
<!--<Import Project="$(MSBuildThisFileDirectory)../SourceLink.props" />-->
</Project>
@@ -5,7 +5,7 @@
<PropertyGroup>
<!-- enable only in CI environments by default -->
<SourceLinkCreate Condition="'$(SourceLinkCreate)' == ''">$(CI)</SourceLinkCreate>
<CompileDependsOn Condition="'$(SourceLinkCreate)' == 'true' and $(DebugType) == 'portable'">SourceLinkCreate;$(CompileDependsOn)</CompileDependsOn>
<CompileDependsOn Condition="'$(SourceLinkCreate)' == 'true' and ($(DebugType) == 'portable' or $(DebugType) == 'embedded')">SourceLinkCreate;$(CompileDependsOn)</CompileDependsOn>
<SourceLinkRepo Condition="'$(SourceLinkRepo)' == ''">$(MSBuildProjectDirectory)</SourceLinkRepo>
<SourceLinkFile Condition="'$(SourceLinkFile)' == ''">$(SourceLink)</SourceLinkFile>
<SourceLinkFile Condition="'$(SourceLinkFile)' == ''">$(BaseIntermediateOutputPath)sourcelink.json</SourceLinkFile>
@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<DebugType>embedded</DebugType>
<!-- https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target -->
<IncludeBuildOutput>false</IncludeBuildOutput>
@@ -34,13 +35,10 @@
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
<Content Include="$(OutputPath)SourceLink.Test.pdb">
<Pack>true</Pack>
<PackagePath>build</PackagePath>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="..\SourceLink.Create.GitHub\Process.cs" Link="Process.cs" />
</ItemGroup>
<!--<Import Project="$(MSBuildThisFileDirectory)../SourceLink.props" />-->
</Project>
@@ -5,9 +5,10 @@
<PropertyGroup>
<!-- enable only in CI environments by default -->
<SourceLinkTest Condition="'$(SourceLinkTest)' == ''">$(CI)</SourceLinkTest>
<CompileDependsOn Condition="'$(SourceLinkTest)' == 'true' and $(DebugType) == 'portable'">$(CompileDependsOn);SourceLinkTest</CompileDependsOn>
<CompileDependsOn Condition="'$(SourceLinkTest)' == 'true' and ($(DebugType) == 'portable' or $(DebugType) == 'embedded')">$(CompileDependsOn);SourceLinkTest</CompileDependsOn>
<SourceLinkPdb Condition="'$(SourceLinkPdb)' == ''">$(PdbFile)</SourceLinkPdb>
<SourceLinkPdb Condition="'$(SourceLinkPdb)' == ''">$(IntermediateOutputPath)$(TargetName).pdb</SourceLinkPdb>
<SourceLinkPdb Condition="'$(SourceLinkPdb)' == '' and $(DebugType) == 'portable'">$(IntermediateOutputPath)$(TargetName).pdb</SourceLinkPdb>
<SourceLinkPdb Condition="'$(SourceLinkPdb)' == '' and $(DebugType) == 'embedded'">$(IntermediateOutputPath)$(TargetName).dll</SourceLinkPdb>
</PropertyGroup>
<Target Name="SourceLinkTest">
@@ -0,0 +1,12 @@
<Project>
<PropertyGroup>
<SourceLinkCreate>true</SourceLinkCreate>
<SourceLinkTest>true</SourceLinkTest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SourceLink.Create.GitHub" Version="[2.0.0-b393]" PrivateAssets="all" />
<PackageReference Include="SourceLink.Test" Version="[2.0.0-b393]" PrivateAssets="all" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="[2.0.0-b393]" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="[2.0.0-b393]" />
</ItemGroup>
</Project>

This file was deleted.

Oops, something went wrong.
@@ -1,5 +1,5 @@
$version = '2.0.0' # the version under development, update after a release
$versionSuffix = '-a088' # manually incremented for local builds
$versionSuffix = '-a094' # manually incremented for local builds
function isVersionTag($tag){
$v = New-Object Version
@@ -15,7 +15,7 @@ if ($env:appveyor){
Update-AppveyorBuild -Version "$version$versionSuffix"
}
$pack = "pack", "-c", "release", "--include-symbols", "-o", "../bin", "/p:Version=$version$versionSuffix"
$pack = "pack", "-c", "release", "-o", "../bin", "/p:Version=$version$versionSuffix", "/v:n"
Set-Location $psscriptroot\dotnet-sourcelink
dotnet restore
@@ -35,7 +35,6 @@ dotnet restore
dotnet $pack
Set-Location $psscriptroot
bash .\build-rename.sh
# testing on local nuget feed
if (-not $env:appveyor){
@@ -47,7 +47,7 @@ public static void PrintRepo(CommandLineApplication command)
command.OnExecute(() =>
{
var dir = "./";
var dir = ".";
if (dirOption.HasValue())
dir = dirOption.Value();
@@ -71,7 +71,7 @@ public static void PrintOrigin(CommandLineApplication command)
command.OnExecute(() =>
{
var dir = "./";
var dir = ".";
if (dirOption.HasValue())
dir = dirOption.Value();
@@ -125,7 +125,7 @@ public static void Create(CommandLineApplication command)
var embedFiles = new List<SourceFile>();
var errors = 0;
var dir = "./";
var dir = ".";
if (dirOption.HasValue())
dir = dirOption.Value();
@@ -356,7 +356,9 @@ public static string FindGitRepo(string dir)
foreach(var d in GetDirectoryNames(dir))
{
if (Repository.IsValid(d))
{
return d;
}
}
return null;
}
@@ -365,14 +367,11 @@ public static string GetOrigin(string repoPath)
{
using (var repo = new Repository(repoPath))
{
if (repo.Head.IsTracking)
foreach (var r in repo.Network.Remotes)
{
foreach (var r in repo.Network.Remotes)
if (r.Name == "origin")
{
if (r.Name == "origin")
{
return r.Url;
}
return r.Url;
}
}
}
@@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<DebugType>embedded</DebugType>
<PackageType>DotnetCliTool</PackageType>
<Authors>Cameron Taggart</Authors>
@@ -24,4 +25,5 @@
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>
<Import Project="$(MSBuildThisFileDirectory)../SourceLink.props" />
</Project>
@@ -10,6 +10,7 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Reflection.PortableExecutable;
namespace SourceLink {
public class Program
@@ -233,11 +234,31 @@ public static void Test(CommandLineApplication command)
public static readonly Guid SourceLinkId = new Guid("CC110556-A091-4D38-9FEC-25AB9A351A6A");
public static byte[] GetSourceLinkBytes(string pdb)
public static MetadataReader GetMetaDataReader(string path, Stream stream)
{
using (var mrp = MetadataReaderProvider.FromPortablePdbStream(File.OpenRead(pdb)))
if (path.EndsWith(".dll"))
{
var mr = mrp.GetMetadataReader();
var reader = new PEReader(stream);
if (reader.HasMetadata)
{
// https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/tests/PortableExecutable/PEReaderTests.cs#L392
var embeddedProvider = reader.ReadEmbeddedPortablePdbDebugDirectoryData(reader.ReadDebugDirectory()[2]);
return embeddedProvider.GetMetadataReader();
}
}
else
{
var mrp = MetadataReaderProvider.FromPortablePdbStream(stream);
return mrp.GetMetadataReader();
}
return null;
}
public static byte[] GetSourceLinkBytes(string path)
{
using (var file = File.OpenRead(path))
{
var mr = GetMetaDataReader(path, file);
var blobh = default(BlobHandle);
foreach (var cdih in mr.GetCustomDebugInformation(EntityHandle.ModuleDefinition))
{
@@ -263,11 +284,11 @@ public static bool IsEmbedded(MetadataReader mr, DocumentHandle dh)
return false;
}
public static IEnumerable<Document> GetDocuments(string pdb)
public static IEnumerable<Document> GetDocuments(string path)
{
using (var mrp = MetadataReaderProvider.FromPortablePdbStream(File.OpenRead(pdb)))
using (var file = File.OpenRead(path))
{
var mr = mrp.GetMetadataReader();
var mr = GetMetaDataReader(path, file);
foreach (var dh in mr.Documents)
{
var d = mr.GetDocument(dh);
@@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<DebugType>embedded</DebugType>
<PackageType>DotnetCliTool</PackageType>
<Authors>Cameron Taggart</Authors>
@@ -20,4 +21,5 @@
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="System.Reflection.Metadata" Version="1.4.2" />
</ItemGroup>
<Import Project="$(MSBuildThisFileDirectory)../SourceLink.props" />
</Project>

0 comments on commit b1c5b6a

Please sign in to comment.