Skip to content

Commit 8181f03

Browse files
github-actions[bot]elinor-fungvitek-karascarlossanlop
authored
[release/8.0] Skip duplicate --info output if it is known SDK output (#92013)
* Skip duplicate --info output if it is known SDK output * Update src/native/corehost/fxr/fx_muxer.cpp Co-authored-by: Vitek Karas <[email protected]> * Add tests --------- Co-authored-by: Elinor Fung <[email protected]> Co-authored-by: Vitek Karas <[email protected]> Co-authored-by: Carlos Sánchez López <[email protected]>
1 parent 5c03c88 commit 8181f03

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

src/installer/tests/HostActivation.Tests/DotnetArgValidation.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,35 @@ public void InvalidFileOrCommand_NoSDK_ListsPossibleIssues()
8282
.And.FindAnySdk(false);
8383
}
8484

85+
[Fact]
86+
public void DotNetInfo_NoSDK()
87+
{
88+
sharedTestState.BuiltDotNet.Exec("--info")
89+
.CaptureStdOut()
90+
.CaptureStdErr()
91+
.Execute()
92+
.Should().Pass()
93+
.And.HaveStdOutMatching($@"Architecture:\s*{RepoDirectoriesProvider.Default.BuildArchitecture}")
94+
.And.HaveStdOutMatching($@"RID:\s*{RepoDirectoriesProvider.Default.BuildRID}");
95+
}
96+
97+
[Fact]
98+
public void DotNetInfo_WithSDK()
99+
{
100+
DotNetCli dotnet = new DotNetBuilder(sharedTestState.BaseDirectory.Location, RepoDirectoriesProvider.Default.BuiltDotnet, "withSdk")
101+
.AddMicrosoftNETCoreAppFrameworkMockHostPolicy("1.0.0")
102+
.AddMockSDK("1.0.0", "1.0.0")
103+
.Build();
104+
105+
dotnet.Exec("--info")
106+
.WorkingDirectory(sharedTestState.BaseDirectory.Location)
107+
.CaptureStdOut()
108+
.CaptureStdErr()
109+
.Execute()
110+
.Should().Pass()
111+
.And.NotHaveStdOutMatching($@"RID:\s*{RepoDirectoriesProvider.Default.BuildRID}");
112+
}
113+
85114
// Return a non-existent path that contains a mix of / and \
86115
private string GetNonexistentAndUnnormalizedPath()
87116
{

src/installer/tests/TestUtils/Assertions/CommandResultAssertions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ public AndConstraint<CommandResultAssertions> HaveStdOutMatching(string pattern,
7474
return new AndConstraint<CommandResultAssertions>(this);
7575
}
7676

77+
public AndConstraint<CommandResultAssertions> NotHaveStdOutMatching(string pattern, RegexOptions options = RegexOptions.None)
78+
{
79+
Execute.Assertion.ForCondition(!Regex.IsMatch(Result.StdOut, pattern, options))
80+
.FailWith($"The command output matched a pattern is should not have matched. Pattern: '{pattern}'{GetDiagnosticsInfo()}");
81+
return new AndConstraint<CommandResultAssertions>(this);
82+
}
83+
7784
public AndConstraint<CommandResultAssertions> HaveStdErr()
7885
{
7986
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(Result.StdErr))

src/native/corehost/fxr/command_line.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,18 @@ int command_line::parse_args_for_sdk_command(
280280
return parse_args(host_info, 1, argc, argv, false, host_mode_t::muxer, new_argoff, app_candidate, opts);
281281
}
282282

283-
void command_line::print_muxer_info(const pal::string_t &dotnet_root, const pal::string_t &global_json_path)
283+
void command_line::print_muxer_info(const pal::string_t &dotnet_root, const pal::string_t &global_json_path, bool skip_sdk_info_output)
284284
{
285285
pal::string_t commit = _STRINGIFY(REPO_COMMIT_HASH);
286286
trace::println(_X("\n")
287287
_X("Host:\n")
288288
_X(" Version: ") _STRINGIFY(HOST_VERSION) _X("\n")
289289
_X(" Architecture: ") _STRINGIFY(CURRENT_ARCH_NAME) _X("\n")
290-
_X(" Commit: %s\n")
291-
_X(" RID: %s"),
292-
commit.substr(0, 10).c_str(),
293-
get_runtime_id().c_str());
290+
_X(" Commit: %s"),
291+
commit.substr(0, 10).c_str());
292+
293+
if (!skip_sdk_info_output)
294+
trace::println(_X(" RID: %s"), get_runtime_id().c_str());
294295

295296
trace::println(_X("\n")
296297
_X(".NET SDKs installed:"));

src/native/corehost/fxr/command_line.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ namespace command_line
5757
/*out*/ pal::string_t &app_candidate,
5858
/*out*/ opt_map_t &opts);
5959

60-
void print_muxer_info(const pal::string_t &dotnet_root, const pal::string_t &global_json_path);
60+
// skip_sdk_info_output indicates whether or not to skip any information that the SDK would have
61+
// already printed. Related: https://github.com/dotnet/sdk/issues/33697
62+
void print_muxer_info(const pal::string_t &dotnet_root, const pal::string_t &global_json_path, bool skip_sdk_info_output);
6163
void print_muxer_usage(bool is_sdk_present);
6264
};
6365

src/native/corehost/fxr/fx_muxer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ int fx_muxer_t::handle_cli(
10551055
}
10561056
else if (pal::strcasecmp(_X("--info"), argv[1]) == 0)
10571057
{
1058-
command_line::print_muxer_info(host_info.dotnet_root, resolver.global_file_path());
1058+
command_line::print_muxer_info(host_info.dotnet_root, resolver.global_file_path(), false /*skip_sdk_info_output*/);
10591059
return StatusCode::Success;
10601060
}
10611061

@@ -1107,7 +1107,7 @@ int fx_muxer_t::handle_cli(
11071107

11081108
if (pal::strcasecmp(_X("--info"), argv[1]) == 0)
11091109
{
1110-
command_line::print_muxer_info(host_info.dotnet_root, resolver.global_file_path());
1110+
command_line::print_muxer_info(host_info.dotnet_root, resolver.global_file_path(), result == 0 /*skip_sdk_info_output*/);
11111111
}
11121112

11131113
return result;

0 commit comments

Comments
 (0)