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 a error/recap summary at the end of the build #11105

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
]9;4;3;\ project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build summary:
project
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!

Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
 project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build summary:
project
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!

Build failed with 1 error(s) and 1 warning(s) in 5.0s

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
]9;4;3;\ project failed with 1 error(s) and 1 warning(s) (0.2s)
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!
[?25l
[?25h
Build summary:
project
directory/file(1,2,3,4): warning AA0000: Warning!
directory/file(1,2,3,4): error AA0000: Error!

Build failed with 1 error(s) and 1 warning(s) in 5.0s
]9;4;0;\
20 changes: 20 additions & 0 deletions src/MSBuild.UnitTests/TerminalLogger_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,26 @@ public Task PrintBuildSummary_FailedWithErrors()
return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}

[Fact]
public Task PrintDetailedBuildSummary_FailedWithErrorAndWarning()
{
string? originalParameters = _terminallogger.Parameters;
_terminallogger.Parameters = "SUMMARY";
_terminallogger.ParseParameters();

InvokeLoggerCallbacksForSimpleProject(succeeded: false, () =>
{
WarningRaised?.Invoke(_eventSender, MakeWarningEventArgs("Warning!"));
ErrorRaised?.Invoke(_eventSender, MakeErrorEventArgs("Error!"));
});

// Restore original parameters
_terminallogger.Parameters = originalParameters;
_terminallogger.ParseParameters();

return Verify(_outputWriter.ToString(), _settings).UniqueForOSPlatform();
}

[Fact]
public Task PrintBuildSummary_FailedWithErrorsAndWarnings()
{
Expand Down
6 changes: 6 additions & 0 deletions src/MSBuild/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,12 @@
's' should reflect the localized abbreviation for seconds
</comment>
</data>
<data name="BuildSummary" xml:space="preserve">
<value>Build summary:</value>
<comment>
A header used by Terminal Logger to introduce the build summary.
</comment>
</data>
<data name="BuildResult_FailedWithErrors" xml:space="preserve">
<value>failed with {0} error(s)</value>
<comment>
Expand Down
7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion src/MSBuild/TerminalLogger/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Microsoft.Build.Logging.TerminalLogger;

Expand All @@ -16,8 +17,9 @@ internal sealed class Project
/// Initialized a new <see cref="Project"/> with the given <paramref name="targetFramework"/>.
/// </summary>
/// <param name="targetFramework">The target framework of the project or null if not multi-targeting.</param>
public Project(string? targetFramework, StopwatchAbstraction? stopwatch)
public Project(string projectFile, string? targetFramework, StopwatchAbstraction? stopwatch)
{
File = projectFile;
TargetFramework = targetFramework;

if (stopwatch is not null)
Expand All @@ -31,6 +33,8 @@ public Project(string? targetFramework, StopwatchAbstraction? stopwatch)
}
}

public string File { get; }

/// <summary>
/// A stopwatch to time the build of the project.
/// </summary>
Expand Down Expand Up @@ -69,4 +73,17 @@ public void AddBuildMessage(MessageSeverity severity, string message)
BuildMessages ??= new List<BuildMessage>();
BuildMessages.Add(new BuildMessage(severity, message));
}

/// <summary>
/// Filters the build messages to only include errors and warnings.
/// </summary>
/// <returns>A sequence of error and warning build messages.</returns>
public IEnumerable<BuildMessage> GetBuildErrorAndWarningMessages()
{
return BuildMessages is null ?
Enumerable.Empty<BuildMessage>() :
BuildMessages.Where(message =>
message.Severity == MessageSeverity.Error ||
message.Severity == MessageSeverity.Warning);
}
}
Loading