Skip to content

Commit f329648

Browse files
adamsitnikCopilotjkotas
authored
stop using System.CommandLine types that won't be public anymore (#116065)
* stop using System.CommandLine types that won't be public anymore * bump System.CommandLine version to what SDK is going to use as well Co-authored-by: Copilot <[email protected]> Co-authored-by: Jan Kotas <[email protected]>
1 parent 7a06f23 commit f329648

File tree

9 files changed

+115
-116
lines changed

9 files changed

+115
-116
lines changed

eng/Version.Details.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<Uri>https://github.com/dotnet/llvm-project</Uri>
4242
<Sha>da5dd054a531e6fea65643b7e754285b73eab433</Sha>
4343
</Dependency>
44-
<Dependency Name="System.CommandLine" Version="2.0.0-beta5.25260.104">
44+
<Dependency Name="System.CommandLine" Version="2.0.0-beta5.25279.2">
4545
<Uri>https://github.com/dotnet/dotnet</Uri>
4646
<Sha>85778473549347b3e4bad3ea009e9438df7b11bb</Sha>
4747
</Dependency>

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
<!-- Not auto-updated. -->
181181
<MicrosoftDiaSymReaderVersion>2.0.0</MicrosoftDiaSymReaderVersion>
182182
<MicrosoftDiaSymReaderNativeVersion>17.10.0-beta1.24272.1</MicrosoftDiaSymReaderNativeVersion>
183-
<SystemCommandLineVersion>2.0.0-beta5.25260.104</SystemCommandLineVersion>
183+
<SystemCommandLineVersion>2.0.0-beta5.25279.2</SystemCommandLineVersion>
184184
<TraceEventVersion>3.1.16</TraceEventVersion>
185185
<NETStandardLibraryRefVersion>2.1.0</NETStandardLibraryRefVersion>
186186
<NetStandardLibraryVersion>2.0.3</NetStandardLibraryVersion>

src/coreclr/tools/Common/CommandLineHelpers.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.CommandLine.Help;
54
using System.Collections.Generic;
5+
using System.CommandLine.Help;
6+
using System.CommandLine.Invocation;
67
using System.CommandLine.Parsing;
78
using System.IO;
89
using System.IO.Compression;
@@ -129,15 +130,13 @@ public static RootCommand UseVersion(this RootCommand command)
129130
return command;
130131
}
131132

132-
public static RootCommand UseExtendedHelp(this RootCommand command, Func<HelpContext, IEnumerable<Func<HelpContext, bool>>> customizer)
133+
public static RootCommand UseExtendedHelp(this RootCommand command, Action<ParseResult> customizer)
133134
{
134135
foreach (Option option in command.Options)
135136
{
136137
if (option is HelpOption helpOption)
137138
{
138-
HelpBuilder builder = new();
139-
builder.CustomizeLayout(customizer);
140-
helpOption.Action = new HelpAction { Builder = builder };
139+
helpOption.Action = new CustomizedHelpAction(helpOption, customizer);
141140
break;
142141
}
143142
}
@@ -427,5 +426,26 @@ public static bool TryReadResponseFile(string filePath, out IReadOnlyList<string
427426
newTokens = null;
428427
return false;
429428
}
429+
430+
private sealed class CustomizedHelpAction : SynchronousCommandLineAction
431+
{
432+
private readonly HelpAction _helpAction;
433+
private readonly Action<ParseResult> _customizer;
434+
435+
public CustomizedHelpAction(HelpOption helpOption, Action<ParseResult> customizer)
436+
{
437+
_helpAction = (HelpAction)helpOption.Action;
438+
_customizer = customizer;
439+
}
440+
441+
public override int Invoke(ParseResult parseResult)
442+
{
443+
int result = _helpAction.Invoke(parseResult);
444+
445+
_customizer(parseResult);
446+
447+
return result;
448+
}
449+
}
430450
}
431451
}

src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -329,64 +329,57 @@ public ILCompilerRootCommand(string[] args) : base(".NET Native IL Compiler")
329329
});
330330
}
331331

