Skip to content

Commit

Permalink
WIP adding ability to produce a binlog
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarolf committed Mar 10, 2020
1 parent 2ace784 commit 51ac8ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/CodeFormatter.cs
Expand Up @@ -33,7 +33,8 @@ internal static class CodeFormatter
public static async Task<WorkspaceFormatResult> FormatWorkspaceAsync(
FormatOptions options,
ILogger logger,
CancellationToken cancellationToken)
CancellationToken cancellationToken,
bool createBinaryLog = false)
{
var (workspaceFilePath, workspaceType, logLevel, saveFormattedFiles, _, fileMatcher, reportPath) = options;
var logWorkspaceWarnings = logLevel == LogLevel.Trace;
Expand All @@ -45,7 +46,7 @@ internal static class CodeFormatter
var workspaceStopwatch = Stopwatch.StartNew();

using (var workspace = await OpenWorkspaceAsync(
workspaceFilePath, workspaceType, fileMatcher, logWorkspaceWarnings, logger, cancellationToken).ConfigureAwait(false))
workspaceFilePath, workspaceType, fileMatcher, logWorkspaceWarnings, logger, cancellationToken, createBinaryLog).ConfigureAwait(false))
{
if (workspace is null)
{
Expand Down Expand Up @@ -147,7 +148,8 @@ private static string GetReportFilePath(string reportPath)
Matcher fileMatcher,
bool logWorkspaceWarnings,
ILogger logger,
CancellationToken cancellationToken)
CancellationToken cancellationToken,
bool createBinaryLog = false)
{
if (workspaceType == WorkspaceType.Folder)
{
Expand All @@ -156,15 +158,16 @@ private static string GetReportFilePath(string reportPath)
return folderWorkspace;
}

return await OpenMSBuildWorkspaceAsync(workspacePath, workspaceType, logWorkspaceWarnings, logger, cancellationToken);
return await OpenMSBuildWorkspaceAsync(workspacePath, workspaceType, logWorkspaceWarnings, logger, cancellationToken, createBinaryLog);
}

private static async Task<Workspace> OpenMSBuildWorkspaceAsync(
string solutionOrProjectPath,
WorkspaceType workspaceType,
bool logWorkspaceWarnings,
ILogger logger,
CancellationToken cancellationToken)
CancellationToken cancellationToken,
bool createBinaryLog = false)
{
var properties = new Dictionary<string, string>(StringComparer.Ordinal)
{
Expand All @@ -178,6 +181,7 @@ private static string GetReportFilePath(string reportPath)
};

var workspace = MSBuildWorkspace.Create(properties);
workspace.ProduceBinaryLog = createBinaryLog;

if (workspaceType == WorkspaceType.Solution)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Program.cs
Expand Up @@ -150,7 +150,8 @@ public static async Task<int> Run(string folder, string workspace, string verbos
var formatResult = await CodeFormatter.FormatWorkspaceAsync(
formatOptions,
logger,
cancellationTokenSource.Token).ConfigureAwait(false);
cancellationTokenSource.Token,
createBinaryLog: logLevel == LogLevel.Trace ? true : false).ConfigureAwait(false);

return GetExitCode(formatResult, check);
}
Expand Down

0 comments on commit 51ac8ac

Please sign in to comment.