Skip to content

Commit

Permalink
Logging Main.Execute commandLine arguments as oppose to Environmet.Co…
Browse files Browse the repository at this point in the history
…mmandLine (#7326)

Fixes #7216 

### Context
See #7216 

### Changes Made
- Logging commandLine arguments passed into Execute method as oppose to Environment.CommandLine

### Testing
- ren before and after and compared its binary log in viewer.

### Notes
- I reviewed other places which uses  Environment.CommandLine and it seems to be OK with respect to `dotnet build` use case.
  • Loading branch information
rokonec authored Jan 26, 2022
1 parent 65447ab commit 6a79376
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,8 @@ public void InvalidToolsVersionErrors()
graphBuildOptions: null,
lowPriority: false,
inputResultsCaches: null,
outputResultsCache: null
outputResultsCache: null,
commandLine: null
);
}
finally
Expand Down
29 changes: 22 additions & 7 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,9 @@ string[] commandLine
graphBuildOptions,
lowPriority,
inputResultsCaches,
outputResultsCache))
outputResultsCache,
commandLine
))
{
exitType = ExitType.BuildError;
}
Expand Down Expand Up @@ -1006,7 +1008,12 @@ internal static bool BuildProject
GraphBuildOptions graphBuildOptions,
bool lowPriority,
string[] inputResultsCaches,
string outputResultsCache
string outputResultsCache,
#if FEATURE_GET_COMMANDLINE
string commandLine
#else
string[] commandLine
#endif
)
{
if (FileUtilities.IsVCProjFilename(projectFile) || FileUtilities.IsDspFilename(projectFile))
Expand Down Expand Up @@ -1207,9 +1214,17 @@ string outputResultsCache
#endif
BuildResultCode? result = null;

var messagesToLogInBuildLoggers = Traits.Instance.EscapeHatches.DoNotSendDeferredMessagesToBuildManager
? null
: GetMessagesToLogInBuildLoggers();
IEnumerable<BuildManager.DeferredBuildMessage> messagesToLogInBuildLoggers = null;
if (!Traits.Instance.EscapeHatches.DoNotSendDeferredMessagesToBuildManager)
{
var commandLineString =
#if FEATURE_GET_COMMANDLINE
commandLine;
#else
string.Join(" ", commandLine);
#endif
messagesToLogInBuildLoggers = GetMessagesToLogInBuildLoggers(commandLineString);
}

buildManager.BeginBuild(parameters, messagesToLogInBuildLoggers);

Expand Down Expand Up @@ -1355,7 +1370,7 @@ private static bool PrintTargets(string projectFile, string toolsVersion, Dictio
}
}

private static IEnumerable<BuildManager.DeferredBuildMessage> GetMessagesToLogInBuildLoggers()
private static IEnumerable<BuildManager.DeferredBuildMessage> GetMessagesToLogInBuildLoggers(string commandLineString)
{
return new[]
{
Expand All @@ -1372,7 +1387,7 @@ private static bool PrintTargets(string projectFile, string toolsVersion, Dictio
new BuildManager.DeferredBuildMessage(
ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword(
"CommandLine",
Environment.CommandLine),
commandLineString),
MessageImportance.Low),
new BuildManager.DeferredBuildMessage(
ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword(
Expand Down

0 comments on commit 6a79376

Please sign in to comment.