Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation name from binlog #188

Merged
merged 1 commit into from
Dec 6, 2024
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
11 changes: 8 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/artifacts/bin/Basic.CompilerLog/debug_net8.0/Basic.CompilerLog.dll",
"args": ["export", "C:\\Users\\jaredpar\\Downloads\\Build1.complog"],
"cwd": "C:\\Users\\jaredpar\\Downloads",
"program": "${workspaceFolder}/artifacts/bin/Basic.CompilerLog/debug_net9.0/Basic.CompilerLog.dll",
"args": [
"replay",
"/home/jaredpar/code/msbuild/artifacts/log/Debug/Build.binlog",
"-p",
"StringTools.UnitTests.csproj",
"-n"],
"cwd": "/home/jaredpar/code/msbuild/artifacts/log/Debug",
// "cwd": "${workspaceFolder}/src/Basic.CompilerLog",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
Expand Down
16 changes: 16 additions & 0 deletions src/Basic.CompilerLog.UnitTests/CompilerLogReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ public void KeyFileCustomState()
Assert.False(File.Exists(data.CompilationOptions.CryptoKeyFile));
}

[Fact]
public void KeyFileAssemblyName()
{
Go(Fixture.ConsoleComplex.Value.BinaryLogPath!);
Go(Fixture.ConsoleComplex.Value.CompilerLogPath);

void Go(string filePath)
{
using var reader = CompilerCallReaderUtil.Create(filePath, BasicAnalyzerKind.None);
var compilerCall = reader.ReadCompilerCall(0);
var data = reader.ReadCompilationData(compilerCall);
var compilation = data.GetCompilationAfterGenerators();
Assert.Equal("console-complex", compilation.AssemblyName);
}
}

[Fact]
public void AdditionalFiles()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Basic.CompilerLog.Util/BinaryLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ public CompilerCallData ReadCompilerCallData(CompilerCall compilerCall) =>
{
var args = ReadCommandLineArguments(compilerCall);
var assemblyFileName = RoslynUtil.GetAssemblyFileName(args);
var compilationName = Path.GetFileNameWithoutExtension(assemblyFileName);
var data = new CompilerCallData(
compilerCall,
assemblyFileName,
compilationName,
args.OutputDirectory,
args.ParseOptions,
args.CompilationOptions,
Expand Down
3 changes: 1 addition & 2 deletions src/Basic.CompilerLog/FilterOptionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ internal FilterOptionSet(bool analyzers = false)
Add("all", "include all compilation kinds", i => { if (i is not null) IncludeAllKinds = true; });
Add("f|framework=", "include only compilations for the target framework (allows multiple)", TargetFrameworks.Add);
Add("p|project=", "include only compilations for the given project (allows multiple)", ProjectNames.Add);
Add("n|projectName=", "include only compilations for the project", ProjectNames.Add, hidden: true);
Add("h|help", "print help", h => { if (h != null) Help = true; });

if (analyzers)
{
_hasAnalyzerOptions = true;
_basicAnalyzerKind = BasicAnalyzerHost.DefaultKind;
Add("a|analyzers=", "analyzer load strategy: none, ondisk, inmemory", void (BasicAnalyzerKind k) => _basicAnalyzerKind = k);
Add("none", "Do not run analyzers", i => { if (i is not null) _basicAnalyzerKind = BasicAnalyzerKind.None; }, hidden: true);
Add("n|none", "Do not run analyzers", i => { if (i is not null) _basicAnalyzerKind = BasicAnalyzerKind.None; }, hidden: true);
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/Scratch/Scratch.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.IO.Pipelines;
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
Expand All @@ -24,8 +25,14 @@

#pragma warning disable 8321

var temp = CompilerLogUtil.GetOrCreateCompilerLogStream(@"C:\Users\jaredpar\code\roslyn\src\Compilers\Core\Portable\msbuild.binlog");

using var reader = CompilerCallReaderUtil.Create("/home/jaredpar/code/msbuild/artifacts/log/Debug/Build.binlog", BasicAnalyzerKind.None);
var compilerCall = reader
.ReadAllCompilerCalls()
.Single(x => x.ProjectFileName == "StringTools.UnitTests.csproj");
var data = reader.ReadCompilationData(compilerCall);
var compilation = data.GetCompilationAfterGenerators();
Console.WriteLine(compilation.AssemblyName);
var diagnostics = compilation.GetDiagnostics();

Bing();
void Bing()
Expand Down
Loading