Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<configuration>
<packageSources>
<clear />
<add key="dotnet-public" value="https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<disabledPackageSources>
<clear />
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.203",
"version": "8.0.117",
"rollForward": "major"
}
}
2 changes: 1 addition & 1 deletion src/SourceBrowser/src/BinLogParser/BinLogParser.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net472;net9.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
<AssemblyName>BinLogParser</AssemblyName>
<RootNamespace>Microsoft.SourceBrowser.BinLogParser</RootNamespace>
</PropertyGroup>
Expand Down
124 changes: 70 additions & 54 deletions src/SourceBrowser/src/BinLogParser/BinLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void TryGetInvocationFromEvent(object sender, BuildEventArgs args)
}
}

reader.TargetStarted += TryGetInvocationFromEvent;
reader.TargetStarted += TryGetInvocationFromEvent;
reader.MessageRaised += TryGetInvocationFromEvent;

reader.Replay(binLogFilePath);
Expand Down Expand Up @@ -81,40 +81,40 @@ private static List<CompilerInvocation> ExtractInvocationsFromBuild(string logFi
return invocations;
}

private static CompilerInvocation TryGetInvocationFromRecord(BuildEventArgs args, Dictionary<(int, int), CompilerInvocation> taskIdToInvocationMap)
{
int targetId = args.BuildEventContext?.TargetId ?? -1;
int projectId = args.BuildEventContext?.ProjectInstanceId ?? -1;
if (targetId < 0)
{
return null;
}
var targetStarted = args as TargetStartedEventArgs;
if (targetStarted != null && targetStarted.TargetName == "CoreCompile")
{
var invocation = new CompilerInvocation();
taskIdToInvocationMap[(targetId, projectId)] = invocation;
invocation.ProjectFilePath = targetStarted.ProjectFile;
return null;
}
var commandLine = GetCommandLineFromEventArgs(args, out var language);
if (commandLine == null)
{
return null;
}
CompilerInvocation compilerInvocation;
if (taskIdToInvocationMap.TryGetValue((targetId, projectId), out compilerInvocation))
{
compilerInvocation.Language = language == CompilerKind.CSharp ? LanguageNames.CSharp : LanguageNames.VisualBasic;
compilerInvocation.CommandLineArguments = commandLine;
Populate(compilerInvocation);
taskIdToInvocationMap.Remove((targetId, projectId));
}
return compilerInvocation;
private static CompilerInvocation TryGetInvocationFromRecord(BuildEventArgs args, Dictionary<(int, int), CompilerInvocation> taskIdToInvocationMap)
{
int targetId = args.BuildEventContext?.TargetId ?? -1;
int projectId = args.BuildEventContext?.ProjectInstanceId ?? -1;
if (targetId < 0)
{
return null;
}

var targetStarted = args as TargetStartedEventArgs;
if (targetStarted != null && targetStarted.TargetName == "CoreCompile")
{
var invocation = new CompilerInvocation();
taskIdToInvocationMap[(targetId, projectId)] = invocation;
invocation.ProjectFilePath = targetStarted.ProjectFile;
return null;
}

var commandLine = GetCommandLineFromEventArgs(args, out var language);
if (commandLine == null)
{
return null;
}

CompilerInvocation compilerInvocation;
if (taskIdToInvocationMap.TryGetValue((targetId, projectId), out compilerInvocation))
{
compilerInvocation.Language = language == CompilerKind.CSharp ? LanguageNames.CSharp : LanguageNames.VisualBasic;
compilerInvocation.CommandLineArguments = commandLine;
Populate(compilerInvocation);
taskIdToInvocationMap.Remove((targetId, projectId));
}

return compilerInvocation;
}

private static void Populate(CompilerInvocation compilerInvocation)
Expand All @@ -125,25 +125,41 @@ private static void Populate(CompilerInvocation compilerInvocation)
}
}