332-
public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext _)
332+
public static void PrintExtendedHelp(ParseResult _)
333333
{
334-
foreach (Func<HelpContext, bool> sectionDelegate in HelpBuilder.Default.GetLayout())
335-
yield return sectionDelegate;
334+
Console.WriteLine("Options may be passed on the command line, or via response file. On the command line switch values may be specified by passing " +
335+
"the option followed by a space followed by the value of the option, or by specifying a : between option and switch value. A response file " +
336+
"is specified by passing the @ symbol before the response file name. In a response file all options must be specified on their own lines, and " +
337+
"only the : syntax for switches is supported.\n");
336338

337-
yield return _ =>
338-
{
339-
Console.WriteLine("Options may be passed on the command line, or via response file. On the command line switch values may be specified by passing " +
340-
"the option followed by a space followed by the value of the option, or by specifying a : between option and switch value. A response file " +
341-
"is specified by passing the @ symbol before the response file name. In a response file all options must be specified on their own lines, and " +
342-
"only the : syntax for switches is supported.\n");
343-
344-
Console.WriteLine("Use the '--' option to disambiguate between input files that have begin with -- and options. After a '--' option, all arguments are " +
345-
"considered to be input files. If no input files begin with '--' then this option is not necessary.\n");
339+
Console.WriteLine("Use the '--' option to disambiguate between input files that have begin with -- and options. After a '--' option, all arguments are " +
340+
"considered to be input files. If no input files begin with '--' then this option is not necessary.\n");
346341

347-
string[] ValidArchitectures = new string[] { "arm", "arm64", "x86", "x64", "riscv64", "loongarch64" };
348-
string[] ValidOS = new string[] { "windows", "linux", "freebsd", "osx", "maccatalyst", "ios", "iossimulator", "tvos", "tvossimulator" };
342+
string[] ValidArchitectures = new string[] { "arm", "arm64", "x86", "x64", "riscv64", "loongarch64" };
343+
string[] ValidOS = new string[] { "windows", "linux", "freebsd", "osx", "maccatalyst", "ios", "iossimulator", "tvos", "tvossimulator" };
349344

350-
Console.WriteLine("Valid switches for {0} are: '{1}'. The default value is '{2}'\n", "--targetos", string.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant());
345+
Console.WriteLine("Valid switches for {0} are: '{1}'. The default value is '{2}'\n", "--targetos", string.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant());
351346

352-
Console.WriteLine(string.Format("Valid switches for {0} are: '{1}'. The default value is '{2}'\n", "--targetarch", string.Join("', '", ValidArchitectures), Helpers.GetTargetArchitecture(null).ToString().ToLowerInvariant()));
347+
Console.WriteLine(string.Format("Valid switches for {0} are: '{1}'. The default value is '{2}'\n", "--targetarch", string.Join("', '", ValidArchitectures), Helpers.GetTargetArchitecture(null).ToString().ToLowerInvariant()));
353348

354-
Console.WriteLine("The allowable values for the --instruction-set option are described in the table below. Each architecture has a different set of valid " +
355-
"instruction sets, and multiple instruction sets may be specified by separating the instructions sets by a ','. For example 'avx2,bmi,lzcnt'");
349+
Console.WriteLine("The allowable values for the --instruction-set option are described in the table below. Each architecture has a different set of valid " +
350+
"instruction sets, and multiple instruction sets may be specified by separating the instructions sets by a ','. For example 'avx2,bmi,lzcnt'");
356351

357-
foreach (string arch in ValidArchitectures)
352+
foreach (string arch in ValidArchitectures)
353+
{
354+
TargetArchitecture targetArch = Helpers.GetTargetArchitecture(arch);
355+
bool first = true;
356+
foreach (var instructionSet in Internal.JitInterface.InstructionSetFlags.ArchitectureToValidInstructionSets(targetArch))
358357
{
359-
TargetArchitecture targetArch = Helpers.GetTargetArchitecture(arch);
360-
bool first = true;
361-
foreach (var instructionSet in Internal.JitInterface.InstructionSetFlags.ArchitectureToValidInstructionSets(targetArch))
358+
// Only instruction sets with are specifiable should be printed to the help text
359+
if (instructionSet.Specifiable)
362360
{
363-
// Only instruction sets with are specifiable should be printed to the help text
364-
if (instructionSet.Specifiable)
361+
if (first)
365362
{
366-
if (first)
367-
{
368-
Console.Write(arch);
369-
Console.Write(": ");
370-
first = false;
371-
}
372-
else
373-
{
374-
Console.Write(", ");
375-
}
376-
Console.Write(instructionSet.Name);
363+
Console.Write(arch);
364+
Console.Write(": ");
365+
first = false;
377366
}
367+
else
368+
{
369+
Console.Write(", ");
370+
}
371+
Console.Write(instructionSet.Name);
378372
}
379-
380-
if (first) continue; // no instruction-set found for this architecture
381-
382-
Console.WriteLine();
383373
}
384374

375+
if (first) continue; // no instruction-set found for this architecture
376+
385377
Console.WriteLine();
386-
Console.WriteLine("The following CPU names are predefined groups of instruction sets and can be used in --instruction-set too:");
387-
Console.WriteLine(string.Join(", ", Internal.JitInterface.InstructionSetFlags.AllCpuNames));
388-
return true;
389-
};
378+
}
379+
380+
Console.WriteLine();
381+
Console.WriteLine("The following CPU names are predefined groups of instruction sets and can be used in --instruction-set too:");
382+
Console.WriteLine(string.Join(", ", Internal.JitInterface.InstructionSetFlags.AllCpuNames));
390383
}
391384

