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

Request silent restore for all separate restore steps #40148

Merged
merged 7 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 12 additions & 13 deletions src/Cli/dotnet/commands/RestoringCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ private static RestoreCommand GetSeparateRestoreCommand(
}

IEnumerable<string> restoreArguments = ["-target:Restore"];
if (arguments != null)
{
(var newArgumentsToAdd, var existingArgumentsToForward) = ProcessForwardedArgumentsForSeparateRestore(arguments);
restoreArguments = [.. restoreArguments, .. newArgumentsToAdd, .. existingArgumentsToForward];
}
(var newArgumentsToAdd, var existingArgumentsToForward) = ProcessForwardedArgumentsForSeparateRestore(arguments);
restoreArguments = [.. restoreArguments, .. newArgumentsToAdd, .. existingArgumentsToForward];

return new RestoreCommand(restoreArguments, msbuildPath);
}
Expand All @@ -84,12 +81,13 @@ private static bool HasArgumentToExcludeFromRestore(IEnumerable<string> argument
"TargetFramework"
];

// These arguments should lead to absolutely no output from the restore command
private static readonly string[] FlagsThatTriggerSilentRestore =
[
"getProperty",
"getItem",
"getTargetResult"
];
[
"getProperty",
"getItem",
"getTargetResult"
];

// These arguments don't by themselves require that restore be run in a separate process,
// but if there is a separate restore process they shouldn't be passed to it
Expand All @@ -116,12 +114,12 @@ private static bool HasArgumentToExcludeFromRestore(IEnumerable<string> argument
// that we need to compensate for, so we might yield new arguments that should be included in the overall restore call.
private static (string[] newArgumentsToAdd, string[] existingArgumentsToForward) ProcessForwardedArgumentsForSeparateRestore(IEnumerable<string> forwardedArguments)
{
HashSet<string> newArgumentsToAdd = new();
// Separate restore should be silent in terminal logger - regardless of actual scenario
HashSet<string> newArgumentsToAdd = new() { "-tlp:verbosity=quiet" };
List<string> existingArgumentsToForward = new();

foreach (var argument in forwardedArguments)
foreach (var argument in forwardedArguments ?? Enumerable.Empty<string>())
{

if (!IsExcludedFromSeparateRestore(argument) && !IsExcludedFromRestore(argument))
{
existingArgumentsToForward.Add(argument);
Expand Down Expand Up @@ -165,6 +163,7 @@ private static bool IsExcludedFromRestore(string argument)
private static bool IsExcludedFromSeparateRestore(string argument)
=> FlagsToExcludeFromSeparateRestore.Any(p => argument.StartsWith(p, StringComparison.OrdinalIgnoreCase));

// These arguments should lead to absolutely no output from the restore command - regardless of loggers
private static bool TriggersSilentSeparateRestore(string argument)
=> FlagsThatTriggerSilentSeparateRestore.Any(p => argument.StartsWith(p, StringComparison.OrdinalIgnoreCase));

Expand Down
14 changes: 7 additions & 7 deletions test/dotnet.Tests/dotnet-msbuild/GivenDotnetBuildInvocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalA
}

[Theory]
[InlineData(new string[] { "-f", "tfm" }, "-target:Restore", "-property:TargetFramework=tfm")]
[InlineData(new string[] { "-p:TargetFramework=tfm" }, "-target:Restore", "--property:TargetFramework=tfm")]
[InlineData(new string[] { "/p:TargetFramework=tfm" }, "-target:Restore", "--property:TargetFramework=tfm")]
[InlineData(new string[] { "-t:Run", "-f", "tfm" }, "-target:Restore", "-property:TargetFramework=tfm -t:Run")]
[InlineData(new string[] { "/t:Run", "-f", "tfm" }, "-target:Restore", "-property:TargetFramework=tfm /t:Run")]
[InlineData(new string[] { "-f", "tfm" }, "-target:Restore -tlp:verbosity=quiet", "-property:TargetFramework=tfm")]
[InlineData(new string[] { "-p:TargetFramework=tfm" }, "-target:Restore -tlp:verbosity=quiet", "--property:TargetFramework=tfm")]
[InlineData(new string[] { "/p:TargetFramework=tfm" }, "-target:Restore -tlp:verbosity=quiet", "--property:TargetFramework=tfm")]
[InlineData(new string[] { "-t:Run", "-f", "tfm" }, "-target:Restore -tlp:verbosity=quiet", "-property:TargetFramework=tfm -t:Run")]
[InlineData(new string[] { "/t:Run", "-f", "tfm" }, "-target:Restore -tlp:verbosity=quiet", "-property:TargetFramework=tfm /t:Run")]
[InlineData(new string[] { "-o", "myoutput", "-f", "tfm", "-v", "diag", "/ArbitrarySwitchForMSBuild" },
"-target:Restore -verbosity:diag -property:OutputPath=<cwd>myoutput -property:_CommandLineDefinedOutputPath=true /ArbitrarySwitchForMSBuild",
"-target:Restore -tlp:verbosity=quiet -verbosity:diag -property:OutputPath=<cwd>myoutput -property:_CommandLineDefinedOutputPath=true /ArbitrarySwitchForMSBuild",
"-property:TargetFramework=tfm -verbosity:diag -property:OutputPath=<cwd>myoutput -property:_CommandLineDefinedOutputPath=true /ArbitrarySwitchForMSBuild")]
[InlineData(new string[] { "-f", "tfm", "-getItem:Compile", "-getProperty:TargetFramework", "-getTargetResult:Build" }, "-target:Restore -nologo -verbosity:quiet", "-property:TargetFramework=tfm -getItem:Compile -getProperty:TargetFramework -getTargetResult:Build")]
[InlineData(new string[] { "-f", "tfm", "-getItem:Compile", "-getProperty:TargetFramework", "-getTargetResult:Build" }, "-target:Restore -tlp:verbosity=quiet -nologo -verbosity:quiet", "-property:TargetFramework=tfm -getItem:Compile -getProperty:TargetFramework -getTargetResult:Build")]
public void MsbuildInvocationIsCorrectForSeparateRestore(
string[] args,
string expectedAdditionalArgsForRestore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void MsbuildInvocationIsCorrectForSeparateRestore(string[] args, string e
command.SeparateRestoreCommand
.GetArgumentsToMSBuild()
.Should()
.Be($"{ExpectedPrefix} -target:Restore {ExpectedProperties}");
.Be($"{ExpectedPrefix} -target:Restore -tlp:verbosity=quiet {ExpectedProperties}");

command.GetArgumentsToMSBuild()
.Should()
Expand Down