Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpar committed Jun 7, 2024
1 parent 56e2b11 commit 15e82d5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Basic.CompilerLog.UnitTests/BinaryLogUtilTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void ParseCompilerAndArgumentsCsc(string inputArgs, string? expectedCompi
}

[WindowsTheory]
[InlineData(@" C:\Program Files\dotnet\dotnet.exe exec ""C:\Program Files\dotnet\sdk\8.0.301\Roslyn\bincore\csc.dll"" a.cs", @"C:\Program Files\dotnet\sdk\8.0.301\Roslyn\bincore\csc.dll", "a.cs")]
[InlineData(@"C:\Program Files\dotnet\dotnet.exe exec ""C:\Program Files\dotnet\sdk\8.0.301\Roslyn\bincore\csc.dll"" a.cs", @"C:\Program Files\dotnet\sdk\8.0.301\Roslyn\bincore\csc.dll", "a.cs")]
[InlineData(@"""C:\Program Files\dotnet\dotnet.exe"" exec ""C:\Program Files\dotnet\sdk\8.0.301\Roslyn\bincore\csc.dll"" a.cs", @"C:\Program Files\dotnet\sdk\8.0.301\Roslyn\bincore\csc.dll", "a.cs")]
[InlineData(@"'C:\Program Files\dotnet\dotnet.exe' exec ""C:\Program Files\dotnet\sdk\8.0.301\Roslyn\bincore\csc.dll"" a.cs", @"C:\Program Files\dotnet\sdk\8.0.301\Roslyn\bincore\csc.dll", "a.cs")]
Expand Down Expand Up @@ -74,10 +75,20 @@ public void ParseCompilerAndArgumentsVbc(string inputArgs, string? expectedCompi
[InlineData("dotnet not what we expect a.cs")]
[InlineData("dotnet csc2 what we expect a.cs")]
[InlineData("dotnet exec vbc.dll what we expect a.cs")]
[InlineData("empty")]
[InlineData(" ")]
public void ParseCompilerAndArgumentsBad(string inputArgs)
{
Assert.Throws<InvalidOperationException>(() => BinaryLogUtil.ParseTaskForCompilerAndArguments(inputArgs, "csc.exe", "csc.dll"));
}

[Fact]
public void ParseCompilerAndArgumentsNull()
{
var (actualCompilerFilePath, actualArgs) = BinaryLogUtil.ParseTaskForCompilerAndArguments(null, "csc.exe", "csc.dll");
Assert.Null(actualCompilerFilePath);
Assert.Empty(actualArgs);
}
}

public sealed class MSBuildProjectDataTests
Expand Down
1 change: 1 addition & 0 deletions src/Basic.CompilerLog.Util/CompilerAssemblyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public sealed class CompilerAssemblyData(string filePath, AssemblyName assemblyN
public AssemblyName AssemblyName { get; } = assemblyName;
public string? CommitHash { get; } = commitHash;

[ExcludeFromCodeCoverage]
public override string ToString() => $"{FilePath} {CommitHash}";
}

59 changes: 57 additions & 2 deletions src/Scratch/Scratch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using Basic.CompilerLog;
using Basic.CompilerLog.Util;
using BenchmarkDotNet.Environments;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging.StructuredLogger;

//using Microsoft.Build.Logging.StructuredLogger;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Classification;
Expand Down Expand Up @@ -42,7 +45,8 @@

// Profile();

ReadAttribute();
DarkArtOfBuild();
// ReadAttribute();
// ExportScratch();
// await WorkspaceScratch();
// RoslynScratch();
Expand Down Expand Up @@ -93,6 +97,56 @@
}
*/

void DarkArtOfBuild()
{
var filePath = @"c:\users\jaredpar\temp\console\msbuild.binlog";
const string targetProjectFile = @"C:\Users\jaredpar\temp\console\console.csproj";
using var stream = File.OpenRead(filePath);
var records = BinaryLog.ReadRecords(stream);
foreach (var record in records)
{
if (record.Args is not { BuildEventContext: { } context })
{
continue;
}

var suffix = $"eval: {context.EvaluationId}, context: {context.ProjectContextId}, instance: {context.ProjectInstanceId}";

switch (record.Args)
{
case ProjectStartedEventArgs { ProjectFile: targetProjectFile } e:
{
Console.WriteLine($"ProjectStarted: {suffix}");
break;
}
case ProjectFinishedEventArgs {ProjectFile: targetProjectFile } e:
{
Console.WriteLine($"ProjectFinished: {suffix}");
break;
}
case ProjectEvaluationStartedEventArgs { ProjectFile: targetProjectFile } e:
{
Console.WriteLine($"EvaluationStarted: {suffix}");
break;
}
case ProjectEvaluationFinishedEventArgs { ProjectFile: targetProjectFile } e:
{
Console.WriteLine($"EvaluationFinished: {suffix}");
break;
}
case TaskStartedEventArgs { ProjectFile: targetProjectFile } e:
{
if ((e.TaskName == "Csc" || e.TaskName == "Vbc"))
{
Console.WriteLine($"CompileStarted: {suffix}");
}
break;
}
}
}

}

void ReadAttribute()
{
var assemblyPath = @"c:\Program Files\dotnet\sdk\8.0.204\Roslyn\bincore\csc.dll";
Expand Down Expand Up @@ -183,7 +237,7 @@ static void PrintGeneratedFiles()
}
}

static async Task WorkspaceScratch()
/*static async Task WorkspaceScratch()
{
var filePath = @"/mnt/c/Users/jaredpar/temp/console/msbuild.complog";
using var reader = SolutionReader.Create(filePath, BasicAnalyzerKind.None);
Expand All @@ -199,6 +253,7 @@ static async Task WorkspaceScratch()
}
}
}
*/

static void ExportScratch()
{
Expand Down

0 comments on commit 15e82d5

Please sign in to comment.