Skip to content
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
2 changes: 1 addition & 1 deletion eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<Uri>https://github.com/dotnet/llvm-project</Uri>
<Sha>da5dd054a531e6fea65643b7e754285b73eab433</Sha>
</Dependency>
<Dependency Name="System.CommandLine" Version="2.0.0-beta5.25260.104">
<Dependency Name="System.CommandLine" Version="2.0.0-beta5.25279.2">
<Uri>https://github.com/dotnet/dotnet</Uri>
<Sha>85778473549347b3e4bad3ea009e9438df7b11bb</Sha>
</Dependency>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<!-- Not auto-updated. -->
<MicrosoftDiaSymReaderVersion>2.0.0</MicrosoftDiaSymReaderVersion>
<MicrosoftDiaSymReaderNativeVersion>17.10.0-beta1.24272.1</MicrosoftDiaSymReaderNativeVersion>
<SystemCommandLineVersion>2.0.0-beta5.25260.104</SystemCommandLineVersion>
<SystemCommandLineVersion>2.0.0-beta5.25279.2</SystemCommandLineVersion>
<TraceEventVersion>3.1.16</TraceEventVersion>
<NETStandardLibraryRefVersion>2.1.0</NETStandardLibraryRefVersion>
<NetStandardLibraryVersion>2.0.3</NetStandardLibraryVersion>
Expand Down
30 changes: 25 additions & 5 deletions src/coreclr/tools/Common/CommandLineHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine.Help;
using System.Collections.Generic;
using System.CommandLine.Help;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.IO;
using System.IO.Compression;
Expand Down Expand Up @@ -129,15 +130,13 @@ public static RootCommand UseVersion(this RootCommand command)
return command;
}

public static RootCommand UseExtendedHelp(this RootCommand command, Func<HelpContext, IEnumerable<Func<HelpContext, bool>>> customizer)
public static RootCommand UseExtendedHelp(this RootCommand command, Action<ParseResult> customizer)
{
foreach (Option option in command.Options)
{
if (option is HelpOption helpOption)
{
HelpBuilder builder = new();
builder.CustomizeLayout(customizer);
helpOption.Action = new HelpAction { Builder = builder };
helpOption.Action = new CustomizedHelpAction(helpOption, customizer);
break;
}
}
Expand Down Expand Up @@ -427,5 +426,26 @@ public static bool TryReadResponseFile(string filePath, out IReadOnlyList<string
newTokens = null;
return false;
}

private sealed class CustomizedHelpAction : SynchronousCommandLineAction
{
private readonly HelpAction _helpAction;
private readonly Action<ParseResult> _customizer;

public CustomizedHelpAction(HelpOption helpOption, Action<ParseResult> customizer)
{
_helpAction = (HelpAction)helpOption.Action;
_customizer = customizer;
}

public override int Invoke(ParseResult parseResult)
{
int result = _helpAction.Invoke(parseResult);

_customizer(parseResult);

return result;
}
}
}
}
79 changes: 36 additions & 43 deletions src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,64 +329,57 @@ public ILCompilerRootCommand(string[] args) : base(".NET Native IL Compiler")
});
}

public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext _)
public static void PrintExtendedHelp(ParseResult _)
{
foreach (Func<HelpContext, bool> sectionDelegate in HelpBuilder.Default.GetLayout())
yield return sectionDelegate;
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 " +
"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 " +
"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 " +
"only the : syntax for switches is supported.\n");

yield return _ =>
{
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 " +
"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 " +
"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 " +
"only the : syntax for switches is supported.\n");

Console.WriteLine("Use the '--' option to disambiguate between input files that have begin with -- and options. After a '--' option, all arguments are " +
"considered to be input files. If no input files begin with '--' then this option is not necessary.\n");
Console.WriteLine("Use the '--' option to disambiguate between input files that have begin with -- and options. After a '--' option, all arguments are " +
"considered to be input files. If no input files begin with '--' then this option is not necessary.\n");

string[] ValidArchitectures = new string[] { "arm", "arm64", "x86", "x64", "riscv64", "loongarch64" };
string[] ValidOS = new string[] { "windows", "linux", "freebsd", "osx", "maccatalyst", "ios", "iossimulator", "tvos", "tvossimulator" };
string[] ValidArchitectures = new string[] { "arm", "arm64", "x86", "x64", "riscv64", "loongarch64" };
string[] ValidOS = new string[] { "windows", "linux", "freebsd", "osx", "maccatalyst", "ios", "iossimulator", "tvos", "tvossimulator" };

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

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()));
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()));

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

