Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Basic.CompilerLog.UnitTests/CompilationDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Basic.CompilerLog.Util;
using Basic.CompilerLog.Util.Impl;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.Testing.Platform.Extensions.Messages;
using Xunit;

Expand Down Expand Up @@ -82,6 +83,28 @@ public void EmitToMemoryCombinations()
});
}

/// <summary>
/// Covers <see href="https://github.com/dotnet/roslyn/issues/78721"/> while the fix in
/// <see href="https://github.com/dotnet/roslyn/pull/85028"/> is not yet available in our Roslyn package.
/// </summary>
[Fact]
public void EmitToMemoryMetadataOnlyWithPdbPath()
{
RunInContext(Fixture.ClassLib.Value.CompilerLogPath, static (testOutputHelper, filePath, cancellationToken) =>
{
using var reader = CompilerLogReader.Create(filePath);
var data = reader.ReadCompilationData(0);
var emitOptions = data.EmitOptions
.WithEmitMetadataOnly(true)
.WithDebugInformationFormat(DebugInformationFormat.Embedded)
.WithPdbFilePath("test.pdb");

var exception = Assert.Throws<ArgumentException>(
() => data.EmitToMemory(EmitFlags.MetadataOnly, emitOptions, cancellationToken));
Assert.Equal("metadataPEStream", exception.ParamName);
});
}

[Fact]
public void EmitToMemoryRefOnly()
{
Expand Down
20 changes: 20 additions & 0 deletions src/Basic.CompilerLog.Util/CompilerLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ public IReadOnlyCollection<string> ReadArguments(CompilerCall compilerCall)
CompilationDataPack dataPack)
{
var emitOptions = MessagePackUtil.CreateEmitOptions(GetContentPack<EmitOptionsPack>(pack.EmitOptionsHash));
emitOptions = ApplyMetadataOnlyEmitWorkaround(emitOptions);
ParseOptions parseOptions;
CompilationOptions compilationOptions;
if (pack.IsCSharp)
Expand All @@ -396,6 +397,25 @@ public IReadOnlyCollection<string> ReadArguments(CompilerCall compilerCall)
compilationOptions = MaterializeCryptoKeyFile(dataPack, compilationOptions);
return (emitOptions, parseOptions, compilationOptions);

EmitOptions ApplyMetadataOnlyEmitWorkaround(EmitOptions emitOptions)
{
// Metadata-only output cannot have an associated PDB. Current Roslyn can retain the PDB path,
// emit a CodeView entry, or reject embedded debug information. Work around dotnet/roslyn#85028
// until a Roslyn package containing the fix is available.
if (!emitOptions.EmitMetadataOnly)
{
return emitOptions;
}

emitOptions = emitOptions.WithPdbFilePath(null!);
if (emitOptions.DebugInformationFormat == DebugInformationFormat.Embedded)
{
emitOptions = emitOptions.WithDebugInformationFormat(DebugInformationFormat.PortablePdb);
}

return emitOptions;
}

// This method will materialize the crypto key file to the location specified by the path mapping util. This
// is the rare case where reading compilation information will cause a file to be written to disk. It's the
// rare case where the compiler reads directly from disk at binding vs. pre-reading at Compilation creation
Expand Down
Loading