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

Add separate command for binary log #1044

Merged
merged 6 commits into from Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/CodeFormatter.cs
Expand Up @@ -32,7 +32,7 @@ internal static class CodeFormatter
FormatOptions formatOptions,
ILogger logger,
CancellationToken cancellationToken,
bool createBinaryLog = false)
string? binaryLogPath = null)
{
var logWorkspaceWarnings = formatOptions.LogLevel == LogLevel.Trace;

Expand All @@ -44,7 +44,7 @@ internal static class CodeFormatter

using var workspace = formatOptions.WorkspaceType == WorkspaceType.Folder
? OpenFolderWorkspace(formatOptions.WorkspaceFilePath, formatOptions.FileMatcher)
: await OpenMSBuildWorkspaceAsync(formatOptions.WorkspaceFilePath, formatOptions.WorkspaceType, createBinaryLog, logWorkspaceWarnings, logger, cancellationToken).ConfigureAwait(false);
: await OpenMSBuildWorkspaceAsync(formatOptions.WorkspaceFilePath, formatOptions.WorkspaceType, binaryLogPath, logWorkspaceWarnings, logger, cancellationToken).ConfigureAwait(false);

if (workspace is null)
{
Expand Down Expand Up @@ -123,12 +123,12 @@ private static Workspace OpenFolderWorkspace(string workspacePath, SourceFileMat
private static Task<Workspace?> OpenMSBuildWorkspaceAsync(
string solutionOrProjectPath,
WorkspaceType workspaceType,
bool createBinaryLog,
string? binaryLogPath,
bool logWorkspaceWarnings,
ILogger logger,
CancellationToken cancellationToken)
{
return MSBuildWorkspaceLoader.LoadAsync(solutionOrProjectPath, workspaceType, createBinaryLog, logWorkspaceWarnings, logger, cancellationToken);
return MSBuildWorkspaceLoader.LoadAsync(solutionOrProjectPath, workspaceType, binaryLogPath, logWorkspaceWarnings, logger, cancellationToken);
}

private static async Task<Solution> RunCodeFormattersAsync(
Expand Down
9 changes: 8 additions & 1 deletion src/FormatCommand.cs
Expand Up @@ -3,14 +3,15 @@
using System;
using System.CommandLine;
using System.CommandLine.Parsing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.Tools
{
internal static class FormatCommand
{
// This delegate should be kept in Sync with the FormatCommand options and arguement names
// This delegate should be kept in Sync with the FormatCommand options and argument names
// so that values bind correctly.
internal delegate Task<int> Handler(
string? workspace,
Expand All @@ -25,6 +26,7 @@ internal static class FormatCommand
string[] exclude,
string? report,
bool includeGenerated,
string? binarylog,
IConsole console);

internal static string[] VerbosityLevels => new[] { "q", "quiet", "m", "minimal", "n", "normal", "d", "detailed", "diag", "diagnostic" };
Expand Down Expand Up @@ -75,6 +77,11 @@ internal static RootCommand CreateCommandLineOptions()
{
IsHidden = true
},
new Option(new[] {"--binarylog", "-bl" }, Resources.Log_all_project_or_solution_load_information_to_a_binary_log_file)
jmarolf marked this conversation as resolved.
Show resolved Hide resolved
{
Argument = new Argument<string?>(
() => Path.Combine(Environment.CurrentDirectory, "formatDiagnosticLog.binlog") ) { Name = "binary-log-path" }.LegalFilePathsOnly()
jmarolf marked this conversation as resolved.
Show resolved Hide resolved
},
};

rootCommand.Description = "dotnet-format";
Expand Down
3 changes: 2 additions & 1 deletion src/Program.cs
Expand Up @@ -55,6 +55,7 @@ private static async Task<int> Main(string[] args)
string[] exclude,
string? report,
bool includeGenerated,
string? binarylog,
IConsole console = null!)
{
if (s_parseResult == null)
Expand Down Expand Up @@ -182,7 +183,7 @@ private static async Task<int> Main(string[] args)
formatOptions,
logger,
cancellationTokenSource.Token,
createBinaryLog: logLevel == LogLevel.Trace).ConfigureAwait(false);
binaryLogPath: binarylog).ConfigureAwait(false);
jmarolf marked this conversation as resolved.
Show resolved Hide resolved

return GetExitCode(formatResult, check);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Resources.resx
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Expand Down Expand Up @@ -321,4 +321,7 @@
<data name="Replace_0_characters_with_1" xml:space="preserve">
<value>Replace {0} characters with '{1}'.</value>
</data>
<data name="Log_all_project_or_solution_load_information_to_a_binary_log_file" xml:space="preserve">
<value>Log all project or solution load information to a binary log file.</value>
</data>
</root>
11 changes: 5 additions & 6 deletions src/Workspaces/MSBuildWorkspaceLoader.cs
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.MSBuild;
Expand All @@ -19,7 +18,7 @@ internal static class MSBuildWorkspaceLoader
public static async Task<Workspace?> LoadAsync(
string solutionOrProjectPath,
WorkspaceType workspaceType,
bool createBinaryLog,
string? binaryLogPath,
bool logWorkspaceWarnings,
ILogger logger,
CancellationToken cancellationToken)
Expand All @@ -35,11 +34,11 @@ internal static class MSBuildWorkspaceLoader
var workspace = MSBuildWorkspace.Create(properties);

Build.Framework.ILogger? binlog = null;
if (createBinaryLog)
if (binaryLogPath is not null)
{
binlog = new Build.Logging.BinaryLogger()
{
Parameters = Path.Combine(Environment.CurrentDirectory, "formatDiagnosticLog.binlog"),
Parameters = binaryLogPath,
Verbosity = Build.Framework.LoggerVerbosity.Diagnostic,
};
}
Expand Down Expand Up @@ -98,15 +97,15 @@ static void LogWorkspaceDiagnostics(ILogger logger, bool logWorkspaceWarnings, I
internal static async Task<Workspace?> LockedLoadAsync(
string solutionOrProjectPath,
WorkspaceType workspaceType,
bool createBinaryLog,
string? binaryLogPath,
bool logWorkspaceWarnings,
ILogger logger,
CancellationToken cancellationToken)
{
await Guard.WaitAsync();
try
{
return await LoadAsync(solutionOrProjectPath, workspaceType, createBinaryLog, logWorkspaceWarnings, logger, cancellationToken);
return await LoadAsync(solutionOrProjectPath, workspaceType, binaryLogPath, logWorkspaceWarnings, logger, cancellationToken);
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet-format.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>Microsoft.CodeAnalysis.Tools</RootNamespace>
<ServerGarbageCollection>true</ServerGarbageCollection>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.cs.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Načítá se pracovní prostor.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">{0} obsahuje více souborů projektů MSBuild. Určete, který soubor chcete použít, pomocí argumentu &lt;workspace&gt;.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.de.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Arbeitsbereich wird geladen.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">In "{0}" wurden mehrere MSBuild-Projektdateien gefunden. Geben Sie die zu verwendende Datei mit dem &lt;workspace&gt;-Argument an.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.es.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Cargando área de trabajo.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">Se encontraron varios archivos del proyecto MSBuild en "{0}". Especifique cuál debe usarse con el argumento &lt;workspace&gt;.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.fr.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Chargement de l'espace de travail.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">Plusieurs fichiers projet MSBuild trouvés dans '{0}'. Spécifiez celui qui doit être utilisé avec l'argument &lt;espace de travail&gt;.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.it.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Caricamento dell'area di lavoro.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">In '{0}' sono stati trovati più file di progetto MSBuild. Per specificare quello desiderato, usare l'argomento &lt;workspace&gt;.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.ja.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">ワークスペースを読み込んでいます。</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">複数の MSBuild プロジェクト ファイルが '{0}' で見つかりました。使用するものを &lt;workspace&gt; 引数で指定してください。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.ko.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">작업 영역을 로드하는 중입니다.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">'{0}'에 여러 MSBuild 프로젝트 파일이 있습니다. &lt;workspace&gt; 인수를 사용하여 사용할 파일을 지정하세요.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.pl.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Ładowanie obszaru roboczego.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">W elemencie „{0}” znaleziono wiele plików projektów MSBuild. Określ, którego użyć, za pomocą argumentu &lt;workspace&gt;.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.pt-BR.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Carregando espaço de trabalho.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">Foram encontrados vários arquivos de projeto do MSBuild em '{0}'. Especifique qual será usado com o argumento &lt;workspace&gt;.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.ru.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Загрузка рабочей области.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">В "{0}" обнаружено несколько файлов проекта MSBuild. Укажите используемый файл с помощью аргумента &lt;workspace&gt;.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.tr.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">Çalışma alanı yükleniyor.</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">'{0}' içinde birden fazla MSBuild proje dosyası bulundu. Hangisinin &lt;çalışma alanı&gt; bağımsız değişkeni ile kullanılacağını belirtin.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.zh-Hans.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">正在加载工作区。</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">在“{0}”中找到多个 MSBuild 项目文件。请指定要用于 &lt;workspace&gt; 参数的文件。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/xlf/Resources.zh-Hant.xlf
Expand Up @@ -167,6 +167,11 @@
<target state="translated">正在載入工作區。</target>
<note />
</trans-unit>
<trans-unit id="Log_all_project_or_solution_load_information_to_a_binary_log_file">
<source>Log all project or solution load information to a binary log file.</source>
<target state="new">Log all project or solution load information to a binary log file.</target>
<note />
</trans-unit>
<trans-unit id="Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument">
<source>Multiple MSBuild project files found in '{0}'. Specify which to use with the &lt;workspace&gt; argument.</source>
<target state="translated">在 '{0}' 中找到多個 MSBuild 專案檔。請指定要用於 &lt;workspace&gt; 引數的檔案。</target>
Expand Down
2 changes: 1 addition & 1 deletion tests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs
Expand Up @@ -43,7 +43,7 @@ public async Task InitializeAsync()
var workspacePath = Path.Combine(TestProjectsPathHelper.GetProjectsDirectory(), s_analyzerProjectFilePath);

MSBuildRegistrar.RegisterInstance(logger);
var analyzerWorkspace = await MSBuildWorkspaceLoader.LockedLoadAsync(workspacePath, WorkspaceType.Project, createBinaryLog: false, logWorkspaceWarnings: true, logger, CancellationToken.None);
var analyzerWorkspace = await MSBuildWorkspaceLoader.LockedLoadAsync(workspacePath, WorkspaceType.Project, binaryLogPath: null, logWorkspaceWarnings: true, logger, CancellationToken.None);

// From this project we can get valid AnalyzerReferences to add to our test project.
_analyzerReferencesProject = analyzerWorkspace.CurrentSolution.Projects.Single();
Expand Down
1 change: 1 addition & 0 deletions tests/ProgramTests.cs
Expand Up @@ -191,6 +191,7 @@ public async Task CommandLine_AllArguments_Bind()
string[] exclude,
string report,
bool includeGenerated,
string binaryLogPath,
IConsole console = null)
{
Assert.Equal("./src", workspace);
Expand Down
2 changes: 1 addition & 1 deletion tests/dotnet-format.UnitTests.csproj
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable>
<RootNamespace>Microsoft.CodeAnalysis.Tools.Tests</RootNamespace>

Expand Down