From e498c59a29d731e5340b3282f614f9dd06ba7580 Mon Sep 17 00:00:00 2001 From: Jonathon Marolf Date: Wed, 10 Mar 2021 21:23:52 -0800 Subject: [PATCH 1/6] Add separate command for binary log --- src/CodeFormatter.cs | 8 ++++---- src/FormatCommand.cs | 9 ++++++++- src/Program.cs | 3 ++- src/Resources.resx | 5 ++++- src/Workspaces/MSBuildWorkspaceLoader.cs | 11 +++++------ src/dotnet-format.csproj | 2 +- src/xlf/Resources.cs.xlf | 5 +++++ src/xlf/Resources.de.xlf | 5 +++++ src/xlf/Resources.es.xlf | 5 +++++ src/xlf/Resources.fr.xlf | 5 +++++ src/xlf/Resources.it.xlf | 5 +++++ src/xlf/Resources.ja.xlf | 5 +++++ src/xlf/Resources.ko.xlf | 5 +++++ src/xlf/Resources.pl.xlf | 5 +++++ src/xlf/Resources.pt-BR.xlf | 5 +++++ src/xlf/Resources.ru.xlf | 5 +++++ src/xlf/Resources.tr.xlf | 5 +++++ src/xlf/Resources.zh-Hans.xlf | 5 +++++ src/xlf/Resources.zh-Hant.xlf | 5 +++++ tests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs | 2 +- tests/ProgramTests.cs | 1 + tests/dotnet-format.UnitTests.csproj | 2 +- 22 files changed, 92 insertions(+), 16 deletions(-) diff --git a/src/CodeFormatter.cs b/src/CodeFormatter.cs index 6fcef04741..244c61e9bc 100644 --- a/src/CodeFormatter.cs +++ b/src/CodeFormatter.cs @@ -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; @@ -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) { @@ -123,12 +123,12 @@ private static Workspace OpenFolderWorkspace(string workspacePath, SourceFileMat private static Task 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 RunCodeFormattersAsync( diff --git a/src/FormatCommand.cs b/src/FormatCommand.cs index 0de958fa97..db76c92b79 100644 --- a/src/FormatCommand.cs +++ b/src/FormatCommand.cs @@ -3,6 +3,7 @@ using System; using System.CommandLine; using System.CommandLine.Parsing; +using System.IO; using System.Linq; using System.Threading.Tasks; @@ -10,7 +11,7 @@ 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 Handler( string? workspace, @@ -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" }; @@ -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) + { + Argument = new Argument( + () => Path.Combine(Environment.CurrentDirectory, "formatDiagnosticLog.binlog") ) { Name = "binary-log-path" }.LegalFilePathsOnly() + }, }; rootCommand.Description = "dotnet-format"; diff --git a/src/Program.cs b/src/Program.cs index 99a349306e..e533a74cfa 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -55,6 +55,7 @@ private static async Task Main(string[] args) string[] exclude, string? report, bool includeGenerated, + string? binarylog, IConsole console = null!) { if (s_parseResult == null) @@ -182,7 +183,7 @@ private static async Task Main(string[] args) formatOptions, logger, cancellationTokenSource.Token, - createBinaryLog: logLevel == LogLevel.Trace).ConfigureAwait(false); + binaryLogPath: binarylog).ConfigureAwait(false); return GetExitCode(formatResult, check); } diff --git a/src/Resources.resx b/src/Resources.resx index 3df29ecc26..b3120bb4af 100644 --- a/src/Resources.resx +++ b/src/Resources.resx @@ -1,4 +1,4 @@ - +