foreach (string arch in ValidArchitectures)
foreach (string arch in ValidArchitectures)
{
TargetArchitecture targetArch = Helpers.GetTargetArchitecture(arch);
bool first = true;
foreach (var instructionSet in Internal.JitInterface.InstructionSetFlags.ArchitectureToValidInstructionSets(targetArch))
{
TargetArchitecture targetArch = Helpers.GetTargetArchitecture(arch);
bool first = true;
foreach (var instructionSet in Internal.JitInterface.InstructionSetFlags.ArchitectureToValidInstructionSets(targetArch))
// Only instruction sets with are specifiable should be printed to the help text
if (instructionSet.Specifiable)
{
// Only instruction sets with are specifiable should be printed to the help text
if (instructionSet.Specifiable)
if (first)
{
if (first)
{
Console.Write(arch);
Console.Write(": ");
first = false;
}
else
{
Console.Write(", ");
}
Console.Write(instructionSet.Name);
Console.Write(arch);
Console.Write(": ");
first = false;
}
else
{
Console.Write(", ");
}
Console.Write(instructionSet.Name);
}

if (first) continue; // no instruction-set found for this architecture

Console.WriteLine();
}

if (first) continue; // no instruction-set found for this architecture

Console.WriteLine();
Console.WriteLine("The following CPU names are predefined groups of instruction sets and can be used in --instruction-set too:");
Console.WriteLine(string.Join(", ", Internal.JitInterface.InstructionSetFlags.AllCpuNames));
return true;
};
}

Console.WriteLine();
Console.WriteLine("The following CPU names are predefined groups of instruction sets and can be used in --instruction-set too:");
Console.WriteLine(string.Join(", ", Internal.JitInterface.InstructionSetFlags.AllCpuNames));
}

private static TargetArchitecture MakeTargetArchitecture(ArgumentResult result)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ private static IEnumerable<int> ProcessWarningCodes(IEnumerable<string> warningC
private static int Main(string[] args) =>
new CommandLineConfiguration(new ILCompilerRootCommand(args)
.UseVersion()
.UseExtendedHelp(ILCompilerRootCommand.GetExtendedHelp))
.UseExtendedHelp(ILCompilerRootCommand.PrintExtendedHelp))
{
ResponseFileTokenReplacer = Helpers.TryReadResponseFile,
EnableDefaultExceptionHandler = false,
Expand Down
99 changes: 46 additions & 53 deletions src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,69 +285,62 @@ public Crossgen2RootCommand(string[] args) : base(SR.Crossgen2BannerText)
});
}

public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext _)
public static void PrintExtendedHelp(ParseResult _)
{
foreach (Func<HelpContext, bool> sectionDelegate in HelpBuilder.Default.GetLayout())
yield return sectionDelegate;

yield return _ =>
Console.WriteLine(SR.OptionPassingHelp);
Console.WriteLine();
Console.WriteLine(SR.DashDashHelp);
Console.WriteLine();

string[] ValidArchitectures = new string[] {"arm", "armel", "arm64", "x86", "x64", "riscv64", "loongarch64"};
string[] ValidOS = new string[] {"windows", "linux", "osx", "ios", "iossimulator", "maccatalyst"};

Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetos", String.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant()));
Console.WriteLine();
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetarch", String.Join("', '", ValidArchitectures), Helpers.GetTargetArchitecture(null).ToString().ToLowerInvariant()));
Console.WriteLine();
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--type-validation", String.Join("', '", Enum.GetNames<TypeValidationRule>()), nameof(TypeValidationRule.Automatic)));
Console.WriteLine();

Console.WriteLine(SR.CrossModuleInliningExtraHelp);
Console.WriteLine();
Console.WriteLine(String.Format(SR.LayoutOptionExtraHelp, "--method-layout", String.Join("', '", Enum.GetNames<MethodLayoutAlgorithm>())));
Console.WriteLine();
Console.WriteLine(String.Format(SR.LayoutOptionExtraHelp, "--file-layout", String.Join("', '", Enum.GetNames<FileLayoutAlgorithm>())));
Console.WriteLine();

Console.WriteLine(SR.InstructionSetHelp);
foreach (string arch in ValidArchitectures)
{
Console.WriteLine(SR.OptionPassingHelp);
Console.WriteLine();
Console.WriteLine(SR.DashDashHelp);
Console.WriteLine();

string[] ValidArchitectures = new string[] {"arm", "armel", "arm64", "x86", "x64", "riscv64", "loongarch64"};
string[] ValidOS = new string[] {"windows", "linux", "osx", "ios", "iossimulator", "maccatalyst"};

Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetos", String.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant()));
Console.WriteLine();
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetarch", String.Join("', '", ValidArchitectures), Helpers.GetTargetArchitecture(null).ToString().ToLowerInvariant()));
Console.WriteLine();
Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--type-validation", String.Join("', '", Enum.GetNames<TypeValidationRule>()), nameof(TypeValidationRule.Automatic)));
Console.WriteLine();

Console.WriteLine(SR.CrossModuleInliningExtraHelp);
Console.WriteLine();
Console.WriteLine(String.Format(SR.LayoutOptionExtraHelp, "--method-layout", String.Join("', '", Enum.GetNames<MethodLayoutAlgorithm>())));
Console.WriteLine();
Console.WriteLine(String.Format(SR.LayoutOptionExtraHelp, "--file-layout", String.Join("', '", Enum.GetNames<FileLayoutAlgorithm>())));
Console.WriteLine();

Console.WriteLine(SR.InstructionSetHelp);
foreach (string arch in ValidArchitectures)
TargetArchitecture targetArch = Helpers.GetTargetArchitecture(arch);
bool first = true;
foreach (var instructionSet in Internal.JitInterface.InstructionSetFlags.ArchitectureToValidInstructionSets(targetArch))
{
TargetArchitecture targetArch = Helpers.GetTargetArchitecture(arch);
bool first = true;
foreach (var instructionSet in Internal.JitInterface.InstructionSetFlags.ArchitectureToValidInstructionSets(targetArch))
// Only instruction sets with are specifiable should be printed to the help text
if (instructionSet.Specifiable)
{
// Only instruction sets with are specifiable should be printed to the help text
if (instructionSet.Specifiable)
if (first)
{
if (first)
{
Console.Write(arch);
Console.Write(": ");
first = false;
}
else
{
Console.Write(", ");
}
Console.Write(instructionSet.Name);
Console.Write(arch);
Console.Write(": ");
first = false;
}
else
{
Console.Write(", ");
}
Console.Write(instructionSet.Name);
}

if (first) continue; // no instruction-set found for this architecture

Console.WriteLine();
}

if (first) continue; // no instruction-set found for this architecture

Console.WriteLine();
Console.WriteLine(SR.CpuFamilies);
Console.WriteLine(string.Join(", ", Internal.JitInterface.InstructionSetFlags.AllCpuNames));
return true;
};
}

Console.WriteLine();
Console.WriteLine(SR.CpuFamilies);
Console.WriteLine(string.Join(", ", Internal.JitInterface.InstructionSetFlags.AllCpuNames));
}

private static TargetArchitecture MakeTargetArchitecture(ArgumentResult result)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ internal static bool IsValidPublicKey(byte[] blob)
private static int Main(string[] args) =>
new CommandLineConfiguration(new Crossgen2RootCommand(args)
.UseVersion()
.UseExtendedHelp(Crossgen2RootCommand.GetExtendedHelp))
.UseExtendedHelp(Crossgen2RootCommand.PrintExtendedHelp))
{
ResponseFileTokenReplacer = Helpers.TryReadResponseFile,
EnableDefaultExceptionHandler = false,
Expand Down
13 changes: 3 additions & 10 deletions src/coreclr/tools/dotnet-pgo/PgoRootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,11 @@ int ExecuteWithContext(ParseResult result, bool setVerbosity)
}
}

public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext context)
public static void PrintExtendedHelp(ParseResult parseResult)
{
foreach (Func<HelpContext, bool> sectionDelegate in HelpBuilder.Default.GetLayout())
yield return sectionDelegate;

if (context.Command.Name == "create-mibc" || context.Command.Name == "create-jittrace")
if (parseResult.CommandResult.Command.Name is "create-mibc" or "create-jittrace")
{
yield return _ =>
{
Console.WriteLine(
Console.WriteLine(
@"Example tracing commands used to generate the input to this tool:
""dotnet-trace collect -p 73060 --providers Microsoft-Windows-DotNETRuntime:0x1E000080018:4""
- Capture events from process 73060 where we capture both JIT and R2R events using EventPipe tracing
Expand All @@ -280,8 +275,6 @@ public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext c
""perfview collect -LogFile:logOfCollection.txt -DataFile:jittrace.etl -Zip:false -merge:false -providers:Microsoft-Windows-DotNETRuntime:0x1E000080018:4""
- Capture Jit and R2R events via perfview of all processes running using ETW tracing
");
return true;
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/dotnet-pgo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public Program(PgoRootCommand command)
private static int Main(string[] args) =>
new CommandLineConfiguration(new PgoRootCommand(args)
.UseVersion()
.UseExtendedHelp(PgoRootCommand.GetExtendedHelp))
.UseExtendedHelp(PgoRootCommand.PrintExtendedHelp))
{
ResponseFileTokenReplacer = Helpers.TryReadResponseFile,
EnableDefaultExceptionHandler = false,
Expand Down
Loading