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 support for improved TaskParameterEventArgs #780

Merged
merged 2 commits into from
May 17, 2024

Conversation

ladipro
Copy link
Contributor

@ladipro ladipro commented May 15, 2024

dotnet/msbuild#10130 is making MSBuild log TaskParameterEventArgs for all task parameters, including all output parameters. This PR adds support for this format change to the viewer.

Changes

  • Bumped the current format version and implemented the corresponding (de)serialization.
  • Updated task parameter processing to expect TaskParameterEventArgs used for all parameters.
  • Updated the presentation of output parameters (up for discussion, details below).

Testing

  • Old binlog with new viewer - no changes.

  • New binlog with old viewer - shows the Skipped some data unknown to this version ... warning and misplaces output parameters assigned to properties. They are incorrectly displayed under OutputItems with N/A name.

image

This is assumed to be an acceptable break for users who haven't updated to the new version.

  • New binlog with new viewer - newly shows the name of the task parameter.

image

This is just a quick proof-of-concept as I'm not sure what the best way of presenting this data is or if there's appetite for enriching the UI at all. We could certainly not show the parameter name anywhere for now.

@@ -165,7 +165,7 @@ public static Build ReadBuild(Stream stream, Progress progress, byte[] projectIm

if (errorByType.Any(i => i != 0))
{
string summary = string.Join(", ", errorByType.Where((count, index) => count > 0).Select((count, index) => $"{((ReaderErrorType)index)}: {count}"));
string summary = string.Join(", ", errorByType.Where((count, index) => count > 0).Select((count, index) => $"{((ReaderErrorType)index)}: {count} cases"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm finding the existing message confusing. For example, Skipped some data unknown to this version of Viewer. 7 cases encountered (UnknownEventType: 7). to me suggests that 7 is the event type. Making it clearer that the number is the count.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed very confusing. Thanks!

Comment on lines -74 to -85
private static Action<BuildMessageEventArgs, int> lineNumberSetter = GetFieldSetter<BuildMessageEventArgs, int>("lineNumber");
public static void SetLineNumber(BuildMessageEventArgs args, int lineNumber)
{
lineNumberSetter(args, lineNumber);
}

private static Action<BuildMessageEventArgs, int> columnNumberSetter = GetFieldSetter<BuildMessageEventArgs, int>("columnNumber");
public static void SetColumnNumber(BuildMessageEventArgs args, int columnNumber)
{
columnNumberSetter(args, columnNumber);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this anymore as TaskParameterEventArgs2 contains new props representing line and column number.

Copy link
Contributor

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me - simple and effective. Thank you!

@@ -165,7 +165,7 @@ public static Build ReadBuild(Stream stream, Progress progress, byte[] projectIm

if (errorByType.Any(i => i != 0))
{
string summary = string.Join(", ", errorByType.Where((count, index) => count > 0).Select((count, index) => $"{((ReaderErrorType)index)}: {count}"));
string summary = string.Join(", ", errorByType.Where((count, index) => count > 0).Select((count, index) => $"{((ReaderErrorType)index)}: {count} cases"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed very confusing. Thanks!

Comment on lines -32 to +35
if (line != 0)
{
Reflector.SetLineNumber(args, line);
}

if (column != 0)
{
Reflector.SetColumnNumber(args, column);
}

// Should probably make these public
// args.LineNumber = line;
// args.ColumnNumber = column;
args.LineNumber = line;
args.ColumnNumber = column;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Owner

@KirillOsenkov KirillOsenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@KirillOsenkov KirillOsenkov merged commit 8d94b16 into KirillOsenkov:main May 17, 2024
1 check passed
@KirillOsenkov
Copy link
Owner

Published https://github.com/KirillOsenkov/MSBuildStructuredLog/releases/tag/v2.2.243 - please try it out to make sure it all works as expected. Thanks!

@ladipro
Copy link
Contributor Author

ladipro commented May 22, 2024

@KirillOsenkov I have tested it on version 2.2.248 and all seems to be good. Please confirm that it's OK to merge the MSBuild PR now.

@KirillOsenkov
Copy link
Owner

yes, go ahead

ladipro added a commit to dotnet/msbuild that referenced this pull request May 23, 2024
Contributes to #9881

### Context

When `TaskParameterEventArgs` represents an output parameter of a task, it currently does not capture the name of the parameter. This information is generally useful as multiple output parameters can be assigned to the same item, and it's important for the BuildCheck infrastructure to provide a consistent object model to build analyzers.

Additionally, output parameters that are assigned to properties are currently logged as textual log messages `Output Property: {0}={1}` which miss the name of the parameter as well.

### Changes Made

Added two new properties on the `TaskParameterEventArgs` class, including the requisite serialization support. Updated logging to populate the properties with the name of the task parameter and the name of the build property, respectively, and updated BuildCheck infra to expose it to analyzers subscribed to task parameter events.

All task parameters are now logged as the structured `TaskParameterEventArgs` and the kind of parameter (input, output to property, output to item) can be determined by examining the args.

### Testing

- Tweaked existing unit test and updated the relevant BuildCheck test.
- Verified that when using the standard console logger, the resulting textual log is identical.
- Verified that binlog viewer without the corresponding changes displays the forward-compat warning about unknown data.

### Notes

- Complementary binlog viewer PR: KirillOsenkov/MSBuildStructuredLog#780
- The change is behind a changewave because it is technically a breaking change for third party loggers.

Co-authored-by: Rainer Sigwald <raines@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants