Skip to content

Commit

Permalink
Add support for indexing .binlog files.
Browse files Browse the repository at this point in the history
Similar to .sln files, Csc invocations are extracted from the .binlog.
  • Loading branch information
KirillOsenkov committed Apr 18, 2020
1 parent 3e03563 commit b79ff9c
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 18 deletions.
5 changes: 3 additions & 2 deletions RunTestSite.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cd src\HtmlGenerator\bin\Debug\net472\Web\Index
dotnet Microsoft.SourceBrowser.SourceIndexServer.dll
pushd src\HtmlGenerator\bin\Debug\net472\Web\Index
dotnet Microsoft.SourceBrowser.SourceIndexServer.dll
popd
10 changes: 9 additions & 1 deletion src/Common/AssemblyNameExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ public static IEnumerable<string> GetAssemblyNames(string projectOrSolutionFileP
return null;
}

if (projectOrSolutionFilePath.EndsWith(".sln"))
if (projectOrSolutionFilePath.EndsWith(".sln", System.StringComparison.OrdinalIgnoreCase))
{
return GetAssemblyNamesFromSolution(projectOrSolutionFilePath);
}
else if (projectOrSolutionFilePath.EndsWith(".dll", System.StringComparison.OrdinalIgnoreCase) ||
projectOrSolutionFilePath.EndsWith(".exe", System.StringComparison.OrdinalIgnoreCase))
{
return new[]
{
Path.GetFileNameWithoutExtension(projectOrSolutionFilePath)
};
}
else
{
return new[] { GetAssemblyNameFromProject(projectOrSolutionFilePath) };
Expand Down
1 change: 1 addition & 0 deletions src/HtmlGenerator/HtmlGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Features" Version="$(NuGetVersionRoslyn)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="$(NuGetVersionRoslyn)" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="$(NuGetVersionRoslyn)" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.0.174" />
<PackageReference Include="GuiLabs.Language.Xml" Version="1.2.46" />
<PackageReference Include="Microsoft.VisualStudio.Language.Intellisense" Version="16.4.280" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
Expand Down
67 changes: 60 additions & 7 deletions src/HtmlGenerator/Pass1-Generation/GenerateFromBuildLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.VisualBasic;
using Microsoft.SourceBrowser.BuildLogParser;
using Microsoft.SourceBrowser.Common;

Expand Down Expand Up @@ -40,7 +44,11 @@ public static void IndexLogFile(string logFile, string serverPath = null, string
}
}

public static void GenerateInvocation(CompilerInvocation invocation)
public static void GenerateInvocation(CompilerInvocation invocation,
IReadOnlyDictionary<string, string> serverPathMappings = null,
HashSet<string> processedAssemblyList = null,
HashSet<string> assemblyNames = null,
Folder<ProjectSkeleton> solutionExplorerRoot = null)
{
try
{
Expand All @@ -61,7 +69,9 @@ public static void GenerateInvocation(CompilerInvocation invocation)
Paths.SolutionDestinationFolder,
invocation.ServerPath,
invocation.NetworkShare);
solutionGenerator.Generate();
solutionGenerator.ServerPathMappings = serverPathMappings;
solutionGenerator.GlobalAssemblyList = assemblyNames;
solutionGenerator.Generate(processedAssemblyList, solutionExplorerRoot);
}
else
{
Expand Down Expand Up @@ -118,6 +128,7 @@ private static IEnumerable<CompilerInvocation> GetInvocationsToProcess()
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 ServerPath { get; set; }
Expand All @@ -133,22 +144,64 @@ public string AssemblyName
}
}

private string language;
public string Language
{
get
{
if (ProjectFilePath == null && TypeScriptFiles != null)
if (language == null)
{
return "TypeScript";
if (ProjectFilePath == null && TypeScriptFiles != null)
{
language = "TypeScript";
}
else if (".vbproj".Equals(Path.GetExtension(ProjectFilePath), StringComparison.OrdinalIgnoreCase))
{
language = "Visual Basic";
}
else
{
language = "C#";
}
}
else if (".vbproj".Equals(Path.GetExtension(ProjectFilePath), StringComparison.OrdinalIgnoreCase))

return language;
}

set
{
language = value;
}
}

private string[] GetCommandLineArguments()
{
return CommandLineParser.SplitCommandLineIntoArguments(CommandLineArguments, removeHashComments: false).ToArray();
}

