Skip to content

Commit

Permalink
Get generated files binary log
Browse files Browse the repository at this point in the history
closes #125
  • Loading branch information
jaredpar committed May 4, 2024
1 parent a6d2007 commit e248d6b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Basic.CompilerLog.UnitTests/BinaryLogReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,18 @@ public void ReadDeletedPdb()
var data = reader.ReadAllCompilationData().Single();
var diagnostic = data.GetDiagnostics().Where(x => x.Severity == DiagnosticSeverity.Error).Single();
Assert.Contains("Can't find portable pdb file for", diagnostic.GetMessage());

Assert.Throws<InvalidOperationException>(() => reader.ReadGeneratedFiles(data.CompilerCall));
}

[Fact]
public void ReadGeneratedFiles()
{
using var reader = BinaryLogReader.Create(Fixture.Console.Value.BinaryLogPath!, BasicAnalyzerKind.None);
var compilerCall = reader.ReadAllCompilerCalls().Single();
var generatedFiles = reader.ReadGeneratedFiles(compilerCall);
Assert.Single(generatedFiles);
var tuple = generatedFiles.Single();
Assert.True(tuple.Stream.TryGetBuffer(out var _));
}
}
14 changes: 14 additions & 0 deletions src/Basic.CompilerLog.Util/BinaryLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ public List<ReferenceData> ReadAllReferenceData(CompilerCall compilerCall)
return ReadAllReferenceDataCore(args.MetadataReferences.Select(x => x.Reference), args.MetadataReferences.Length);
}

/// <summary>
/// Attempt to add all the generated files from generators. When successful the generators
/// don't need to be run when re-hydrating the compilation.
/// </summary>
/// <remarks>
/// This method will throw if the compilation does not have a PDB compatible with generated files
/// available to read
/// </remarks>
public List<(string FilePath, MemoryStream Stream)> ReadGeneratedFiles(CompilerCall compilerCall)
{
var args = ReadCommandLineArguments(compilerCall);
return RoslynUtil.ReadGeneratedFiles(compilerCall, args);
}

private List<ReferenceData> ReadAllReferenceDataCore(IEnumerable<string> filePaths, int count)
{
var list = new List<ReferenceData>(capacity: count);
Expand Down

0 comments on commit e248d6b

Please sign in to comment.