392385
private static TargetArchitecture MakeTargetArchitecture(ArgumentResult result)

src/coreclr/tools/aot/ILCompiler/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ private static IEnumerable<int> ProcessWarningCodes(IEnumerable<string> warningC
788788
private static int Main(string[] args) =>
789789
new CommandLineConfiguration(new ILCompilerRootCommand(args)
790790
.UseVersion()
791-
.UseExtendedHelp(ILCompilerRootCommand.GetExtendedHelp))
791+
.UseExtendedHelp(ILCompilerRootCommand.PrintExtendedHelp))
792792
{
793793
ResponseFileTokenReplacer = Helpers.TryReadResponseFile,
794794
EnableDefaultExceptionHandler = false,

src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -285,69 +285,62 @@ public Crossgen2RootCommand(string[] args) : base(SR.Crossgen2BannerText)
285285
});
286286
}
287287

288-
public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext _)
288+
public static void PrintExtendedHelp(ParseResult _)
289289
{
290-
foreach (Func<HelpContext, bool> sectionDelegate in HelpBuilder.Default.GetLayout())
291-
yield return sectionDelegate;
292-
293-
yield return _ =>
290+
Console.WriteLine(SR.OptionPassingHelp);
291+
Console.WriteLine();
292+
Console.WriteLine(SR.DashDashHelp);
293+
Console.WriteLine();
294+
295+
string[] ValidArchitectures = new string[] {"arm", "armel", "arm64", "x86", "x64", "riscv64", "loongarch64"};
296+
string[] ValidOS = new string[] {"windows", "linux", "osx", "ios", "iossimulator", "maccatalyst"};
297+
298+
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetos", String.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant()));
299+
Console.WriteLine();
300+
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetarch", String.Join("', '", ValidArchitectures), Helpers.GetTargetArchitecture(null).ToString().ToLowerInvariant()));
301+
Console.WriteLine();
302+
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--type-validation", String.Join("', '", Enum.GetNames<TypeValidationRule>()), nameof(TypeValidationRule.Automatic)));
303+
Console.WriteLine();
304+
305+
Console.WriteLine(SR.CrossModuleInliningExtraHelp);
306+
Console.WriteLine();
307+
Console.WriteLine(String.Format(SR.LayoutOptionExtraHelp, "--method-layout", String.Join("', '", Enum.GetNames<MethodLayoutAlgorithm>())));
308+
Console.WriteLine();
309+
Console.WriteLine(String.Format(SR.LayoutOptionExtraHelp, "--file-layout", String.Join("', '", Enum.GetNames<FileLayoutAlgorithm>())));
310+
Console.WriteLine();
311+
312+
Console.WriteLine(SR.InstructionSetHelp);
313+
foreach (string arch in ValidArchitectures)
294314
{
295-
Console.WriteLine(SR.OptionPassingHelp);
296-
Console.WriteLine();
297-
Console.WriteLine(SR.DashDashHelp);
298-
Console.WriteLine();
299-
300-
string[] ValidArchitectures = new string[] {"arm", "armel", "arm64", "x86", "x64", "riscv64", "loongarch64"};
301-
string[] ValidOS = new string[] {"windows", "linux", "osx", "ios", "iossimulator", "maccatalyst"};
302-
303-
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetos", String.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant()));
304-
Console.WriteLine();
305-
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetarch", String.Join("', '", ValidArchitectures), Helpers.GetTargetArchitecture(null).ToString().ToLowerInvariant()));
306-
Console.WriteLine();
307-
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--type-validation", String.Join("', '", Enum.GetNames<TypeValidationRule>()), nameof(TypeValidationRule.Automatic)));
308-
Console.WriteLine();
309-
310-
Console.WriteLine(SR.CrossModuleInliningExtraHelp);
311-
Console.WriteLine();
312-
Console.WriteLine(String.Format(SR.LayoutOptionExtraHelp, "--method-layout", String.Join("', '", Enum.GetNames<MethodLayoutAlgorithm>())));
313-
Console.WriteLine();
314-
Console.WriteLine(String.Format(SR.LayoutOptionExtraHelp, "--file-layout", String.Join("', '", Enum.GetNames<FileLayoutAlgorithm>())));
315-
Console.WriteLine();
316-
317-
Console.WriteLine(SR.InstructionSetHelp);
318-
foreach (string arch in ValidArchitectures)
315+
TargetArchitecture targetArch = Helpers.GetTargetArchitecture(arch);
316+
bool first = true;
317+
foreach (var instructionSet in Internal.JitInterface.InstructionSetFlags.ArchitectureToValidInstructionSets(targetArch))
319318
{
320-
TargetArchitecture targetArch = Helpers.GetTargetArchitecture(arch);
321-
bool first = true;
322-
foreach (var instructionSet in Internal.JitInterface.InstructionSetFlags.ArchitectureToValidInstructionSets(targetArch))
319+
// Only instruction sets with are specifiable should be printed to the help text
320+
if (instructionSet.Specifiable)
323321
{
324-
// Only instruction sets with are specifiable should be printed to the help text
325-
if (instructionSet.Specifiable)
322+
if (first)
326323
{
327-
if (first)
328-
{
329-
Console.Write(arch);
330-
Console.Write(": ");
331-
first = false;
332-
}
333-
else
334-
{
335-
Console.Write(", ");
336-
}
337-
Console.Write(instructionSet.Name);
324+
Console.Write(arch);
325+
Console.Write(": ");
326+
first = false;
338327
}
328+
else
329+
{
330+
Console.Write(", ");
331+
}
332+
Console.Write(instructionSet.Name);
339333
}
340-
341-
if (first) continue; // no instruction-set found for this architecture
342-
343-
Console.WriteLine();
344334
}
345335

336+
if (first) continue; // no instruction-set found for this architecture
337+
346338
Console.WriteLine();
347-
Console.WriteLine(SR.CpuFamilies);
348-
Console.WriteLine(string.Join(", ", Internal.JitInterface.InstructionSetFlags.AllCpuNames));
349-
return true;
350-
};
339+
}
340+
341+
Console.WriteLine();
342+
Console.WriteLine(SR.CpuFamilies);
343+
Console.WriteLine(string.Join(", ", Internal.JitInterface.InstructionSetFlags.AllCpuNames));
351344
}
352345

