Skip to content

Conversation

@Forgind
Copy link
Contributor

@Forgind Forgind commented Jun 21, 2022

Context

MSBuild has a command-line switch that tells it to output all environment variables. C++ used that fairly regularly. This PR automatically opts out of the environment variable logging change in #7484 for the duration of the one build.

Changes Made

Made the Trait settable via environment variable or with the file logger parameter. Since the parameter needs to be applied first, this means the Trait has to be set after the start of the build, so it is no longer read-only. In tests, Traits.Instance is reset every time a variable is read, so setting it at the start of the test does not work. For that reason, I had to make it a static variable on Traits instead of Traits.Instance.

Of importance, the Trait is reset (to the environment variable's value) at logger shutdown for any BaseConsoleLogger. There is theoretically a race condition here, since the Trait is set at logger initialization (if the parameter is set) and used for the BuildStarted event. If there are two builds executing concurrently in the entrypoint node, and loggers are initialized for both, then one finishes before the other has gotten to BuildStarted, the latter will not log the environment. On the other hand, that doesn't affect whether your build succeeds, and the resolution is to just run the build again, and it will likely succeed.

Testing

It passed unit tests. I also created an experimental insertion, and it passed the C++ test.

Forgind added 6 commits June 21, 2022 11:15
When running tests, Traits.Instance is recreated every time it's accessed. That means that even if we reset the value at the start, it's a new Traits.Instance that's used a moment later when we try to figure out whether to log environment variables. That doesn't work so well.
@rainersigwald rainersigwald added this to the VS 17.3 milestone Jun 27, 2022
@rainersigwald rainersigwald merged commit 6a7e837 into dotnet:main Jun 27, 2022
rainersigwald added a commit that referenced this pull request Jun 30, 2022
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.

2 participants