From e248d6b86627d904be0fd81bec4d95a5b8d6534e Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Sat, 4 May 2024 07:40:20 -0700 Subject: [PATCH] Get generated files binary log closes #125 --- .../BinaryLogReaderTests.cs | 13 +++++++++++++ src/Basic.CompilerLog.Util/BinaryLogReader.cs | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Basic.CompilerLog.UnitTests/BinaryLogReaderTests.cs b/src/Basic.CompilerLog.UnitTests/BinaryLogReaderTests.cs index 677e847..a9a5b0b 100644 --- a/src/Basic.CompilerLog.UnitTests/BinaryLogReaderTests.cs +++ b/src/Basic.CompilerLog.UnitTests/BinaryLogReaderTests.cs @@ -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(() => 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 _)); } } diff --git a/src/Basic.CompilerLog.Util/BinaryLogReader.cs b/src/Basic.CompilerLog.Util/BinaryLogReader.cs index b40a1ce..9fa0e2c 100644 --- a/src/Basic.CompilerLog.Util/BinaryLogReader.cs +++ b/src/Basic.CompilerLog.Util/BinaryLogReader.cs @@ -305,6 +305,20 @@ public List ReadAllReferenceData(CompilerCall compilerCall) return ReadAllReferenceDataCore(args.MetadataReferences.Select(x => x.Reference), args.MetadataReferences.Length); } + /// + /// Attempt to add all the generated files from generators. When successful the generators + /// don't need to be run when re-hydrating the compilation. + /// + /// + /// This method will throw if the compilation does not have a PDB compatible with generated files + /// available to read + /// + public List<(string FilePath, MemoryStream Stream)> ReadGeneratedFiles(CompilerCall compilerCall) + { + var args = ReadCommandLineArguments(compilerCall); + return RoslynUtil.ReadGeneratedFiles(compilerCall, args); + } + private List ReadAllReferenceDataCore(IEnumerable filePaths, int count) { var list = new List(capacity: count);