Skip to content

Commit

Permalink
Order PDB document table to match compiler arguments (#50615)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkiGibson authored Jan 25, 2021
1 parent 749283b commit ab05661
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ private static void VerifyCompilationOptions(
Compilation compilation,
EmitOptions emitOptions,
BlobReader compilationOptionsBlobReader,
string langVersion)
string langVersion,
int sourceFileCount)
{
var pdbOptions = DeterministicBuildCompilationTestHelpers.ParseCompilationOptions(compilationOptionsBlobReader);

Expand All @@ -43,12 +44,19 @@ private static void VerifyCompilationOptions(
pdbOptions.VerifyPdbOption("unsafe", originalOptions.AllowUnsafe);

Assert.Equal(langVersion, pdbOptions["language-version"]);
Assert.Equal(sourceFileCount.ToString(), pdbOptions["source-file-count"]);

var firstSyntaxTree = (CSharpSyntaxTree)compilation.SyntaxTrees.FirstOrDefault();
pdbOptions.VerifyPdbOption("define", firstSyntaxTree.Options.PreprocessorSymbolNames, isDefault: v => v.IsEmpty(), toString: v => string.Join(",", v));
}

private static void TestDeterministicCompilationCSharp(string langVersion, SyntaxTree[] syntaxTrees, CSharpCompilationOptions compilationOptions, EmitOptions emitOptions, params TestMetadataReferenceInfo[] metadataReferences)
private static void TestDeterministicCompilationCSharp(
string langVersion,
SyntaxTree[] syntaxTrees,
CSharpCompilationOptions compilationOptions,
EmitOptions emitOptions,
TestMetadataReferenceInfo[] metadataReferences,
int? debugDocumentsCount = null)
{
var originalCompilation = CreateCompilation(
syntaxTrees,
Expand All @@ -74,11 +82,12 @@ private static void TestDeterministicCompilationCSharp(string langVersion, Synta
using (var embeddedPdb = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(embedded))
{
var pdbReader = embeddedPdb.GetMetadataReader();

var metadataReferenceReader = DeterministicBuildCompilationTestHelpers.GetSingleBlob(PortableCustomDebugInfoKinds.CompilationMetadataReferences, pdbReader);
var compilationOptionsReader = DeterministicBuildCompilationTestHelpers.GetSingleBlob(PortableCustomDebugInfoKinds.CompilationOptions, pdbReader);

VerifyCompilationOptions(compilationOptions, originalCompilation, emitOptions, compilationOptionsReader, langVersion);
Assert.Equal(debugDocumentsCount ?? syntaxTrees.Length, pdbReader.Documents.Count);

VerifyCompilationOptions(compilationOptions, originalCompilation, emitOptions, compilationOptionsReader, langVersion, syntaxTrees.Length);
DeterministicBuildCompilationTestHelpers.VerifyReferenceInfo(metadataReferences, metadataReferenceReader);
}
}
Expand All @@ -98,17 +107,77 @@ public static void Main()
Console.WriteLine();
}
}
", options: parseOptions, encoding: Encoding.UTF8);
", filename: "a.cs", options: parseOptions, encoding: Encoding.UTF8);

var sourceTwo = Parse(@"
class TypeTwo
{
}", filename: "b.cs", options: parseOptions, encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));

var sourceThree = Parse(@"
class TypeThree
{
}", filename: "c.cs", options: parseOptions, encoding: Encoding.Unicode);

var referenceOneCompilation = CreateCompilation(
@"public struct StructWithReference
{
string PrivateData;
}
public struct StructWithValue
{
int PrivateData;
}", options: TestOptions.DebugDll);

var referenceTwoCompilation = CreateCompilation(
@"public class ReferenceTwo
{
}", options: TestOptions.DebugDll);

using var referenceOne = TestMetadataReferenceInfo.Create(
referenceOneCompilation,
fullPath: "abcd.dll",
emitOptions: emitOptions);

using var referenceTwo = TestMetadataReferenceInfo.Create(
referenceTwoCompilation,
fullPath: "efgh.dll",
emitOptions: emitOptions);

var testSource = new[] { sourceOne, sourceTwo, sourceThree };
TestDeterministicCompilationCSharp(
parseOptions.LanguageVersion.MapSpecifiedToEffectiveVersion().ToDisplayString(),
testSource,
compilationOptions,
emitOptions,
new[] { referenceOne, referenceTwo });
}

[Theory]
[ClassData(typeof(CSharpDeterministicBuildCompilationTests))]
public void PortablePdb_DeterministicCompilation_DuplicateFilePaths(CSharpCompilationOptions compilationOptions, EmitOptions emitOptions, CSharpParseOptions parseOptions)
{
var sourceOne = Parse(@"
using System;
class MainType
{
public static void Main()
{
Console.WriteLine();
}
}
", filename: "a.cs", options: parseOptions, encoding: Encoding.UTF8);

var sourceTwo = Parse(@"
class TypeTwo
{
}", options: parseOptions, encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
}", filename: "b.cs", options: parseOptions, encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));

var sourceThree = Parse(@"
class TypeThree
{
}", options: parseOptions, encoding: Encoding.Unicode);
}", filename: "a.cs", options: parseOptions, encoding: Encoding.Unicode);

var referenceOneCompilation = CreateCompilation(
@"public struct StructWithReference
Expand Down Expand Up @@ -136,7 +205,16 @@ public struct StructWithValue
emitOptions: emitOptions);

var testSource = new[] { sourceOne, sourceTwo, sourceThree };
TestDeterministicCompilationCSharp(parseOptions.LanguageVersion.MapSpecifiedToEffectiveVersion().ToDisplayString(), testSource, compilationOptions, emitOptions, referenceOne, referenceTwo);

// Note that only one debug document can be present for each distinct source path.
// So if more than one syntax tree has the same file path, it won't be possible to do a rebuild from the DLL+PDB.
TestDeterministicCompilationCSharp(
parseOptions.LanguageVersion.MapSpecifiedToEffectiveVersion().ToDisplayString(),
testSource,
compilationOptions,
emitOptions,
new[] { referenceOne, referenceTwo },
debugDocumentsCount: 2);
}

[ConditionalTheory(typeof(DesktopOnly))]
Expand All @@ -153,17 +231,17 @@ public static void Main()
Console.WriteLine();
}
}
", options: parseOptions, encoding: Encoding.UTF8);
", filename: "a.cs", options: parseOptions, encoding: Encoding.UTF8);

var sourceTwo = Parse(@"
class TypeTwo
{
}", options: parseOptions, encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
}", filename: "b.cs", options: parseOptions, encoding: new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));

var sourceThree = Parse(@"
class TypeThree
{
}", options: parseOptions, encoding: Encoding.GetEncoding(932)); // SJIS encoding
}", filename: "c.cs", options: parseOptions, encoding: Encoding.GetEncoding(932)); // SJIS encoding

var referenceOneCompilation = CreateCompilation(
@"public struct StructWithReference
Expand Down Expand Up @@ -191,7 +269,12 @@ public struct StructWithValue
emitOptions: emitOptions);

var testSource = new[] { sourceOne, sourceTwo, sourceThree };
TestDeterministicCompilationCSharp(parseOptions.LanguageVersion.MapSpecifiedToEffectiveVersion().ToDisplayString(), testSource, compilationOptions, emitOptions, referenceOne, referenceTwo);
TestDeterministicCompilationCSharp(
parseOptions.LanguageVersion.MapSpecifiedToEffectiveVersion().ToDisplayString(),
testSource,
compilationOptions,
emitOptions,
new[] { referenceOne, referenceTwo });
}

public IEnumerator<object[]> GetEnumerator() => GetTestParameters().GetEnumerator();
Expand Down
39 changes: 16 additions & 23 deletions src/Compilers/CSharp/Test/Emit/PDB/CheckSumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Immutable;
using System.Text;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
Expand Down Expand Up @@ -193,6 +194,7 @@ class C1
}

[Fact]
[WorkItem(50611, "https://github.com/dotnet/roslyn/issues/50611")]
public void TestPartialClassFieldInitializers()
{
var text1 = WithWindowsLineBreaks(@"
Expand Down Expand Up @@ -232,27 +234,22 @@ static void Main()
compilation.VerifyPdb("C.Main", @"
<symbols>
<files>
<file id=""1"" name=""USED1.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D9"" />
<file id=""2"" name=""USED2.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D9"" />
<file id=""3"" name=""b.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""C0-51-F0-6F-D3-ED-44-A2-11-4D-03-70-89-20-A6-05-11-62-14-BE"" />
<file id=""4"" name=""a.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""F0-C4-23-63-A5-89-B9-29-AF-94-07-85-2F-3A-40-D3-70-14-8F-9B"" />
<file id=""1"" name=""a.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""F0-C4-23-63-A5-89-B9-29-AF-94-07-85-2F-3A-40-D3-70-14-8F-9B"" />
<file id=""2"" name=""b.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""C0-51-F0-6F-D3-ED-44-A2-11-4D-03-70-89-20-A6-05-11-62-14-BE"" />
<file id=""3"" name=""USED1.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D9"" />
<file id=""4"" name=""USED2.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D9"" />
<file id=""5"" name=""UNUSED.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D9"" />
</files>
<methods>
<method containingType=""C"" name=""Main"">
<customDebugInfo>
<using>
<namespace usingCount=""0"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""112"" startColumn=""9"" endLine=""112"" endColumn=""23"" document=""1"" />
<entry offset=""0x6"" startLine=""112"" startColumn=""9"" endLine=""112"" endColumn=""24"" document=""2"" />
<entry offset=""0xc"" startLine=""19"" startColumn=""5"" endLine=""19"" endColumn=""6"" document=""3"" />
<entry offset=""0x0"" startLine=""112"" startColumn=""9"" endLine=""112"" endColumn=""23"" document=""3"" />
<entry offset=""0x6"" startLine=""112"" startColumn=""9"" endLine=""112"" endColumn=""24"" document=""4"" />
<entry offset=""0xc"" startLine=""19"" startColumn=""5"" endLine=""19"" endColumn=""6"" document=""2"" />
</sequencePoints>
</method>
</methods>
</symbols>");
</symbols>", format: DebugInformationFormat.PortablePdb);
}

[WorkItem(729235, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/729235")]
Expand Down Expand Up @@ -292,6 +289,7 @@ void M()
}

[ConditionalFact(typeof(WindowsOnly))]
[WorkItem(50611, "https://github.com/dotnet/roslyn/issues/50611")]
public void NoResolver()
{
var comp = CSharpCompilation.Create(
Expand All @@ -309,23 +307,18 @@ class C { void M() { } }
comp.VerifyPdb(@"
<symbols>
<files>
<file id=""1"" name=""a\..\a.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D5"" />
<file id=""2"" name=""C:\a\..\b.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""36-39-3C-83-56-97-F2-F0-60-95-A4-A0-32-C6-32-C7-B2-4B-16-92"" />
<file id=""1"" name=""C:\a\..\b.cs"" language=""C#"" checksumAlgorithm=""SHA1"" checksum=""36-39-3C-83-56-97-F2-F0-60-95-A4-A0-32-C6-32-C7-B2-4B-16-92"" />
<file id=""2"" name=""a\..\a.cs"" language=""C#"" checksumAlgorithm=""406ea660-64cf-4c82-b6f0-42d48172a799"" checksum=""AB-00-7F-1D-23-D5"" />
</files>
<methods>
<method containingType=""C"" name=""M"">
<customDebugInfo>
<using>
<namespace usingCount=""0"" />
</using>
</customDebugInfo>
<sequencePoints>
<entry offset=""0x0"" startLine=""10"" startColumn=""20"" endLine=""10"" endColumn=""21"" document=""1"" />
<entry offset=""0x1"" startLine=""10"" startColumn=""22"" endLine=""10"" endColumn=""23"" document=""1"" />
<entry offset=""0x0"" startLine=""10"" startColumn=""20"" endLine=""10"" endColumn=""21"" document=""2"" />
<entry offset=""0x1"" startLine=""10"" startColumn=""22"" endLine=""10"" endColumn=""23"" document=""2"" />
</sequencePoints>
</method>
</methods>
</symbols>");
</symbols>", format: DebugInformationFormat.PortablePdb);
}

[WorkItem(729235, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/729235")]
Expand Down
Loading

0 comments on commit ab05661

Please sign in to comment.