private CommandLineArguments parsed;
public CommandLineArguments Parsed
{
get
{
if (parsed != null)
{
return "Visual Basic";
return parsed;
}

var sdkDirectory = RuntimeEnvironment.GetRuntimeDirectory();
var args = GetCommandLineArguments();

if (Language == LanguageNames.CSharp)
{
parsed = CSharpCommandLineParser.Default.Parse(args, ProjectDirectory, sdkDirectory);
}
else
{
return "C#";
parsed = VisualBasicCommandLineParser.Default.Parse(args, ProjectDirectory, sdkDirectory);
}

return parsed;
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/HtmlGenerator/Pass1-Generation/ProjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ public async Task Generate()

Log.Write(ProjectDestinationFolder, ConsoleColor.DarkCyan);

ProjectSourcePath = Paths.MakeRelativeToFolder(ProjectFilePath, SolutionGenerator.SolutionSourceFolder);
if (SolutionGenerator.SolutionSourceFolder is string solutionFolder)
{
ProjectSourcePath = Paths.MakeRelativeToFolder(ProjectFilePath, solutionFolder);
}
else
{
ProjectSourcePath = ProjectFilePath;
}

if (File.Exists(Path.Combine(ProjectDestinationFolder, Constants.DeclaredSymbolsFileName + ".txt")))
{
Expand Down
2 changes: 1 addition & 1 deletion src/HtmlGenerator/Pass1-Generation/SolutionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class SolutionGenerator : IDisposable
public string SolutionDestinationFolder { get; private set; }
public string ProjectFilePath { get; private set; }
public string ServerPath { get; set; }
public IReadOnlyDictionary<string, string> ServerPathMappings { get; }
public IReadOnlyDictionary<string, string> ServerPathMappings { get; set; }
public string NetworkShare { get; private set; }
private Federation Federation { get; set; }
public IEnumerable<string> PluginBlacklist { get; private set; }
Expand Down
40 changes: 37 additions & 3 deletions src/HtmlGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Immutable;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -233,8 +234,12 @@ private static bool IsSupportedProject(string filePath)
}

return filePath.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) ||
filePath.EndsWith(".binlog", StringComparison.OrdinalIgnoreCase) ||
filePath.EndsWith(".buildlog", StringComparison.OrdinalIgnoreCase) ||
filePath.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) ||
filePath.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase);
filePath.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase) ||
filePath.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
filePath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase);
}

private static void PrintUsage()
Expand All @@ -244,7 +249,7 @@ private static void PrintUsage()
+ "[/force] "
+ "[/noplugins] "
+ "[/noplugin:Git] "
+ "<pathtosolution1.csproj|vbproj|sln> [more solutions/projects..] "
+ "<pathtosolution1.csproj|vbproj|sln|binlog|buildlog|dll|exe> [more solutions/projects..] "
+ "[/in:<filecontaingprojectlist>] "
+ "[/nobuiltinfederations] "
+ "[/offlinefederation:server=assemblyListFile] "
Expand All @@ -253,6 +258,18 @@ private static void PrintUsage()

private static readonly Folder<ProjectSkeleton> mergedSolutionExplorerRoot = new Folder<ProjectSkeleton>();

private static IEnumerable<string> GetAssemblyNames(string filePath)
{
if (filePath.EndsWith(".binlog", System.StringComparison.OrdinalIgnoreCase) ||
filePath.EndsWith(".buildlog", System.StringComparison.OrdinalIgnoreCase))
{
var invocations = BinLogCompilerInvocationsReader.ExtractInvocations(filePath);
return invocations.Select(i => Path.GetFileNameWithoutExtension(i.Parsed.OutputFileName)).ToArray();
}

return AssemblyNameExtractor.GetAssemblyNames(filePath);
}

private static void IndexSolutions(
IEnumerable<string> solutionFilePaths,
Dictionary<string, string> properties,
Expand All @@ -267,7 +284,7 @@ private static void IndexSolutions(
{
using (Disposable.Timing("Reading assembly names from " + path))
{
foreach (var assemblyName in AssemblyNameExtractor.GetAssemblyNames(path))
foreach (var assemblyName in GetAssemblyNames(path))
{
assemblyNames.Add(assemblyName);
}
Expand All @@ -280,6 +297,23 @@ private static void IndexSolutions(
{
using (Disposable.Timing("Generating " + path))
{
if (path.EndsWith(".binlog", StringComparison.OrdinalIgnoreCase) ||
path.EndsWith(".buildlog", StringComparison.OrdinalIgnoreCase))
{
var invocations = BinLogCompilerInvocationsReader.ExtractInvocations(path);
foreach (var invocation in invocations)
{
GenerateFromBuildLog.GenerateInvocation(
invocation,
serverPathMappings,
processedAssemblyList,
assemblyNames,
mergedSolutionExplorerRoot);
}

continue;
}

using (var solutionGenerator = new SolutionGenerator(
path,
Paths.SolutionDestinationFolder,
Expand Down
Loading

0 comments on commit b79ff9c

Please sign in to comment.