353346
private static TargetArchitecture MakeTargetArchitecture(ArgumentResult result)

src/coreclr/tools/aot/crossgen2/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ internal static bool IsValidPublicKey(byte[] blob)
914914
private static int Main(string[] args) =>
915915
new CommandLineConfiguration(new Crossgen2RootCommand(args)
916916
.UseVersion()
917-
.UseExtendedHelp(Crossgen2RootCommand.GetExtendedHelp))
917+
.UseExtendedHelp(Crossgen2RootCommand.PrintExtendedHelp))
918918
{
919919
ResponseFileTokenReplacer = Helpers.TryReadResponseFile,
920920
EnableDefaultExceptionHandler = false,

src/coreclr/tools/dotnet-pgo/PgoRootCommand.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,11 @@ int ExecuteWithContext(ParseResult result, bool setVerbosity)
260260
}
261261
}
262262

263-
public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext context)
263+
public static void PrintExtendedHelp(ParseResult parseResult)
264264
{
265-
foreach (Func<HelpContext, bool> sectionDelegate in HelpBuilder.Default.GetLayout())
266-
yield return sectionDelegate;
267-
268-
if (context.Command.Name == "create-mibc" || context.Command.Name == "create-jittrace")
265+
if (parseResult.CommandResult.Command.Name is "create-mibc" or "create-jittrace")
269266
{
270-
yield return _ =>
271-
{
272-
Console.WriteLine(
267+
Console.WriteLine(
273268
@"Example tracing commands used to generate the input to this tool:
274269
""dotnet-trace collect -p 73060 --providers Microsoft-Windows-DotNETRuntime:0x1E000080018:4""
275270
- Capture events from process 73060 where we capture both JIT and R2R events using EventPipe tracing
@@ -280,8 +275,6 @@ public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext c
280275
""perfview collect -LogFile:logOfCollection.txt -DataFile:jittrace.etl -Zip:false -merge:false -providers:Microsoft-Windows-DotNETRuntime:0x1E000080018:4""
281276
- Capture Jit and R2R events via perfview of all processes running using ETW tracing
282277
");
283-
return true;
284-
};
285278
}
286279
}
287280

src/coreclr/tools/dotnet-pgo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public Program(PgoRootCommand command)
163163
private static int Main(string[] args) =>
164164
new CommandLineConfiguration(new PgoRootCommand(args)
165165
.UseVersion()
166-
.UseExtendedHelp(PgoRootCommand.GetExtendedHelp))
166+
.UseExtendedHelp(PgoRootCommand.PrintExtendedHelp))
167167
{
168168
ResponseFileTokenReplacer = Helpers.TryReadResponseFile,
169169
EnableDefaultExceptionHandler = false,

0 commit comments

Comments
 (0)