private static CompilerInvocation TryGetInvocationFromTask(Microsoft.Build.Logging.StructuredLogger.Task task)
{
var name = task.Name;
if (name != "Csc" && name != "Vbc" || ((task.Parent as Microsoft.Build.Logging.StructuredLogger.Target)?.Name != "CoreCompile"))
{
return null;
}

var language = name == "Csc" ? LanguageNames.CSharp : LanguageNames.VisualBasic;
var commandLine = task.CommandLineArguments;
commandLine = TrimCompilerExeFromCommandLine(commandLine, name == "Csc"
? CompilerKind.CSharp
: CompilerKind.VisualBasic);
return new CompilerInvocation
{
Language = language,
CommandLineArguments = commandLine,
ProjectFilePath = task.GetNearestParent<Microsoft.Build.Logging.StructuredLogger.Project>()?.ProjectFile
};
private static CompilerInvocation TryGetInvocationFromTask(Microsoft.Build.Logging.StructuredLogger.Task task)
{
var name = task.Name;
if (name != "Csc" && name != "Vbc" || ((task.Parent as Microsoft.Build.Logging.StructuredLogger.Target)?.Name != "CoreCompile"))
{
return null;
}

var language = name == "Csc" ? LanguageNames.CSharp : LanguageNames.VisualBasic;
var commandLine = task.CommandLineArguments;
commandLine = TrimCompilerExeFromCommandLine(commandLine, name == "Csc"
? CompilerKind.CSharp
: CompilerKind.VisualBasic);

var invocation = new CompilerInvocation
{
Language = language,
CommandLineArguments = commandLine,
ProjectFilePath = task.GetNearestParent<Microsoft.Build.Logging.StructuredLogger.Project>()?.ProjectFile
};

// Capture project properties from the project
var project = task.GetNearestParent<Microsoft.Build.Logging.StructuredLogger.Project>();
if (project != null)
{
project.VisitAllChildren<Microsoft.Build.Logging.StructuredLogger.Property>(prop =>
{
if (!string.IsNullOrEmpty(prop.Name) && !string.IsNullOrEmpty(prop.Value))
{
invocation.ProjectProperties[prop.Name] = prop.Value;
}
});
}

return invocation;
}

public static string TrimCompilerExeFromCommandLine(string commandLine, CompilerKind language)
Expand Down
17 changes: 9 additions & 8 deletions src/SourceBrowser/src/BinLogParser/CompilerInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

namespace Microsoft.SourceBrowser.BinLogParser
{
public class CompilerInvocation
{
public string ProjectFilePath { get; set; }
public string ProjectDirectory => ProjectFilePath == null ? "" : Path.GetDirectoryName(ProjectFilePath);
public string OutputAssemblyPath { get; set; }
public string CommandLineArguments { get; set; }
public string SolutionRoot { get; set; }
public IEnumerable<string> TypeScriptFiles { get; set; }
public class CompilerInvocation
{
public string ProjectFilePath { get; set; }
public string ProjectDirectory => ProjectFilePath == null ? "" : Path.GetDirectoryName(ProjectFilePath);
public string OutputAssemblyPath { get; set; }
public string CommandLineArguments { get; set; }
public string SolutionRoot { get; set; }
public IEnumerable<string> TypeScriptFiles { get; set; }
public Dictionary<string, string> ProjectProperties { get; set; } = new Dictionary<string, string>();

public string AssemblyName => Path.GetFileNameWithoutExtension(OutputAssemblyPath);

Expand Down
11 changes: 6 additions & 5 deletions src/SourceBrowser/src/BinLogToSln/BinLogToSln.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PackAsTool>true</PackAsTool>
<RollForward>Major</RollForward>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<VersionPrefix>1.0.1</VersionPrefix>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LibGit2Sharp" />
<PackageReference Include="Mono.Options" />
<PackageReference Include="System.Reflection.Metadata" />
<ItemGroup>
<PackageReference Include="LibGit2Sharp" />
<PackageReference Include="Mono.Options" />
<PackageReference Include="NuGet.Frameworks" />
<PackageReference Include="System.Reflection.Metadata" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading