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

Expose LogTaskInputs to tasks #6803

Merged
merged 5 commits into from
Sep 13, 2021
Merged

Conversation

ladipro
Copy link
Member

@ladipro ladipro commented Sep 1, 2021

Fixes #6305

Context

The LogTaskInputs flag passed to MSBuild in BuildParameters can be used by tasks to optimize logging. When it's true, a task can omit its own duplicated logging of inputs.

Changes Made

LogTaskInputs is plumbed through and exposed as IsTaskInputLoggingEnabled on EngineServices and also on TaskLoggingHelper for convenience. The RAR task is updated to use the new property.

Testing

  • New unit test.
  • Manual testing with and without /v:diag and inspecting the log.

Copy link
Member

@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.

❤️

/// <summary>
/// This version added the IsTaskInputLoggingEnabled property.
/// </summary>
public const int Version2 = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Why add a new variable here instead of just incrementing Version? are you trying to make it extra tough to accidentally have to changes that update the version to the same thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I use named constants to basically keep a change log and have something formal to attach the comments to so they make it into the public documentation. It's just a convenience thing, trying to make it nicer for callers to use the class.

/// Returns <see langword="true"/> if the build is configured to log all task inputs.
/// </summary>
public bool IsTaskInputLoggingEnabled =>
BuildEngine is IBuildEngine10 buildEngine10 && buildEngine10.EngineServices.IsTaskInputLoggingEnabled;
Copy link
Member

Choose a reason for hiding this comment

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

|| Traits.Instance.EscapeHatches.LogTaskInputs? Maybe || (Traits.Instance.EscapeHatches.LogTaskInputs && BuildEngine is not IBuildEngine 10)?

Copy link
Member

Choose a reason for hiding this comment

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

I don’t think escape hatch is needed here anymore. It doesn’t work in other nodes anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is basically saying that we're fine without the optimization in scenarios where EngineServices is not supported, which is primarily the .NET Framework 3.5 task host. I agree with Kirill that using the escape hatch here wouldn't work reliably. And it's unlikely that 3.5 tasks would want to take advantage of this new optimization, anyway.

@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Sep 10, 2021
@AR-May AR-May merged commit e3e141f into dotnet:main Sep 13, 2021
KirillOsenkov added a commit to KirillOsenkov/NuGet.Client that referenced this pull request Nov 8, 2023
When binary logger is present, LogTaskInputs is set, so MSBuild automatically logs all inputs and outputs, there's no need to manually do so.

Starting with MSBuild 17.5 taskLogging.IsTaskInputLoggingEnabled is available, but we're still referencing Microsoft.Build.Utilities.v4.0.dll for net472 so it's not available. Instead of using reflection, just read the environment.

This results in significant savings to binlog size and potentially faster restore as well (and less memory allocations).

Fixes NuGet/Home#10696

See related:
 * dotnet/msbuild#6305
 * dotnet/msbuild#6803
jeffkl pushed a commit to KirillOsenkov/NuGet.Client that referenced this pull request Nov 9, 2023
When binary logger is present, LogTaskInputs is set, so MSBuild automatically logs all inputs and outputs, there's no need to manually do so.

Starting with MSBuild 17.5 taskLogging.IsTaskInputLoggingEnabled is available, but we're still referencing Microsoft.Build.Utilities.v4.0.dll for net472 so it's not available. Instead of using reflection, just read the environment.

This results in significant savings to binlog size and potentially faster restore as well (and less memory allocations).

Fixes NuGet/Home#10696

See related:
 * dotnet/msbuild#6305
 * dotnet/msbuild#6803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not log task inputs/outputs when LogTaskInputs is set
6 participants