diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index c4868c14788be3..ac8bc4d738efdc 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -40,14 +40,14 @@ https://github.com/dotnet/llvm-project da5dd054a531e6fea65643b7e754285b73eab433 - + https://github.com/dotnet/command-line-api - feb61c7f328a2401d74f4317b39d02126cfdfe24 + 48bd86bdcd926a194e1581a60d820d12a64ef3c6 - + https://github.com/dotnet/command-line-api - feb61c7f328a2401d74f4317b39d02126cfdfe24 + 48bd86bdcd926a194e1581a60d820d12a64ef3c6 diff --git a/eng/Versions.props b/eng/Versions.props index 637481059e52c5..4b0185cff0c168 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -179,7 +179,7 @@ 2.0.0 17.10.0-beta1.24272.1 - 2.0.0-beta4.24528.1 + 2.0.0-beta5.25208.1 3.1.16 2.1.0 2.0.3 diff --git a/src/coreclr/tools/Common/CommandLineHelpers.cs b/src/coreclr/tools/Common/CommandLineHelpers.cs index 7f93e48a8949f6..ef60fe2d27ff05 100644 --- a/src/coreclr/tools/Common/CommandLineHelpers.cs +++ b/src/coreclr/tools/Common/CommandLineHelpers.cs @@ -24,11 +24,11 @@ internal static partial class Helpers { public const string DefaultSystemModule = "System.Private.CoreLib"; - public static Dictionary BuildPathDictionary(IReadOnlyList tokens, bool strict) + public static Dictionary BuildPathDictionary(IReadOnlyList tokens, bool strict) { Dictionary dictionary = new(StringComparer.OrdinalIgnoreCase); - foreach (CliToken token in tokens) + foreach (Token token in tokens) { AppendExpandedPaths(dictionary, token.Value, strict); } @@ -36,11 +36,11 @@ public static Dictionary BuildPathDictionary(IReadOnlyList BuildPathList(IReadOnlyList tokens) + public static List BuildPathList(IReadOnlyList tokens) { List paths = new(); Dictionary dictionary = new(StringComparer.OrdinalIgnoreCase); - foreach (CliToken token in tokens) + foreach (Token token in tokens) { AppendExpandedPaths(dictionary, token.Value, false); foreach (string file in dictionary.Values) @@ -115,7 +115,7 @@ public static TargetArchitecture GetTargetArchitecture(string token) } } - public static CliRootCommand UseVersion(this CliRootCommand command) + public static RootCommand UseVersion(this RootCommand command) { for (int i = 0; i < command.Options.Count; i++) { @@ -129,9 +129,9 @@ public static CliRootCommand UseVersion(this CliRootCommand command) return command; } - public static CliRootCommand UseExtendedHelp(this CliRootCommand command, Func>> customizer) + public static RootCommand UseExtendedHelp(this RootCommand command, Func>> customizer) { - foreach (CliOption option in command.Options) + foreach (Option option in command.Options) { if (option is HelpOption helpOption) { @@ -209,7 +209,7 @@ public static void MakeReproPackage(string makeReproPath, string outputFilePath, Dictionary outputToReproPackageFileName = new(); List rspFile = new List(); - foreach (CliOption option in res.CommandResult.Command.Options) + foreach (Option option in res.CommandResult.Command.Options) { OptionResult optionResult = res.GetResult(option); if (optionResult is null || option.Name == "--make-repro-path") @@ -266,7 +266,7 @@ public static void MakeReproPackage(string makeReproPath, string outputFilePath, } } - foreach (CliArgument argument in res.CommandResult.Command.Arguments) + foreach (Argument argument in res.CommandResult.Command.Arguments) { ArgumentResult argumentResult = res.GetResult(argument); if (argumentResult is null) diff --git a/src/coreclr/tools/ILVerify/ILVerifyRootCommand.cs b/src/coreclr/tools/ILVerify/ILVerifyRootCommand.cs index 9f5eac54af8e2c..62e1aecba47b24 100644 --- a/src/coreclr/tools/ILVerify/ILVerifyRootCommand.cs +++ b/src/coreclr/tools/ILVerify/ILVerifyRootCommand.cs @@ -8,33 +8,33 @@ namespace ILVerify { - internal sealed class ILVerifyRootCommand : CliRootCommand + internal sealed class ILVerifyRootCommand : RootCommand { - public CliArgument> InputFilePath { get; } = + public Argument> InputFilePath { get; } = new("input-file-path") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, true), Description = "Input file(s)", Arity = ArgumentArity.OneOrMore }; - public CliOption> Reference { get; } = + public Option> Reference { get; } = new("--reference", "-r") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, false), DefaultValueFactory = result => Helpers.BuildPathDictionary(result.Tokens, false), Description = "Reference metadata from the specified assembly" }; - public CliOption SystemModule { get; } = + public Option SystemModule { get; } = new("--system-module", "-s") { Description = "System module name (default: mscorlib)" }; - public CliOption SanityChecks { get; } = + public Option SanityChecks { get; } = new("--sanity-checks", "-c") { Description = "Check for valid constructs that are likely mistakes" }; - public CliOption Include { get; } = + public Option Include { get; } = new("--include", "-i") { Description = "Use only methods/types/namespaces, which match the given regular expression(s)" }; - public CliOption IncludeFile { get; } = - new CliOption("--include-file") { Description = "Same as --include, but the regular expression(s) are declared line by line in the specified file." }.AcceptExistingOnly(); - public CliOption Exclude { get; } = + public Option IncludeFile { get; } = + new Option("--include-file") { Description = "Same as --include, but the regular expression(s) are declared line by line in the specified file." }.AcceptExistingOnly(); + public Option Exclude { get; } = new("--exclude", "-e") { Description = "Skip methods/types/namespaces, which match the given regular expression(s)" }; - public CliOption ExcludeFile { get; } = - new CliOption("--exclude-file") { Description = "Same as --exclude, but the regular expression(s) are declared line by line in the specified file." }.AcceptExistingOnly(); - public CliOption IgnoreError { get; } = + public Option ExcludeFile { get; } = + new Option("--exclude-file") { Description = "Same as --exclude, but the regular expression(s) are declared line by line in the specified file." }.AcceptExistingOnly(); + public Option IgnoreError { get; } = new("--ignore-error", "-g") { Description = "Ignore errors, which match the given regular expression(s)" }; - public CliOption IgnoreErrorFile { get; } = - new CliOption("--ignore-error-file") { Description = "Same as --ignore-error, but the regular expression(s) are declared line by line in the specified file." }.AcceptExistingOnly(); - public CliOption Statistics { get; } = + public Option IgnoreErrorFile { get; } = + new Option("--ignore-error-file") { Description = "Same as --ignore-error, but the regular expression(s) are declared line by line in the specified file." }.AcceptExistingOnly(); + public Option Statistics { get; } = new("--statistics") { Description = "Print verification statistics" }; - public CliOption Verbose { get; } = + public Option Verbose { get; } = new("--verbose") { Description = "Verbose output" }; - public CliOption Tokens { get; } = + public Option Tokens { get; } = new("--tokens", "-t") { Description = "Include metadata tokens in error messages" }; public ParseResult Result; diff --git a/src/coreclr/tools/ILVerify/Program.cs b/src/coreclr/tools/ILVerify/Program.cs index 7dd39082a0c0e4..eae57d8bfd752d 100644 --- a/src/coreclr/tools/ILVerify/Program.cs +++ b/src/coreclr/tools/ILVerify/Program.cs @@ -475,11 +475,11 @@ public PEReader Resolve(string simpleName) return null; } - private T Get(CliOption option) => _command.Result.GetValue(option); - private T Get(CliArgument argument) => _command.Result.GetValue(argument); + private T Get(Option option) => _command.Result.GetValue(option); + private T Get(Argument argument) => _command.Result.GetValue(argument); private static int Main(string[] args) => - new CliConfiguration(new ILVerifyRootCommand().UseVersion()) + new CommandLineConfiguration(new ILVerifyRootCommand().UseVersion()) { ResponseFileTokenReplacer = Helpers.TryReadResponseFile, EnableDefaultExceptionHandler = false, diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs index cca4dddc14669f..60c2616d9f261c 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs +++ b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs @@ -11,167 +11,167 @@ namespace ILCompiler { - internal sealed class ILCompilerRootCommand : CliRootCommand + internal sealed class ILCompilerRootCommand : RootCommand { - public CliArgument> InputFilePaths { get; } = + public Argument> InputFilePaths { get; } = new("input-file-path") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, true), Description = "Input file(s)", Arity = ArgumentArity.OneOrMore }; - public CliOption> ReferenceFiles { get; } = + public Option> ReferenceFiles { get; } = new("--reference", "-r") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, false), DefaultValueFactory = result => Helpers.BuildPathDictionary(result.Tokens, false), Description = "Reference file(s) for compilation" }; - public CliOption OutputFilePath { get; } = + public Option OutputFilePath { get; } = new("--out", "-o") { Description = "Output file path" }; - public CliOption Optimize { get; } = + public Option Optimize { get; } = new("--optimize", "-O") { Description = "Enable optimizations" }; - public CliOption OptimizeSpace { get; } = + public Option OptimizeSpace { get; } = new("--optimize-space", "--Os") { Description = "Enable optimizations, favor code space" }; - public CliOption OptimizeTime { get; } = + public Option OptimizeTime { get; } = new("--optimize-time", "--Ot") { Description = "Enable optimizations, favor code speed" }; - public CliOption MibcFilePaths { get; } = + public Option MibcFilePaths { get; } = new("--mibc", "-m") { DefaultValueFactory = _ => Array.Empty(), Description = "Mibc file(s) for profile guided optimization" }; - public CliOption SatelliteFilePaths { get; } = + public Option SatelliteFilePaths { get; } = new("--satellite") { DefaultValueFactory = _ => Array.Empty(), Description = "Satellite assemblies associated with inputs/references" }; - public CliOption EnableDebugInfo { get; } = + public Option EnableDebugInfo { get; } = new("--debug", "-g") { Description = "Emit debugging information" }; - public CliOption UseDwarf5 { get; } = + public Option UseDwarf5 { get; } = new("--gdwarf-5") { Description = "Generate source-level debug information with dwarf version 5" }; - public CliOption NativeLib { get; } = + public Option NativeLib { get; } = new("--nativelib") { Description = "Compile as static or shared library" }; - public CliOption SplitExeInitialization { get; } = + public Option SplitExeInitialization { get; } = new("--splitinit") { Description = "Split initialization of an executable between the library entrypoint and a main entrypoint" }; - public CliOption ExportsFile { get; } = + public Option ExportsFile { get; } = new("--exportsfile") { Description = "File to write exported symbol and method definitions" }; - public CliOption ExportUnmanagedEntryPoints { get; } = + public Option ExportUnmanagedEntryPoints { get; } = new("--export-unmanaged-entrypoints") { Description = "Controls whether the named UnmanagedCallersOnly methods are exported" }; - public CliOption ExportDynamicSymbols { get; } = + public Option ExportDynamicSymbols { get; } = new("--export-dynamic-symbol") { Description = "Add dynamic export symbol to exports file" }; - public CliOption DgmlLogFileName { get; } = + public Option DgmlLogFileName { get; } = new("--dgmllog") { Description = "Save result of dependency analysis as DGML" }; - public CliOption GenerateFullDgmlLog { get; } = + public Option GenerateFullDgmlLog { get; } = new("--fulllog") { Description = "Save detailed log of dependency analysis" }; - public CliOption ScanDgmlLogFileName { get; } = + public Option ScanDgmlLogFileName { get; } = new("--scandgmllog") { Description = "Save result of scanner dependency analysis as DGML" }; - public CliOption GenerateFullScanDgmlLog { get; } = + public Option GenerateFullScanDgmlLog { get; } = new("--scanfulllog") { Description = "Save detailed log of scanner dependency analysis" }; - public CliOption IsVerbose { get; } = + public Option IsVerbose { get; } = new("--verbose") { Description = "Enable verbose logging" }; - public CliOption SystemModuleName { get; } = + public Option SystemModuleName { get; } = new("--systemmodule") { DefaultValueFactory = _ => Helpers.DefaultSystemModule, Description = "System module name (default: System.Private.CoreLib)" }; - public CliOption Win32ResourceModuleName { get; } = + public Option Win32ResourceModuleName { get; } = new("--win32resourcemodule") { Description = "Name of the module from which to copy Win32 resources (Windows target only)" }; - public CliOption MultiFile { get; } = + public Option MultiFile { get; } = new("--multifile") { Description = "Compile only input files (do not compile referenced assemblies)" }; - public CliOption WaitForDebugger { get; } = + public Option WaitForDebugger { get; } = new("--waitfordebugger") { Description = "Pause to give opportunity to attach debugger" }; - public CliOption Resilient { get; } = + public Option Resilient { get; } = new("--resilient") { Description = "Ignore unresolved types, methods, and assemblies. Defaults to false" }; - public CliOption CodegenOptions { get; } = + public Option CodegenOptions { get; } = new("--codegenopt") { DefaultValueFactory = _ => Array.Empty(), Description = "Define a codegen option" }; - public CliOption RdXmlFilePaths { get; } = + public Option RdXmlFilePaths { get; } = new("--rdxml") { DefaultValueFactory = _ => Array.Empty(), Description = "RD.XML file(s) for compilation" }; - public CliOption LinkTrimFilePaths { get; } = + public Option LinkTrimFilePaths { get; } = new("--descriptor") { DefaultValueFactory = _ => Array.Empty(), Description = "ILLink.Descriptor file(s) for compilation" }; - public CliOption SubstitutionFilePaths { get; } = + public Option SubstitutionFilePaths { get; } = new("--substitution") { DefaultValueFactory = _ => Array.Empty(), Description = "ILLink.Substitution file(s) for compilation" }; - public CliOption MapFileName { get; } = + public Option MapFileName { get; } = new("--map") { Description = "Generate a map file" }; - public CliOption MstatFileName { get; } = + public Option MstatFileName { get; } = new("--mstat") { Description = "Generate an mstat file" }; - public CliOption SourceLinkFileName { get; } = + public Option SourceLinkFileName { get; } = new("--sourcelink") { Description = "Generate a SourceLink file" }; - public CliOption MetadataLogFileName { get; } = + public Option MetadataLogFileName { get; } = new("--metadatalog") { Description = "Generate a metadata log file" }; - public CliOption CompleteTypesMetadata { get; } = + public Option CompleteTypesMetadata { get; } = new("--completetypemetadata") { Description = "Generate complete metadata for types" }; - public CliOption ReflectionData { get; } = + public Option ReflectionData { get; } = new("--reflectiondata") { Description = "Reflection data to generate (one of: all, none)" }; - public CliOption ScanReflection { get; } = + public Option ScanReflection { get; } = new("--scanreflection") { Description = "Scan IL for reflection patterns" }; - public CliOption UseScanner { get; } = + public Option UseScanner { get; } = new("--scan") { Description = "Use IL scanner to generate optimized code (implied by -O)" }; - public CliOption NoScanner { get; } = + public Option NoScanner { get; } = new("--noscan") { Description = "Do not use IL scanner to generate optimized code" }; - public CliOption IlDump { get; } = + public Option IlDump { get; } = new("--ildump") { Description = "Dump IL assembly listing for compiler-generated IL" }; - public CliOption NoInlineTls { get; } = + public Option NoInlineTls { get; } = new("--noinlinetls") { Description = "Do not generate inline thread local statics" }; - public CliOption EmitStackTraceData { get; } = + public Option EmitStackTraceData { get; } = new("--stacktracedata") { Description = "Emit data to support generating stack trace strings at runtime" }; - public CliOption MethodBodyFolding { get; } = + public Option MethodBodyFolding { get; } = new("--methodbodyfolding") { Description = "Fold identical method bodies" }; - public CliOption InitAssemblies { get; } = + public Option InitAssemblies { get; } = new("--initassembly") { DefaultValueFactory = _ => Array.Empty(), Description = "Assembly(ies) with a library initializer" }; - public CliOption FeatureSwitches { get; } = + public Option FeatureSwitches { get; } = new("--feature") { DefaultValueFactory = _ => Array.Empty(), Description = "Feature switches to apply (format: 'Namespace.Name=[true|false]'" }; - public CliOption RuntimeOptions { get; } = + public Option RuntimeOptions { get; } = new("--runtimeopt") { DefaultValueFactory = _ => Array.Empty(), Description = "Runtime options to set" }; - public CliOption RuntimeKnobs { get; } = + public Option RuntimeKnobs { get; } = new("--runtimeknob") { DefaultValueFactory = _ => Array.Empty(), Description = "Runtime knobs to set" }; - public CliOption Parallelism { get; } = + public Option Parallelism { get; } = new("--parallelism") { CustomParser = MakeParallelism, DefaultValueFactory = MakeParallelism, Description = "Maximum number of threads to use during compilation" }; - public CliOption InstructionSet { get; } = + public Option InstructionSet { get; } = new("--instruction-set") { Description = "Instruction set to allow or disallow" }; - public CliOption MaxVectorTBitWidth { get; } = + public Option MaxVectorTBitWidth { get; } = new("--max-vectort-bitwidth") { Description = "Maximum width, in bits, that Vector is allowed to be" }; - public CliOption Guard { get; } = + public Option Guard { get; } = new("--guard") { Description = "Enable mitigations. Options: 'cf': CFG (Control Flow Guard, Windows only)" }; - public CliOption Dehydrate { get; } = + public Option Dehydrate { get; } = new("--dehydrate") { Description = "Dehydrate runtime data structures" }; - public CliOption PreinitStatics { get; } = + public Option PreinitStatics { get; } = new("--preinitstatics") { Description = "Interpret static constructors at compile time if possible (implied by -O)" }; - public CliOption NoPreinitStatics { get; } = + public Option NoPreinitStatics { get; } = new("--nopreinitstatics") { Description = "Do not interpret static constructors at compile time" }; - public CliOption InstrumentReachability { get; } = + public Option InstrumentReachability { get; } = new("--reachabilityinstrument") { Description = "Instrument code for dynamic reachability" }; - public CliOption UseReachability { get; } = + public Option UseReachability { get; } = new("--reachabilityuse") { Description = "Use dynamic reachability instrumentation data to produce minimal output" }; - public CliOption SuppressedWarnings { get; } = + public Option SuppressedWarnings { get; } = new("--nowarn") { DefaultValueFactory = _ => Array.Empty(), Description = "Disable specific warning messages" }; - public CliOption SingleWarn { get; } = + public Option SingleWarn { get; } = new("--singlewarn") { Description = "Generate single AOT/trimming warning per assembly" }; - public CliOption NoTrimWarn { get; } = + public Option NoTrimWarn { get; } = new("--notrimwarn") { Description = "Disable warnings related to trimming" }; - public CliOption NoAotWarn { get; } = + public Option NoAotWarn { get; } = new("--noaotwarn") { Description = "Disable warnings related to AOT" }; - public CliOption SingleWarnEnabledAssemblies { get; } = + public Option SingleWarnEnabledAssemblies { get; } = new("--singlewarnassembly") { DefaultValueFactory = _ => Array.Empty(), Description = "Generate single AOT/trimming warning for given assembly" }; - public CliOption SingleWarnDisabledAssemblies { get; } = + public Option SingleWarnDisabledAssemblies { get; } = new("--nosinglewarnassembly") { DefaultValueFactory = _ => Array.Empty(), Description = "Expand AOT/trimming warnings for given assembly" }; - public CliOption TreatWarningsAsErrors { get; } = + public Option TreatWarningsAsErrors { get; } = new("--warnaserror") { Description = "Treat warnings as errors" }; - public CliOption WarningsAsErrorsEnable { get; } = + public Option WarningsAsErrorsEnable { get; } = new("--warnaserr") { Description = "Enable treating specific warnings as errors" }; - public CliOption WarningsAsErrorsDisable { get; } = + public Option WarningsAsErrorsDisable { get; } = new("--nowarnaserr") { Description = "Disable treating specific warnings as errors" }; - public CliOption DirectPInvokes { get; } = + public Option DirectPInvokes { get; } = new("--directpinvoke") { DefaultValueFactory = _ => Array.Empty(), Description = "PInvoke to call directly" }; - public CliOption DirectPInvokeLists { get; } = + public Option DirectPInvokeLists { get; } = new("--directpinvokelist") { DefaultValueFactory = _ => Array.Empty(), Description = "File with list of PInvokes to call directly" }; - public CliOption RootedAssemblies { get; } = + public Option RootedAssemblies { get; } = new("--root") { DefaultValueFactory = _ => Array.Empty(), Description = "Fully generate given assembly" }; - public CliOption ConditionallyRootedAssemblies { get; } = + public Option ConditionallyRootedAssemblies { get; } = new("--conditionalroot") { DefaultValueFactory = _ => Array.Empty(), Description = "Fully generate given assembly if it's used" }; - public CliOption TrimmedAssemblies { get; } = + public Option TrimmedAssemblies { get; } = new("--trim") { DefaultValueFactory = _ => Array.Empty(), Description = "Trim the specified assembly" }; - public CliOption RootDefaultAssemblies { get; } = + public Option RootDefaultAssemblies { get; } = new("--defaultrooting") { Description = "Root assemblies that are not marked [IsTrimmable]" }; - public CliOption TargetArchitecture { get; } = + public Option TargetArchitecture { get; } = new("--targetarch") { CustomParser = MakeTargetArchitecture, DefaultValueFactory = MakeTargetArchitecture, Description = "Target architecture for cross compilation", HelpName = "arg" }; - public CliOption TargetOS { get; } = + public Option TargetOS { get; } = new("--targetos") { CustomParser = result => Helpers.GetTargetOS(result.Tokens.Count > 0 ? result.Tokens[0].Value : null), DefaultValueFactory = result => Helpers.GetTargetOS(result.Tokens.Count > 0 ? result.Tokens[0].Value : null), Description = "Target OS for cross compilation", HelpName = "arg" }; - public CliOption JitPath { get; } = + public Option JitPath { get; } = new("--jitpath") { Description = "Path to JIT compiler library" }; - public CliOption SingleMethodTypeName { get; } = + public Option SingleMethodTypeName { get; } = new("--singlemethodtypename") { Description = "Single method compilation: assembly-qualified name of the owning type" }; - public CliOption SingleMethodName { get; } = + public Option SingleMethodName { get; } = new("--singlemethodname") { Description = "Single method compilation: name of the method" }; - public CliOption MaxGenericCycleDepth { get; } = + public Option MaxGenericCycleDepth { get; } = new("--maxgenericcycle") { DefaultValueFactory = _ => CompilerTypeSystemContext.DefaultGenericCycleDepthCutoff, Description = "Max depth of generic cycle" }; - public CliOption MaxGenericCycleBreadth { get; } = + public Option MaxGenericCycleBreadth { get; } = new("--maxgenericcyclebreadth") { DefaultValueFactory = _ => CompilerTypeSystemContext.DefaultGenericCycleBreadthCutoff, Description = "Max breadth of generic cycle expansion" }; - public CliOption SingleMethodGenericArgs { get; } = + public Option SingleMethodGenericArgs { get; } = new("--singlemethodgenericarg") { Description = "Single method compilation: generic arguments to the method" }; - public CliOption MakeReproPath { get; } = + public Option MakeReproPath { get; } = new("--make-repro-path") { Description = "Path where to place a repro package" }; - public CliOption UnmanagedEntryPointsAssemblies { get; } = + public Option UnmanagedEntryPointsAssemblies { get; } = new("--generateunmanagedentrypoints") { DefaultValueFactory = _ => Array.Empty(), Description = "Generate unmanaged entrypoints for a given assembly" }; public OptimizationMode OptimizationMode { get; private set; } diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs index e9e7daa9691bad..0420a555eb3c5f 100644 --- a/src/coreclr/tools/aot/ILCompiler/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/Program.cs @@ -784,10 +784,10 @@ private static IEnumerable ProcessWarningCodes(IEnumerable warningC } } - private T Get(CliOption option) => _command.Result.GetValue(option); + private T Get(Option option) => _command.Result.GetValue(option); private static int Main(string[] args) => - new CliConfiguration(new ILCompilerRootCommand(args) + new CommandLineConfiguration(new ILCompilerRootCommand(args) .UseVersion() .UseExtendedHelp(ILCompilerRootCommand.GetExtendedHelp)) { diff --git a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs index 64b78d35500ac5..c70d226212b6ec 100644 --- a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs +++ b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs @@ -13,136 +13,136 @@ namespace ILCompiler { - internal class Crossgen2RootCommand : CliRootCommand + internal class Crossgen2RootCommand : RootCommand { - public CliArgument> InputFilePaths { get; } = + public Argument> InputFilePaths { get; } = new("input-file-path") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, true), Description = "Input file(s)", Arity = ArgumentArity.OneOrMore }; - public CliOption> UnrootedInputFilePaths { get; } = + public Option> UnrootedInputFilePaths { get; } = new("--unrooted-input-file-paths", "-u") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, true), DefaultValueFactory = result => Helpers.BuildPathDictionary(result.Tokens, true), Description = SR.UnrootedInputFilesToCompile }; - public CliOption> ReferenceFilePaths { get; } = + public Option> ReferenceFilePaths { get; } = new("--reference", "-r") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, false), DefaultValueFactory = result => Helpers.BuildPathDictionary(result.Tokens, false), Description = SR.ReferenceFiles }; - public CliOption InstructionSet { get; } = + public Option InstructionSet { get; } = new("--instruction-set") { Description = SR.InstructionSets }; - public CliOption MaxVectorTBitWidth { get; } = + public Option MaxVectorTBitWidth { get; } = new("--max-vectort-bitwidth") { Description = SR.MaxVectorTBitWidths }; - public CliOption MibcFilePaths { get; } = + public Option MibcFilePaths { get; } = new("--mibc", "-m") { DefaultValueFactory = _ => Array.Empty(), Description = SR.MibcFiles }; - public CliOption OutputFilePath { get; } = + public Option OutputFilePath { get; } = new("--out", "-o") { Description = SR.OutputFilePath }; - public CliOption CompositeRootPath { get; } = + public Option CompositeRootPath { get; } = new("--compositerootpath", "--crp") { Description = SR.CompositeRootPath }; - public CliOption Optimize { get; } = + public Option Optimize { get; } = new("--optimize", "-O") { Description = SR.EnableOptimizationsOption }; - public CliOption OptimizeDisabled { get; } = + public Option OptimizeDisabled { get; } = new("--optimize-disabled", "--Od") { Description = SR.DisableOptimizationsOption }; - public CliOption OptimizeSpace { get; } = + public Option OptimizeSpace { get; } = new("--optimize-space", "--Os") { Description = SR.OptimizeSpaceOption }; - public CliOption OptimizeTime { get; } = + public Option OptimizeTime { get; } = new("--optimize-time", "--Ot") { Description = SR.OptimizeSpeedOption }; - public CliOption EnableCachedInterfaceDispatchSupport { get; } = + public Option EnableCachedInterfaceDispatchSupport { get; } = new("--enable-cached-interface-dispatch-support", "--CID") { Description = SR.EnableCachedInterfaceDispatchSupport }; - public CliOption TypeValidation { get; } = + public Option TypeValidation { get; } = new("--type-validation") { DefaultValueFactory = _ => TypeValidationRule.Automatic, Description = SR.TypeValidation, HelpName = "arg" }; - public CliOption InputBubble { get; } = + public Option InputBubble { get; } = new("--inputbubble") { Description = SR.InputBubbleOption }; - public CliOption> InputBubbleReferenceFilePaths { get; } = + public Option> InputBubbleReferenceFilePaths { get; } = new("--inputbubbleref") { CustomParser = result => Helpers.BuildPathDictionary(result.Tokens, false), DefaultValueFactory = result => Helpers.BuildPathDictionary(result.Tokens, false), Description = SR.InputBubbleReferenceFiles }; - public CliOption Composite { get; } = + public Option Composite { get; } = new("--composite") { Description = SR.CompositeBuildMode }; - public CliOption CompositeKeyFile { get; } = + public Option CompositeKeyFile { get; } = new("--compositekeyfile") { Description = SR.CompositeKeyFile }; - public CliOption CompileNoMethods { get; } = + public Option CompileNoMethods { get; } = new("--compile-no-methods") { Description = SR.CompileNoMethodsOption }; - public CliOption OutNearInput { get; } = + public Option OutNearInput { get; } = new("--out-near-input") { Description = SR.OutNearInputOption }; - public CliOption SingleFileCompilation { get; } = + public Option SingleFileCompilation { get; } = new("--single-file-compilation") { Description = SR.SingleFileCompilationOption }; - public CliOption Partial { get; } = + public Option Partial { get; } = new("--partial") { Description = SR.PartialImageOption }; - public CliOption CompileBubbleGenerics { get; } = + public Option CompileBubbleGenerics { get; } = new("--compilebubblegenerics") { Description = SR.BubbleGenericsOption }; - public CliOption EmbedPgoData { get; } = + public Option EmbedPgoData { get; } = new("--embed-pgo-data") { Description = SR.EmbedPgoDataOption }; - public CliOption DgmlLogFileName { get; } = + public Option DgmlLogFileName { get; } = new("--dgmllog") { Description = SR.SaveDependencyLogOption }; - public CliOption GenerateFullDgmlLog { get; } = + public Option GenerateFullDgmlLog { get; } = new("--fulllog") { Description = SR.SaveDetailedLogOption }; - public CliOption IsVerbose { get; } = + public Option IsVerbose { get; } = new("--verbose") { Description = SR.VerboseLoggingOption }; - public CliOption SystemModuleName { get; } = + public Option SystemModuleName { get; } = new("--systemmodule") { DefaultValueFactory = _ => Helpers.DefaultSystemModule, Description = SR.SystemModuleOverrideOption }; - public CliOption WaitForDebugger { get; } = + public Option WaitForDebugger { get; } = new("--waitfordebugger") { Description = SR.WaitForDebuggerOption }; - public CliOption CodegenOptions { get; } = + public Option CodegenOptions { get; } = new("--codegenopt") { DefaultValueFactory = _ => Array.Empty(), Description = SR.CodeGenOptions }; - public CliOption SupportIbc { get; } = + public Option SupportIbc { get; } = new("--support-ibc") { Description = SR.SupportIbc }; - public CliOption Resilient { get; } = + public Option Resilient { get; } = new("--resilient") { Description = SR.ResilientOption }; - public CliOption ImageBase { get; } = + public Option ImageBase { get; } = new("--imagebase") { Description = SR.ImageBase }; - public CliOption TargetArchitecture { get; } = + public Option TargetArchitecture { get; } = new("--targetarch") { CustomParser = MakeTargetArchitecture, DefaultValueFactory = MakeTargetArchitecture, Description = SR.TargetArchOption, Arity = ArgumentArity.OneOrMore, HelpName = "arg" }; - public CliOption EnableGenericCycleDetection { get; } = + public Option EnableGenericCycleDetection { get; } = new("--enable-generic-cycle-detection") { Description = SR.EnableGenericCycleDetection }; - public CliOption GenericCycleDepthCutoff { get; } = + public Option GenericCycleDepthCutoff { get; } = new("--maxgenericcycle") { DefaultValueFactory = _ => ReadyToRunCompilerContext.DefaultGenericCycleDepthCutoff, Description = SR.GenericCycleDepthCutoff }; - public CliOption GenericCycleBreadthCutoff { get; } = + public Option GenericCycleBreadthCutoff { get; } = new("--maxgenericcyclebreadth") { DefaultValueFactory = _ => ReadyToRunCompilerContext.DefaultGenericCycleBreadthCutoff, Description = SR.GenericCycleBreadthCutoff }; - public CliOption TargetOS { get; } = + public Option TargetOS { get; } = new("--targetos") { CustomParser = result => Helpers.GetTargetOS(result.Tokens.Count > 0 ? result.Tokens[0].Value : null), DefaultValueFactory = result => Helpers.GetTargetOS(result.Tokens.Count > 0 ? result.Tokens[0].Value : null), Description = SR.TargetOSOption, HelpName = "arg" }; - public CliOption JitPath { get; } = + public Option JitPath { get; } = new("--jitpath") { Description = SR.JitPathOption }; - public CliOption PrintReproInstructions { get; } = + public Option PrintReproInstructions { get; } = new("--print-repro-instructions") { Description = SR.PrintReproInstructionsOption }; - public CliOption SingleMethodTypeName { get; } = + public Option SingleMethodTypeName { get; } = new("--singlemethodtypename") { Description = SR.SingleMethodTypeName }; - public CliOption SingleMethodName { get; } = + public Option SingleMethodName { get; } = new("--singlemethodname") { Description = SR.SingleMethodMethodName }; - public CliOption SingleMethodIndex { get; } = + public Option SingleMethodIndex { get; } = new("--singlemethodindex") { Description = SR.SingleMethodIndex }; - public CliOption SingleMethodGenericArgs { get; } = + public Option SingleMethodGenericArgs { get; } = new("--singlemethodgenericarg") { Description = SR.SingleMethodGenericArgs }; - public CliOption Parallelism { get; } = + public Option Parallelism { get; } = new("--parallelism") { CustomParser = MakeParallelism, DefaultValueFactory = MakeParallelism, Description = SR.ParalellismOption }; - public CliOption CustomPESectionAlignment { get; } = + public Option CustomPESectionAlignment { get; } = new("--custom-pe-section-alignment") { Description = SR.CustomPESectionAlignmentOption }; - public CliOption Map { get; } = + public Option Map { get; } = new("--map") { Description = SR.MapFileOption }; - public CliOption MapCsv { get; } = + public Option MapCsv { get; } = new("--mapcsv") { Description = SR.MapCsvFileOption }; - public CliOption Pdb { get; } = + public Option Pdb { get; } = new("--pdb") { Description = SR.PdbFileOption }; - public CliOption PdbPath { get; } = + public Option PdbPath { get; } = new("--pdb-path") { Description = SR.PdbFilePathOption }; - public CliOption PerfMap { get; } = + public Option PerfMap { get; } = new("--perfmap") { Description = SR.PerfMapFileOption }; - public CliOption PerfMapPath { get; } = + public Option PerfMapPath { get; } = new("--perfmap-path") { Description = SR.PerfMapFilePathOption }; - public CliOption PerfMapFormatVersion { get; } = + public Option PerfMapFormatVersion { get; } = new("--perfmap-format-version") { DefaultValueFactory = _ => 0, Description = SR.PerfMapFormatVersionOption }; - public CliOption CrossModuleInlining { get; } = + public Option CrossModuleInlining { get; } = new("--opt-cross-module") { Description = SR.CrossModuleInlining }; - public CliOption AsyncMethodOptimization { get; } = + public Option AsyncMethodOptimization { get; } = new("--opt-async-methods") { Description = SR.AsyncModuleOptimization }; - public CliOption NonLocalGenericsModule { get; } = + public Option NonLocalGenericsModule { get; } = new("--non-local-generics-module") { DefaultValueFactory = _ => string.Empty, Description = SR.NonLocalGenericsModule }; - public CliOption MethodLayout { get; } = + public Option MethodLayout { get; } = new("--method-layout") { CustomParser = MakeReadyToRunMethodLayoutAlgorithm, DefaultValueFactory = MakeReadyToRunMethodLayoutAlgorithm, Description = SR.MethodLayoutOption, HelpName = "arg" }; - public CliOption FileLayout { get; } = + public Option FileLayout { get; } = new("--file-layout") { CustomParser = MakeReadyToRunFileLayoutAlgorithm, DefaultValueFactory = MakeReadyToRunFileLayoutAlgorithm, Description = SR.FileLayoutOption, HelpName = "arg" }; - public CliOption VerifyTypeAndFieldLayout { get; } = + public Option VerifyTypeAndFieldLayout { get; } = new("--verify-type-and-field-layout") { Description = SR.VerifyTypeAndFieldLayoutOption }; - public CliOption CallChainProfileFile { get; } = + public Option CallChainProfileFile { get; } = new("--callchain-profile") { Description = SR.CallChainProfileFile }; - public CliOption MakeReproPath { get; } = + public Option MakeReproPath { get; } = new("--make-repro-path") { Description = "Path where to place a repro package" }; - public CliOption HotColdSplitting { get; } = + public Option HotColdSplitting { get; } = new("--hot-cold-splitting") { Description = SR.HotColdSplittingOption }; - public CliOption SynthesizeRandomMibc { get; } = + public Option SynthesizeRandomMibc { get; } = new("--synthesize-random-mibc"); - public CliOption DeterminismStress { get; } = + public Option DeterminismStress { get; } = new("--determinism-stress"); public bool CompositeOrInputBubble { get; private set; } diff --git a/src/coreclr/tools/aot/crossgen2/Program.cs b/src/coreclr/tools/aot/crossgen2/Program.cs index 0b5c00c95c6717..71ecb43734fd77 100644 --- a/src/coreclr/tools/aot/crossgen2/Program.cs +++ b/src/coreclr/tools/aot/crossgen2/Program.cs @@ -909,10 +909,10 @@ internal static bool IsValidPublicKey(byte[] blob) return true; } - private T Get(CliOption option) => _command.Result.GetValue(option); + private T Get(Option option) => _command.Result.GetValue(option); private static int Main(string[] args) => - new CliConfiguration(new Crossgen2RootCommand(args) + new CommandLineConfiguration(new Crossgen2RootCommand(args) .UseVersion() .UseExtendedHelp(Crossgen2RootCommand.GetExtendedHelp)) { diff --git a/src/coreclr/tools/cdac-build-tool/ComposeCommand.cs b/src/coreclr/tools/cdac-build-tool/ComposeCommand.cs index adb3675695941a..36b1576dd0a5d5 100644 --- a/src/coreclr/tools/cdac-build-tool/ComposeCommand.cs +++ b/src/coreclr/tools/cdac-build-tool/ComposeCommand.cs @@ -8,15 +8,15 @@ namespace Microsoft.DotNet.Diagnostics.DataContract.BuildTool; -internal sealed class ComposeCommand : CliCommand +internal sealed class ComposeCommand : Command { - private readonly CliArgument inputFiles = new("INPUT [INPUTS...]") { Arity = ArgumentArity.OneOrMore, Description = "One or more input files" }; - private readonly CliOption outputFile = new("-o") { Arity = ArgumentArity.ExactlyOne, HelpName = "OUTPUT", Required = true, Description = "Output file" }; - private readonly CliOption contractFile = new("-c") { Arity = ArgumentArity.ZeroOrMore, HelpName = "CONTRACT", Description = "Contract file (may be specified multiple times)" }; - private readonly CliOption baselinePath = new("-b", "--baseline") { Arity = ArgumentArity.ExactlyOne, HelpName = "BASELINEPATH", Description = "Directory containing the baseline contracts"}; - private readonly CliOption templateFile = new("-i", "--input-template") { Arity = ArgumentArity.ExactlyOne, HelpName = "TEMPLATE", Description = "Contract descriptor template to be filled in" }; - private readonly CliOption _verboseOption; - public ComposeCommand(CliOption verboseOption) : base("compose") + private readonly Argument inputFiles = new("INPUT [INPUTS...]") { Arity = ArgumentArity.OneOrMore, Description = "One or more input files" }; + private readonly Option outputFile = new("-o") { Arity = ArgumentArity.ExactlyOne, HelpName = "OUTPUT", Required = true, Description = "Output file" }; + private readonly Option contractFile = new("-c") { Arity = ArgumentArity.ZeroOrMore, HelpName = "CONTRACT", Description = "Contract file (may be specified multiple times)" }; + private readonly Option baselinePath = new("-b", "--baseline") { Arity = ArgumentArity.ExactlyOne, HelpName = "BASELINEPATH", Description = "Directory containing the baseline contracts"}; + private readonly Option templateFile = new("-i", "--input-template") { Arity = ArgumentArity.ExactlyOne, HelpName = "TEMPLATE", Description = "Contract descriptor template to be filled in" }; + private readonly Option _verboseOption; + public ComposeCommand(Option verboseOption) : base("compose") { _verboseOption = verboseOption; Add(inputFiles); diff --git a/src/coreclr/tools/cdac-build-tool/Program.cs b/src/coreclr/tools/cdac-build-tool/Program.cs index bf86ebec0db4cd..c4b0b9d33ac9ab 100644 --- a/src/coreclr/tools/cdac-build-tool/Program.cs +++ b/src/coreclr/tools/cdac-build-tool/Program.cs @@ -10,8 +10,8 @@ public class Program { public static async Task Main(string[] args) { - CliRootCommand rootCommand = new(); - var verboseOption = new CliOption("-v", "--verbose") {Recursive = true, Description = "Verbose"}; + RootCommand rootCommand = new(); + var verboseOption = new Option("-v", "--verbose") {Recursive = true, Description = "Verbose"}; rootCommand.Add(verboseOption); rootCommand.Add(new DiagramDirective()); rootCommand.Add(new ComposeCommand(verboseOption)); diff --git a/src/coreclr/tools/dotnet-pgo/PgoRootCommand.cs b/src/coreclr/tools/dotnet-pgo/PgoRootCommand.cs index f7a7b7edd66c30..a0a6423b11fda6 100644 --- a/src/coreclr/tools/dotnet-pgo/PgoRootCommand.cs +++ b/src/coreclr/tools/dotnet-pgo/PgoRootCommand.cs @@ -13,64 +13,64 @@ namespace Microsoft.Diagnostics.Tools.Pgo { - internal sealed class PgoRootCommand : CliRootCommand + internal sealed class PgoRootCommand : RootCommand { - public CliOption> InputFilesToMerge { get; } = + public Option> InputFilesToMerge { get; } = new("--input", "-i") { CustomParser = result => Helpers.BuildPathList(result.Tokens), Description = "Input .mibc files to be merged. Multiple input arguments are specified as --input file1.mibc --input file2.mibc", Required = true, Arity = ArgumentArity.OneOrMore }; - public CliOption InputFilesToCompare { get; } = + public Option InputFilesToCompare { get; } = new("--input", "-i") { Description = "The input .mibc files to be compared. Specify as --input file1.mibc --input file2.mibc", Required = true, Arity = new ArgumentArity(2, 2) /* exactly two */ }; - public CliOption InputFileToDump { get; } = + public Option InputFileToDump { get; } = new("--input", "-i") { Description = "Name of the input mibc file to dump", Required = true, Arity = ArgumentArity.ExactlyOne }; - public CliOption TraceFilePath { get; } = + public Option TraceFilePath { get; } = new("--trace", "-t") { Description = "Specify the trace file to be parsed" }; - public CliOption OutputFilePath { get; } = + public Option OutputFilePath { get; } = new("--output", "-o") { Description = "Specify the output filename to be created" }; - public CliOption PreciseDebugInfoFile { get; } = + public Option PreciseDebugInfoFile { get; } = new("--precise-debug-info-file") { Description = "Name of file of newline separated JSON objects containing precise debug info" }; - public CliOption Pid { get; } = + public Option Pid { get; } = new("--pid") { Description = "The pid within the trace of the process to examine. If this is a multi-process trace, at least one of --pid or --process-name must be specified" }; - public CliOption ProcessName { get; } = + public Option ProcessName { get; } = new("--process-name") { Description = "The process name within the trace of the process to examine. If this is a multi-process trace, at least one of --pid or --process-name must be specified" }; - public CliOption> Reference = + public Option> Reference = new("--reference", "-r") { CustomParser = result => Helpers.BuildPathList(result.Tokens), DefaultValueFactory = result => Helpers.BuildPathList(result.Tokens), Description = "If a reference is not located on disk at the same location as used in the process, it may be specified with a --reference parameter. Multiple --reference parameters may be specified. The wild cards * and ? are supported by this option" }; - public CliOption ClrInstanceId { get; } = + public Option ClrInstanceId { get; } = new("--clr-instance-id") { Description = "If the process contains multiple .NET runtimes, the instance ID must be specified" }; - public CliOption Spgo { get; } = + public Option Spgo { get; } = new("--spgo") { Description = "Base profile on samples in the input. Uses last branch records if available and otherwise raw IP samples" }; - public CliOption SpgoMinSamples { get; } = + public Option SpgoMinSamples { get; } = new("--spgo-min-samples") { DefaultValueFactory = _ => 50, Description = "The minimum number of total samples a function must have before generating profile data for it with SPGO. Default: 50" }; - public CliOption IncludeFullGraphs { get; } = + public Option IncludeFullGraphs { get; } = new("--include-full-graphs") { Description = "Include all blocks and edges in the written .mibc file, regardless of profile counts" }; - public CliOption ExcludeEventsBefore { get; } = + public Option ExcludeEventsBefore { get; } = new("--exclude-events-before") { DefaultValueFactory = _ => Double.MinValue, Description = "Exclude data from events before specified time. Time is specified as milliseconds from the start of the trace" }; - public CliOption ExcludeEventsAfter { get; } = + public Option ExcludeEventsAfter { get; } = new("--exclude-events-after") { DefaultValueFactory = _ => Double.MaxValue, Description = "Exclude data from events after specified time. Time is specified as milliseconds from the start of the trace" }; - public CliOption ExcludeEventsBeforeJittingMethod { get; } = + public Option ExcludeEventsBeforeJittingMethod { get; } = new("--exclude-events-before-jitting-method") { DefaultValueFactory = _ => string.Empty, Description = "Exclude data from events before observing a specific method getting jitted. Method is matched using a regular expression against the method name. Note that the method name is formatted the same as in PerfView which includes typed parameters." }; - public CliOption ExcludeEventsAfterJittingMethod { get; } = + public Option ExcludeEventsAfterJittingMethod { get; } = new("--exclude-events-after-jitting-method") { DefaultValueFactory = _ => string.Empty, Description = "Exclude data from events after observing a specific method getting jitted. Method is matched using a regular expression against the method name. Note that the method name is formatted the same as in PerfView which includes typed parameters." }; - public CliOption IncludeMethods { get; } = + public Option IncludeMethods { get; } = new("--include-methods") { DefaultValueFactory = _ => string.Empty, Description = "Include methods with names matching regular expression. Note that the method names are formatted the same as in PerfView which includes typed parameters." }; - public CliOption ExcludeMethods { get; } = + public Option ExcludeMethods { get; } = new("--exclude-methods") { DefaultValueFactory = _ => string.Empty, Description = "Exclude methods with names matching regular expression. Note that the method names are formatted the same as in PerfView which includes typed parameters." }; - public CliOption Compressed { get; } = + public Option Compressed { get; } = new("--compressed") { DefaultValueFactory = _ => true, Description = "Generate compressed mibc" }; - public CliOption DumpWorstOverlapGraphs { get; } = + public Option DumpWorstOverlapGraphs { get; } = new("--dump-worst-overlap-graphs") { DefaultValueFactory = _ => -1, Description = "Number of graphs to dump to .dot format in dump-worst-overlap-graphs-to directory" }; - public CliOption DumpWorstOverlapGraphsTo { get; } = + public Option DumpWorstOverlapGraphsTo { get; } = new("--dump-worst-overlap-graphs-to") { Description = "Number of graphs to dump to .dot format in dump-worst-overlap-graphs-to directory" }; - public CliOption AutomaticReferences { get; } = + public Option AutomaticReferences { get; } = new("--automatic-references") { DefaultValueFactory = _ => true, Description = "Attempt to find references by using paths embedded in the trace file. Defaults to true" }; - public CliOption IncludedAssemblies { get; } = + public Option IncludedAssemblies { get; } = new("--include-reference") { CustomParser = MakeAssemblyNameArray, DefaultValueFactory = MakeAssemblyNameArray, Description = "If specified, include in Mibc file only references to the specified assemblies. Assemblies are specified as assembly names, not filenames. For instance, `System.Private.CoreLib` not `System.Private.CoreLib.dll`. Multiple --include-reference options may be specified." }; - private CliOption _includeReadyToRun { get; } = + private Option _includeReadyToRun { get; } = new("--includeReadyToRun") { Description = "Include ReadyToRun methods in the trace file" }; - private CliOption _verbosity { get; } = + private Option _verbosity { get; } = new("--verbose") { DefaultValueFactory = _ => Verbosity.normal, Description = "Adjust verbosity level. Supported levels are minimal, normal, detailed, and diagnostic" }; - private CliOption _isSorted { get; } = + private Option _isSorted { get; } = new("--sorted") { Description = "Generate sorted output." }; - private CliOption _showTimestamp { get; } = + private Option _showTimestamp { get; } = new("--showtimestamp") { Description = "Show timestamps in output" }; public PgoFileType? FileType; @@ -97,7 +97,7 @@ private enum Verbosity public PgoRootCommand(string[] args) : base(".NET PGO Tool") { - CliCommand createMbicCommand = new("create-mibc", "Transform a trace file into a Mibc profile data file") + Command createMbicCommand = new("create-mibc", "Transform a trace file into a Mibc profile data file") { TraceFilePath, OutputFilePath, @@ -139,7 +139,7 @@ public PgoRootCommand(string[] args) : base(".NET PGO Tool") JitTraceOptions = JitTraceOptions.none; #if DEBUG - CliCommand createJitTraceCommand = new("create-jittrace","Transform a trace file into a jittrace runtime file") + Command createJitTraceCommand = new("create-jittrace","Transform a trace file into a jittrace runtime file") { TraceFilePath, OutputFilePath, @@ -179,7 +179,7 @@ public PgoRootCommand(string[] args) : base(".NET PGO Tool") Subcommands.Add(createJitTraceCommand); #endif - CliCommand mergeCommand = new("merge", "Merge multiple Mibc profile data files into one file") + Command mergeCommand = new("merge", "Merge multiple Mibc profile data files into one file") { InputFilesToMerge, OutputFilePath, @@ -201,7 +201,7 @@ public PgoRootCommand(string[] args) : base(".NET PGO Tool") Subcommands.Add(mergeCommand); - CliCommand dumpCommand = new("dump", "Dump the contents of a Mibc file") + Command dumpCommand = new("dump", "Dump the contents of a Mibc file") { _verbosity, InputFileToDump, @@ -216,7 +216,7 @@ public PgoRootCommand(string[] args) : base(".NET PGO Tool") Subcommands.Add(dumpCommand); - CliCommand compareMbicCommand = new("compare-mibc", "Compare two .mibc files") + Command compareMbicCommand = new("compare-mibc", "Compare two .mibc files") { InputFilesToCompare, DumpWorstOverlapGraphs, @@ -290,7 +290,7 @@ private static AssemblyNameInfo[] MakeAssemblyNameArray(ArgumentResult result) if (result.Tokens.Count > 0) { var includedAssemblies = new List(); - foreach (CliToken token in result.Tokens) + foreach (Token token in result.Tokens) { try { diff --git a/src/coreclr/tools/dotnet-pgo/Program.cs b/src/coreclr/tools/dotnet-pgo/Program.cs index c4745a74a20487..c7ac4bba6f2ee8 100644 --- a/src/coreclr/tools/dotnet-pgo/Program.cs +++ b/src/coreclr/tools/dotnet-pgo/Program.cs @@ -156,12 +156,12 @@ public Program(PgoRootCommand command) _inputFilesToCompare = Get(command.InputFilesToCompare); } - private T Get(CliOption option) => _command.Result.GetValue(option); - private T Get(CliArgument argument) => _command.Result.GetValue(argument); - private bool IsSet(CliOption option) => _command.Result.GetResult(option) != null; + private T Get(Option option) => _command.Result.GetValue(option); + private T Get(Argument argument) => _command.Result.GetValue(argument); + private bool IsSet(Option option) => _command.Result.GetResult(option) != null; private static int Main(string[] args) => - new CliConfiguration(new PgoRootCommand(args) + new CommandLineConfiguration(new PgoRootCommand(args) .UseVersion() .UseExtendedHelp(PgoRootCommand.GetExtendedHelp)) { diff --git a/src/coreclr/tools/r2rdump/Program.cs b/src/coreclr/tools/r2rdump/Program.cs index 831570fe2ea5aa..4755414bd66496 100644 --- a/src/coreclr/tools/r2rdump/Program.cs +++ b/src/coreclr/tools/r2rdump/Program.cs @@ -496,10 +496,10 @@ public int Run() return 0; } - private T Get(CliOption option) => _command.Result.GetValue(option); + private T Get(Option option) => _command.Result.GetValue(option); public static int Main(string[] args) => - new CliConfiguration(new R2RDumpRootCommand().UseVersion()) + new CommandLineConfiguration(new R2RDumpRootCommand().UseVersion()) { ResponseFileTokenReplacer = Helpers.TryReadResponseFile }.Invoke(args); diff --git a/src/coreclr/tools/r2rdump/R2RDumpRootCommand.cs b/src/coreclr/tools/r2rdump/R2RDumpRootCommand.cs index 818db56a312663..b7cede62ae5097 100644 --- a/src/coreclr/tools/r2rdump/R2RDumpRootCommand.cs +++ b/src/coreclr/tools/r2rdump/R2RDumpRootCommand.cs @@ -8,75 +8,75 @@ namespace R2RDump { - internal sealed class R2RDumpRootCommand : CliRootCommand + internal sealed class R2RDumpRootCommand : RootCommand { - public CliOption> In { get; } = + public Option> In { get; } = new("--in", "-i") { CustomParser = result => Helpers.BuildPathList(result.Tokens), DefaultValueFactory = result => Helpers.BuildPathList(result.Tokens), Description = "Input file(s) to dump. Expects them to by ReadyToRun images" }; - public CliOption Out { get; } = + public Option Out { get; } = new("--out", "-o") { Description = "Output file path. Dumps everything to the specified file except for help message and exception messages" }; - public CliOption Raw { get; } = + public Option Raw { get; } = new("--raw") { Description = "Dump the raw bytes of each section or runtime function" }; - public CliOption Header { get; } = + public Option Header { get; } = new("--header") { Description = "Dump R2R header" }; - public CliOption Disasm { get; } = + public Option Disasm { get; } = new("--disasm", "-d") { Description = "Show disassembly of methods or runtime functions" }; - public CliOption Naked { get; } = + public Option Naked { get; } = new("--naked") { Description = "Naked dump suppresses most compilation details like placement addresses" }; - public CliOption HideOffsets { get; } = + public Option HideOffsets { get; } = new("--hide-offsets", "--ho") { Description = "Hide offsets in naked disassembly" }; - public CliOption Query { get; } = + public Option Query { get; } = new("--query", "-q") { Description = "Query method by exact name, signature, row ID or token" }; - public CliOption Keyword { get; } = + public Option Keyword { get; } = new("--keyword", "-k") { Description = "Search method by keyword" }; - public CliOption RuntimeFunction { get; } = + public Option RuntimeFunction { get; } = new("--runtimefunction", "-f") { Description = "Get one runtime function by id or relative virtual address" }; - public CliOption Section { get; } = + public Option Section { get; } = new("--section", "-s") { Description = "Get section by keyword" }; - public CliOption Unwind { get; } = + public Option Unwind { get; } = new("--unwind") { Description = "Dump unwindInfo" }; - public CliOption GC { get; } = + public Option GC { get; } = new("--gc") { Description = "Dump gcInfo and slot table" }; - public CliOption Pgo { get; } = + public Option Pgo { get; } = new("--pgo") { Description = "Dump embedded pgo instrumentation data" }; - public CliOption SectionContents { get; } = + public Option SectionContents { get; } = new("--sectionContents", "--sc") { Description = "Dump section contents" }; - public CliOption EntryPoints { get; } = + public Option EntryPoints { get; } = new("--entrypoints", "-e") { Description = "Dump list of method / instance entrypoints in the R2R file" }; - public CliOption Normalize { get; } = + public Option Normalize { get; } = new("--normalize", "-n") { Description = "Normalize dump by sorting the various tables and methods (default = unsorted i.e. file order)" }; - public CliOption HideTransitions { get; } = + public Option HideTransitions { get; } = new("--hide-transitions", "--ht") { Description = "Don't include GC transitions in disassembly output" }; - public CliOption Verbose { get; } = + public Option Verbose { get; } = new("--verbose") { Description = "Dump disassembly, unwindInfo, gcInfo and sectionContents" }; - public CliOption Diff { get; } = + public Option Diff { get; } = new("--diff") { Description = "Compare two R2R images" }; - public CliOption DiffHideSameDisasm { get; } = + public Option DiffHideSameDisasm { get; } = new("--diff-hide-same-disasm") { Description = "In matching method diff dump, hide functions with identical disassembly" }; - public CliOption CreatePDB { get; } = + public Option CreatePDB { get; } = new("--create-pdb") { Description = "Create PDB" }; - public CliOption PdbPath { get; } = + public Option PdbPath { get; } = new("--pdb-path") { Description = "PDB output path for --create-pdb" }; - public CliOption CreatePerfmap { get; } = + public Option CreatePerfmap { get; } = new("--create-perfmap") { Description = "Create PerfMap" }; - public CliOption PerfmapPath { get; } = + public Option PerfmapPath { get; } = new("--perfmap-path") { Description = "PerfMap output path for --create-perfmap" }; - public CliOption PerfmapFormatVersion { get; } = + public Option PerfmapFormatVersion { get; } = new("--perfmap-format-version") { DefaultValueFactory = _ => ILCompiler.Diagnostics.PerfMapWriter.CurrentFormatVersion, Description = "PerfMap format version for --create-perfmap" }; - public CliOption> Reference { get; } = + public Option> Reference { get; } = new("--reference", "-r") { CustomParser = result => Helpers.BuildPathList(result.Tokens), DefaultValueFactory = result => Helpers.BuildPathList(result.Tokens), Description = "Explicit reference assembly files" }; - public CliOption ReferencePath { get; } = + public Option ReferencePath { get; } = new("--referencePath", "--rp") { Description = "Search paths for reference assemblies" }; - public CliOption SignatureBinary { get; } = + public Option SignatureBinary { get; } = new("--signatureBinary", "--sb") { Description = "Append signature binary to its textual representation" }; - public CliOption InlineSignatureBinary { get; } = + public Option InlineSignatureBinary { get; } = new("--inlineSignatureBinary", "--isb") { Description = "Embed binary signature into its textual representation" }; - public CliOption ValidateDebugInfo { get; } = + public Option ValidateDebugInfo { get; } = new("--validateDebugInfo", "--val") { Description = "Validate functions reported debug info." }; public ParseResult Result; diff --git a/src/coreclr/tools/r2rtest/Buckets.cs b/src/coreclr/tools/r2rtest/Buckets.cs index 927182e4926caa..4eb73314003ea8 100644 --- a/src/coreclr/tools/r2rtest/Buckets.cs +++ b/src/coreclr/tools/r2rtest/Buckets.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.CommandLine; using System.Diagnostics; using System.IO; using System.Linq; diff --git a/src/coreclr/tools/r2rtest/CommandLineOptions.cs b/src/coreclr/tools/r2rtest/CommandLineOptions.cs index 4f20677c488970..c892030f1af94b 100644 --- a/src/coreclr/tools/r2rtest/CommandLineOptions.cs +++ b/src/coreclr/tools/r2rtest/CommandLineOptions.cs @@ -8,11 +8,11 @@ namespace R2RTest { - public class R2RTestRootCommand : CliRootCommand + public class R2RTestRootCommand : RootCommand { - void CreateCommand(string name, string description, CliOption[] options, Func action) + void CreateCommand(string name, string description, Option[] options, Func action) { - CliCommand command = new(name, description); + Command command = new(name, description); foreach (var option in GetCommonOptions()) command.Options.Add(option); foreach (var option in options) @@ -21,14 +21,14 @@ void CreateCommand(string name, string description, CliOption[] options, Func new CliOption[] { CoreRootDirectory, DotNetCli }; + Option[] GetCommonOptions() => new Option[] { CoreRootDirectory, DotNetCli }; R2RTestRootCommand() { OutputDirectory.AcceptLegalFilePathsOnly(); CreateCommand("compile-directory", "Compile all assemblies in directory", - new CliOption[] + new Option[] { InputDirectory, OutputDirectory, @@ -67,7 +67,7 @@ void CreateCommand(string name, string description, CliOption[] options, Func InputDirectory { get; } = - new CliOption("--input-directory", "-in") { Description = "Folder containing assemblies to optimize" }.AcceptExistingOnly(); + public Option InputDirectory { get; } = + new Option("--input-directory", "-in") { Description = "Folder containing assemblies to optimize" }.AcceptExistingOnly(); - public CliOption OutputDirectory { get; } = - new CliOption("--output-directory", "-out") { Description = "Folder to emit compiled assemblies" }; + public Option OutputDirectory { get; } = + new Option("--output-directory", "-out") { Description = "Folder to emit compiled assemblies" }; - public CliOption CoreRootDirectory { get; } = - new CliOption("--core-root-directory", "-cr") { Description = "Location of the CoreCLR CORE_ROOT folder", Arity = ArgumentArity.ExactlyOne }.AcceptExistingOnly(); + public Option CoreRootDirectory { get; } = + new Option("--core-root-directory", "-cr") { Description = "Location of the CoreCLR CORE_ROOT folder", Arity = ArgumentArity.ExactlyOne }.AcceptExistingOnly(); - public CliOption ReferencePath { get; } = - new CliOption("--reference-path", "-r") { Description = "Folder containing assemblies to reference during compilation", Arity = ArgumentArity.ZeroOrMore }.AcceptExistingOnly(); + public Option ReferencePath { get; } = + new Option("--reference-path", "-r") { Description = "Folder containing assemblies to reference during compilation", Arity = ArgumentArity.ZeroOrMore }.AcceptExistingOnly(); - public CliOption MibcPath { get; } = - new CliOption("--mibc-path", "-m") { Description = "Mibc files to use in compilation", Arity = ArgumentArity.ZeroOrMore }.AcceptExistingOnly(); + public Option MibcPath { get; } = + new Option("--mibc-path", "-m") { Description = "Mibc files to use in compilation", Arity = ArgumentArity.ZeroOrMore }.AcceptExistingOnly(); - public CliOption Crossgen2Path { get; } = - new CliOption("--crossgen2-path", "-c2p") { Description = "Explicit Crossgen2 path (useful for cross-targeting)" }.AcceptExistingOnly(); + public Option Crossgen2Path { get; } = + new Option("--crossgen2-path", "-c2p") { Description = "Explicit Crossgen2 path (useful for cross-targeting)" }.AcceptExistingOnly(); - public CliOption VerifyTypeAndFieldLayout { get; } = + public Option VerifyTypeAndFieldLayout { get; } = new("--verify-type-and-field-layout") { Description = "Verify that struct type layout and field offsets match between compile time and runtime. Use only for diagnostic purposes." }; - public CliOption NoJit { get; } = + public Option NoJit { get; } = new("--nojit") { Description = "Don't run tests in JITted mode" }; - public CliOption NoCrossgen2 { get; } = + public Option NoCrossgen2 { get; } = new("--nocrossgen2") { Description = "Don't run tests in Crossgen2 mode" }; - public CliOption Exe { get; } = + public Option Exe { get; } = new("--exe") { Description = "Don't compile tests, just execute them" }; - public CliOption NoExe { get; } = + public Option NoExe { get; } = new("--noexe") { Description = "Compilation-only mode (don't execute the built apps)" }; - public CliOption NoEtw { get; } = + public Option NoEtw { get; } = new("--noetw") { Description = "Don't capture jitted methods using ETW" }; - public CliOption NoCleanup { get; } = + public Option NoCleanup { get; } = new("--nocleanup") { Description = "Don't clean up compilation artifacts after test runs" }; - public CliOption Map { get; } = + public Option Map { get; } = new("--map") { Description = "Generate a map file (Crossgen2)" }; - public CliOption Pdb { get; } = + public Option Pdb { get; } = new("--pdb") { Description = "Generate PDB symbol information (Crossgen2 / Windows only)" }; - public CliOption Perfmap { get; } = + public Option Perfmap { get; } = new("--perfmap") { Description = "Generate perfmap symbol information" }; - public CliOption PerfmapFormatVersion { get; } = + public Option PerfmapFormatVersion { get; } = new("--perfmap-format-version") { DefaultValueFactory = _ => 1, Description = "Perfmap format version to generate" }; - public CliOption DegreeOfParallelism { get; } = + public Option DegreeOfParallelism { get; } = new("--degree-of-parallelism", "-dop") { Description = "Override default compilation / execution DOP (default = logical processor count)" }; - public CliOption Sequential { get; } = + public Option Sequential { get; } = new("--sequential") { Description = "Run tests sequentially" }; - public CliOption Iterations { get; } = + public Option Iterations { get; } = new("--iterations") { DefaultValueFactory = _ => 1, Description = "Number of iterations for each test execution" }; - public CliOption Framework { get; } = + public Option Framework { get; } = new("--framework") { Description = "Precompile and use native framework" }; - public CliOption UseFramework { get; } = + public Option UseFramework { get; } = new("--use-framework") { Description = "Use native framework (don't precompile, assume previously compiled)" }; - public CliOption Release { get; } = + public Option Release { get; } = new("--release") { Description = "Build the tests in release mode" }; - public CliOption LargeBubble { get; } = + public Option LargeBubble { get; } = new("--large-bubble") { Description = "Assume all input files as part of one version bubble" }; - public CliOption Composite { get; } = + public Option Composite { get; } = new("--composite") { Description = "Compile tests in composite R2R mode" }; - public CliOption Crossgen2Parallelism { get; } = + public Option Crossgen2Parallelism { get; } = new("--crossgen2-parallelism") { Description = "Max number of threads to use in Crossgen2 (default = logical processor count)" }; - public CliOption Crossgen2JitPath { get; } = + public Option Crossgen2JitPath { get; } = new("--crossgen2-jitpath") { Description = "Jit path to use for crossgen2" }; - public CliOption IssuesPath { get; } = + public Option IssuesPath { get; } = new("--issues-path", "-ip") { Description = "Path to issues.targets", Arity = ArgumentArity.ZeroOrMore }; - public CliOption CompilationTimeoutMinutes { get; } = + public Option CompilationTimeoutMinutes { get; } = new("--compilation-timeout-minutes", "-ct") { Description = "Compilation timeout (minutes)" }; - public CliOption ExecutionTimeoutMinutes { get; } = + public Option ExecutionTimeoutMinutes { get; } = new("--execution-timeout-minutes", "-et") { Description = "Execution timeout (minutes)" }; - public CliOption R2RDumpPath { get; } = - new CliOption("--r2r-dump-path") { Description = "Path to R2RDump.exe/dll" }.AcceptExistingOnly(); + public Option R2RDumpPath { get; } = + new Option("--r2r-dump-path") { Description = "Path to R2RDump.exe/dll" }.AcceptExistingOnly(); - public CliOption MeasurePerf { get; } = + public Option MeasurePerf { get; } = new("--measure-perf") { Description = "Print out compilation time" }; - public CliOption InputFileSearchString { get; } = + public Option InputFileSearchString { get; } = new("--input-file-search-string", "-input-file") { Description = "Search string for input files in the input directory" }; - public CliOption GCStress { get; } = + public Option GCStress { get; } = new("--gcstress") { Description = "Run tests with the specified GC stress level enabled (the argument value is in hex)" }; - public CliOption DotNetCli { get; } = + public Option DotNetCli { get; } = new("--dotnet-cli", "-cli") { Description = "For dev box testing, point at .NET 5 dotnet.exe or /dotnet.cmd." }; - public CliOption TargetArch { get; } = + public Option TargetArch { get; } = new("--target-arch") { Description = "Target architecture for crossgen2" }; // // compile-nuget specific options // - public CliOption PackageList { get; } = - new CliOption("--package-list", "-pl") { Description = "Text file containing a package name on each line" }.AcceptExistingOnly(); + public Option PackageList { get; } = + new Option("--package-list", "-pl") { Description = "Text file containing a package name on each line" }.AcceptExistingOnly(); // // compile-serp specific options // - public CliOption AspNetPath { get; } = - new CliOption("--asp-net-path", "-asp") { Description = "Path to SERP's ASP.NET Core folder" }.AcceptExistingOnly(); + public Option AspNetPath { get; } = + new Option("--asp-net-path", "-asp") { Description = "Path to SERP's ASP.NET Core folder" }.AcceptExistingOnly(); private static int Main(string[] args) => - new CliConfiguration(new R2RTestRootCommand().UseVersion()).Invoke(args); + new CommandLineConfiguration(new R2RTestRootCommand().UseVersion()).Invoke(args); } public partial class BuildOptions diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj index 408d0d1f2c4c66..55c0d1e2d7fc78 100644 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/HttpStress.csproj @@ -4,6 +4,8 @@ $(NetCoreAppCurrent) enable true + + https://api.nuget.org/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json @@ -11,7 +13,7 @@ - + diff --git a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/Program.cs b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/Program.cs index 8a93a43f20ddef..9b42f0795ee798 100644 --- a/src/libraries/System.Net.Http/tests/StressTests/HttpStress/Program.cs +++ b/src/libraries/System.Net.Http/tests/StressTests/HttpStress/Program.cs @@ -45,78 +45,86 @@ public static async Task Main(string[] args) private static bool TryParseCli(string[] args, [NotNullWhen(true)] out Configuration? config) { var cmd = new RootCommand(); - cmd.AddOption(new Option("-n", "Max number of requests to make concurrently.") { Argument = new Argument("numWorkers", Environment.ProcessorCount) }); - cmd.AddOption(new Option("-serverUri", "Stress suite server uri.") { Argument = new Argument("serverUri", "https://localhost:5001") }); - cmd.AddOption(new Option("-runMode", "Stress suite execution mode. Defaults to Both.") { Argument = new Argument("runMode", RunMode.both) }); - cmd.AddOption(new Option("-maxExecutionTime", "Maximum stress execution time, in minutes. Defaults to infinity.") { Argument = new Argument("minutes", null) }); - cmd.AddOption(new Option("-maxContentLength", "Max content length for request and response bodies.") { Argument = new Argument("numBytes", 1000) }); - cmd.AddOption(new Option("-maxRequestUriSize", "Max query string length support by the server.") { Argument = new Argument("numChars", 5000) }); - cmd.AddOption(new Option("-maxRequestHeaderCount", "Maximum number of headers to place in request") { Argument = new Argument("numHeaders", 90) }); - cmd.AddOption(new Option("-maxRequestHeaderTotalSize", "Max request header total size.") { Argument = new Argument("numBytes", 1000) }); - cmd.AddOption(new Option("-http", "HTTP version (1.1 or 2.0 or 3.0)") { Argument = new Argument("version", HttpVersion.Version20) }); - cmd.AddOption(new Option("-connectionLifetime", "Max connection lifetime length (milliseconds).") { Argument = new Argument("connectionLifetime", null) }); - cmd.AddOption(new Option("-ops", "Indices of the operations to use") { Argument = new Argument("space-delimited indices", null) }); - cmd.AddOption(new Option("-xops", "Indices of the operations to exclude") { Argument = new Argument("space-delimited indices", null) }); - cmd.AddOption(new Option("-trace", "Enable System.Net.Http.InternalDiagnostics (client) and/or ASP.NET dignostics (server) tracing.") { Argument = new Argument("enable", false) }); - cmd.AddOption(new Option("-aspnetlog", "Enable ASP.NET warning and error logging.") { Argument = new Argument("enable", false) }); - cmd.AddOption(new Option("-listOps", "List available options.") { Argument = new Argument("enable", false) }); - cmd.AddOption(new Option("-seed", "Seed for generating pseudo-random parameters for a given -n argument.") { Argument = new Argument("seed", null) }); - cmd.AddOption(new Option("-numParameters", "Max number of query parameters or form fields for a request.") { Argument = new Argument("queryParameters", 1) }); - cmd.AddOption(new Option("-cancelRate", "Number between 0 and 1 indicating rate of client-side request cancellation attempts. Defaults to 0.1.") { Argument = new Argument("probability", 0.1) }); - cmd.AddOption(new Option("-httpSys", "Use http.sys instead of Kestrel.") { Argument = new Argument("enable", false) }); - cmd.AddOption(new Option("-winHttp", "Use WinHttpHandler for the stress client.") { Argument = new Argument("enable", false) }); - cmd.AddOption(new Option("-displayInterval", "Client stats display interval in seconds. Defaults to 5 seconds.") { Argument = new Argument("seconds", 5) }); - cmd.AddOption(new Option("-clientTimeout", "Default HttpClient timeout in seconds. Defaults to 60 seconds.") { Argument = new Argument("seconds", 60) }); - cmd.AddOption(new Option("-serverMaxConcurrentStreams", "Overrides kestrel max concurrent streams per connection.") { Argument = new Argument("streams", null) }); - cmd.AddOption(new Option("-serverMaxFrameSize", "Overrides kestrel max frame size setting.") { Argument = new Argument("bytes", null) }); - cmd.AddOption(new Option("-serverInitialConnectionWindowSize", "Overrides kestrel initial connection window size setting.") { Argument = new Argument("bytes", null) }); - cmd.AddOption(new Option("-serverMaxRequestHeaderFieldSize", "Overrides kestrel max request header field size.") { Argument = new Argument("bytes", null) }); - cmd.AddOption(new Option("-unobservedEx", "Enable tracking unobserved exceptions.") { Argument = new Argument("enable", null) }); + cmd.Options.Add(new Option("-n") { Description = "Max number of requests to make concurrently.", DefaultValueFactory = (_) => Environment.ProcessorCount }); + cmd.Options.Add(new Option("-serverUri") { Description = "Stress suite server uri.", DefaultValueFactory = (_) => "https://localhost:5001" }); + cmd.Options.Add(new Option("-runMode") { Description = "Stress suite execution mode. Defaults to Both.", DefaultValueFactory = (_) => RunMode.both }); + cmd.Options.Add(new Option("-maxExecutionTime") { Description = "Maximum stress execution time, in minutes. Defaults to infinity." }); + cmd.Options.Add(new Option("-maxContentLength") { Description = "Max content length for request and response bodies.", DefaultValueFactory = (_) => 1000 }); + cmd.Options.Add(new Option("-maxRequestUriSize") { Description = "Max query string length support by the server.", DefaultValueFactory = (_) => 5000 }); + cmd.Options.Add(new Option("-maxRequestHeaderCount") { Description = "Maximum number of headers to place in request", DefaultValueFactory = (_) => 90 }); + cmd.Options.Add(new Option("-maxRequestHeaderTotalSize") { Description = "Max request header total size.", DefaultValueFactory = (_) => 1000 }); + cmd.Options.Add(new Option("-http") + { + Description = "HTTP version (1.1 or 2.0 or 3.0)", + DefaultValueFactory = (_) => HttpVersion.Version20, + CustomParser = result => + { + if (!Version.TryParse(result.Tokens.Single().Value, out Version? parsed)) + { + result.AddError($"'{result.Tokens[0].Value}' is not a valid Version"); + } + + return parsed; + } + }); + cmd.Options.Add(new Option("-connectionLifetime") { Description = "Max connection lifetime length (milliseconds)." }); + cmd.Options.Add(new Option("-ops") { Description = "Indices of the operations to use" }); + cmd.Options.Add(new Option("-xops") { Description = "Indices of the operations to exclude" }); + cmd.Options.Add(new Option("-trace") { Description = "Enable System.Net.Http.InternalDiagnostics (client) and/or ASP.NET dignostics (server) tracing." }); + cmd.Options.Add(new Option("-aspnetlog") { Description = "Enable ASP.NET warning and error logging." }); + cmd.Options.Add(new Option("-listOps") { Description = "List available options." }); + cmd.Options.Add(new Option("-seed") { Description = "Seed for generating pseudo-random parameters for a given -n argument." }); + cmd.Options.Add(new Option("-numParameters") { Description = "Max number of query parameters or form fields for a request.", DefaultValueFactory = (_) => 1 }); + cmd.Options.Add(new Option("-cancelRate") { Description = "Number between 0 and 1 indicating rate of client-side request cancellation attempts. Defaults to 0.1.", DefaultValueFactory = (_) => 0.1 }); + cmd.Options.Add(new Option("-httpSys") { Description = "Use http.sys instead of Kestrel." }); + cmd.Options.Add(new Option("-winHttp") { Description = "Use WinHttpHandler for the stress client." }); + cmd.Options.Add(new Option("-displayInterval") { Description = "Client stats display interval in seconds. Defaults to 5 seconds.", DefaultValueFactory = (_) => 5 }); + cmd.Options.Add(new Option("-clientTimeout") { Description = "Default HttpClient timeout in seconds. Defaults to 60 seconds.", DefaultValueFactory = (_) => 60 }); + cmd.Options.Add(new Option("-serverMaxConcurrentStreams") { Description = "Overrides kestrel max concurrent streams per connection." }); + cmd.Options.Add(new Option("-serverMaxFrameSize") { Description = "Overrides kestrel max frame size setting." }); + cmd.Options.Add(new Option("-serverInitialConnectionWindowSize") { Description = "Overrides kestrel initial connection window size setting." }); + cmd.Options.Add(new Option("-serverMaxRequestHeaderFieldSize") { Description = "Overrides kestrel max request header field size." }); + cmd.Options.Add(new Option("-unobservedEx") { Description = "Enable tracking unobserved exceptions." }); ParseResult cmdline = cmd.Parse(args); if (cmdline.Errors.Count > 0) { - foreach (ParseError error in cmdline.Errors) - { - Console.WriteLine(error); - } - Console.WriteLine(); - new HelpBuilder(new SystemConsole()).Write(cmd); + cmdline.Invoke(); // this is going to print all the errors and help config = null; return false; } config = new Configuration() { - RunMode = cmdline.ValueForOption("-runMode"), - ServerUri = cmdline.ValueForOption("-serverUri"), - ListOperations = cmdline.ValueForOption("-listOps"), - - HttpVersion = cmdline.ValueForOption("-http"), - UseWinHttpHandler = cmdline.ValueForOption("-winHttp"), - ConcurrentRequests = cmdline.ValueForOption("-n"), - RandomSeed = cmdline.ValueForOption("-seed") ?? new Random().Next(), - MaxContentLength = cmdline.ValueForOption("-maxContentLength"), - MaxRequestUriSize = cmdline.ValueForOption("-maxRequestUriSize"), - MaxRequestHeaderCount = cmdline.ValueForOption("-maxRequestHeaderCount"), - MaxRequestHeaderTotalSize = cmdline.ValueForOption("-maxRequestHeaderTotalSize"), - OpIndices = cmdline.ValueForOption("-ops"), - ExcludedOpIndices = cmdline.ValueForOption("-xops"), - MaxParameters = cmdline.ValueForOption("-numParameters"), - DisplayInterval = TimeSpan.FromSeconds(cmdline.ValueForOption("-displayInterval")), - DefaultTimeout = TimeSpan.FromSeconds(cmdline.ValueForOption("-clientTimeout")), - ConnectionLifetime = cmdline.ValueForOption("-connectionLifetime").Select(TimeSpan.FromMilliseconds), - CancellationProbability = Math.Max(0, Math.Min(1, cmdline.ValueForOption("-cancelRate"))), - MaximumExecutionTime = cmdline.ValueForOption("-maxExecutionTime").Select(TimeSpan.FromMinutes), - - UseHttpSys = cmdline.ValueForOption("-httpSys"), - LogAspNet = cmdline.ValueForOption("-aspnetlog"), - Trace = cmdline.ValueForOption("-trace"), - TrackUnobservedExceptions = cmdline.ValueForOption("-unobservedEx"), - ServerMaxConcurrentStreams = cmdline.ValueForOption("-serverMaxConcurrentStreams"), - ServerMaxFrameSize = cmdline.ValueForOption("-serverMaxFrameSize"), - ServerInitialConnectionWindowSize = cmdline.ValueForOption("-serverInitialConnectionWindowSize"), - ServerMaxRequestHeaderFieldSize = cmdline.ValueForOption("-serverMaxRequestHeaderFieldSize"), + RunMode = cmdline.GetValue("-runMode"), + ServerUri = cmdline.GetValue("-serverUri")!, + ListOperations = cmdline.GetValue("-listOps"), + + HttpVersion = cmdline.GetValue("-http")!, + UseWinHttpHandler = cmdline.GetValue("-winHttp"), + ConcurrentRequests = cmdline.GetValue("-n"), + RandomSeed = cmdline.GetValue("-seed") ?? new Random().Next(), + MaxContentLength = cmdline.GetValue("-maxContentLength"), + MaxRequestUriSize = cmdline.GetValue("-maxRequestUriSize"), + MaxRequestHeaderCount = cmdline.GetValue("-maxRequestHeaderCount"), + MaxRequestHeaderTotalSize = cmdline.GetValue("-maxRequestHeaderTotalSize"), + OpIndices = cmdline.GetValue("-ops"), + ExcludedOpIndices = cmdline.GetValue("-xops"), + MaxParameters = cmdline.GetValue("-numParameters"), + DisplayInterval = TimeSpan.FromSeconds(cmdline.GetValue("-displayInterval")), + DefaultTimeout = TimeSpan.FromSeconds(cmdline.GetValue("-clientTimeout")), + ConnectionLifetime = cmdline.GetValue("-connectionLifetime").Select(TimeSpan.FromMilliseconds), + CancellationProbability = Math.Max(0, Math.Min(1, cmdline.GetValue("-cancelRate"))), + MaximumExecutionTime = cmdline.GetValue("-maxExecutionTime").Select(TimeSpan.FromMinutes), + + UseHttpSys = cmdline.GetValue("-httpSys"), + LogAspNet = cmdline.GetValue("-aspnetlog"), + Trace = cmdline.GetValue("-trace"), + TrackUnobservedExceptions = cmdline.GetValue("-unobservedEx"), + ServerMaxConcurrentStreams = cmdline.GetValue("-serverMaxConcurrentStreams"), + ServerMaxFrameSize = cmdline.GetValue("-serverMaxFrameSize"), + ServerInitialConnectionWindowSize = cmdline.GetValue("-serverInitialConnectionWindowSize"), + ServerMaxRequestHeaderFieldSize = cmdline.GetValue("-serverMaxRequestHeaderFieldSize"), }; return true; diff --git a/src/libraries/System.Net.Security/tests/StressTests/SslStress/Program.cs b/src/libraries/System.Net.Security/tests/StressTests/SslStress/Program.cs index ca8e0044b2f29d..03f33b516684af 100644 --- a/src/libraries/System.Net.Security/tests/StressTests/SslStress/Program.cs +++ b/src/libraries/System.Net.Security/tests/StressTests/SslStress/Program.cs @@ -3,6 +3,7 @@ using System; using System.CommandLine; +using System.CommandLine.Help; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Net; @@ -113,62 +114,66 @@ static async Task WaitUntilMaxExecutionTimeElapsedOrKeyboardInterrupt(TimeSpan? private static bool TryParseCli(string[] args, [NotNullWhen(true)] out Configuration? config) { var cmd = new RootCommand(); - cmd.AddOption(new Option(new[] { "--help", "-h" }, "Display this help text.")); - cmd.AddOption(new Option(new[] { "--mode", "-m" }, "Stress suite execution mode. Defaults to 'both'.") { Argument = new Argument("runMode", RunMode.both) }); - cmd.AddOption(new Option(new[] { "--cancellation-probability", "-p" }, "Cancellation probability 0 <= p <= 1 for a given connection. Defaults to 0.1") { Argument = new Argument("probability", 0.1) }); - cmd.AddOption(new Option(new[] { "--num-connections", "-n" }, "Max number of connections to open concurrently.") { Argument = new Argument("connections", Environment.ProcessorCount) }); - cmd.AddOption(new Option(new[] { "--server-endpoint", "-e" }, "Endpoint to bind to if server, endpoint to listen to if client.") { Argument = new Argument("ipEndpoint", "127.0.0.1:5002") }); - cmd.AddOption(new Option(new[] { "--max-execution-time", "-t" }, "Maximum stress suite execution time, in minutes. Defaults to infinity.") { Argument = new Argument("minutes", null) }); - cmd.AddOption(new Option(new[] { "--max-buffer-length", "-b" }, "Maximum buffer length to write on ssl stream. Defaults to 8192.") { Argument = new Argument("bytes", 8192) }); - cmd.AddOption(new Option(new[] { "--min-connection-lifetime", "-l" }, "Minimum duration for a single connection, in seconds. Defaults to 5 seconds.") { Argument = new Argument("seconds", 5) }); - cmd.AddOption(new Option(new[] { "--max-connection-lifetime", "-L" }, "Maximum duration for a single connection, in seconds. Defaults to 120 seconds.") { Argument = new Argument("seconds", 120) }); - cmd.AddOption(new Option(new[] { "--display-interval", "-i" }, "Client stats display interval, in seconds. Defaults to 5 seconds.") { Argument = new Argument("seconds", 5) }); - cmd.AddOption(new Option(new[] { "--log-server", "-S" }, "Print server logs to stdout.")); - cmd.AddOption(new Option(new[] { "--seed", "-s" }, "Seed for generating pseudo-random parameters. Also depends on the -n argument.") { Argument = new Argument("seed", (new Random().Next())) }); - - ParseResult parseResult = cmd.Parse(args); - if (parseResult.Errors.Count > 0 || parseResult.HasOption("-h")) + cmd.Options.Add(new Option("--mode", "-m") { Description = "Stress suite execution mode. Defaults to 'both'.", DefaultValueFactory = (_) => RunMode.both }); + cmd.Options.Add(new Option("--cancellation-probability", "-p") { Description = "Cancellation probability 0 <= p <= 1 for a given connection. Defaults to 0.1", DefaultValueFactory = (_) => 0.1 }); + cmd.Options.Add(new Option("--num-connections", "-n" ) { Description = "Max number of connections to open concurrently.", DefaultValueFactory = (_) => Environment.ProcessorCount }); + cmd.Options.Add(new Option("--server-endpoint", "-e" ) { - foreach (ParseError error in parseResult.Errors) + Description = "Endpoint to bind to if server, endpoint to listen to if client.", + DefaultValueFactory = (_) => IPEndPoint.Parse("127.0.0.1:5002"), + CustomParser = result => { - Console.WriteLine(error); + try + { + return ParseEndpoint(result.Tokens[0].Value); + } + catch + { + result.AddError($"'{result.Tokens[0].Value}' is not a valid endpoint"); + return default; + } } - WriteHelpText(); + }); + cmd.Options.Add(new Option("--max-execution-time", "-t" ) { Description = "Maximum stress suite execution time, in minutes. Defaults to infinity." }); + cmd.Options.Add(new Option("--max-buffer-length", "-b" ) { Description = "Maximum buffer length to write on ssl stream. Defaults to 8192.", DefaultValueFactory = (_) => 8192 }); + cmd.Options.Add(new Option("--min-connection-lifetime", "-l" ) { Description = "Minimum duration for a single connection, in seconds. Defaults to 5 seconds.", DefaultValueFactory = (_) => 5 }); + cmd.Options.Add(new Option("--max-connection-lifetime", "-L" ) { Description = "Maximum duration for a single connection, in seconds. Defaults to 120 seconds.", DefaultValueFactory = (_) => 120.0 }); + cmd.Options.Add(new Option("--display-interval", "-i" ) { Description = "Client stats display interval, in seconds. Defaults to 5 seconds.", DefaultValueFactory = (_) => 5 }); + cmd.Options.Add(new Option("--log-server", "-S") { Description = "Print server logs to stdout." }); + cmd.Options.Add(new Option("--seed", "-s" ) { Description = "Seed for generating pseudo-random parameters. Also depends on the -n argument.", DefaultValueFactory = (_) => new Random().Next() }); + + ParseResult parseResult = cmd.Parse(args); + if (parseResult.Errors.Count > 0 || parseResult.Action is HelpAction) + { + parseResult.Invoke(); // this is going to print all the errors and help config = null; return false; } config = new Configuration() { - RunMode = parseResult.ValueForOption("-m"), - MaxConnections = parseResult.ValueForOption("-n"), - CancellationProbability = Math.Max(0, Math.Min(1, parseResult.ValueForOption("-p"))), - ServerEndpoint = ParseEndpoint(parseResult.ValueForOption("-e")), - MaxExecutionTime = parseResult.ValueForOption("-t")?.Pipe(TimeSpan.FromMinutes), - MaxBufferLength = parseResult.ValueForOption("-b"), - MinConnectionLifetime = TimeSpan.FromSeconds(parseResult.ValueForOption("-l")), - MaxConnectionLifetime = TimeSpan.FromSeconds(parseResult.ValueForOption("-L")), - DisplayInterval = TimeSpan.FromSeconds(parseResult.ValueForOption("-i")), - LogServer = parseResult.HasOption("-S"), - RandomSeed = parseResult.ValueForOption("-s"), + RunMode = parseResult.GetValue("--mode"), + MaxConnections = parseResult.GetValue("--num-connections"), + CancellationProbability = Math.Max(0, Math.Min(1, parseResult.GetValue("--cancellation-probability"))), + ServerEndpoint = parseResult.GetValue("--server-endpoint"), + MaxExecutionTime = parseResult.GetValue("--max-execution-time")?.Pipe(TimeSpan.FromMinutes), + MaxBufferLength = parseResult.GetValue("--max-buffer-length"), + MinConnectionLifetime = TimeSpan.FromSeconds(parseResult.GetValue("--min-connection-lifetime")), + MaxConnectionLifetime = TimeSpan.FromSeconds(parseResult.GetValue("--max-connection-lifetime")), + DisplayInterval = TimeSpan.FromSeconds(parseResult.GetValue("--display-interval")), + LogServer = parseResult.GetValue("--log-server"), + RandomSeed = parseResult.GetValue("--seed"), }; if (config.MaxConnectionLifetime < config.MinConnectionLifetime) { Console.WriteLine("Max connection lifetime should be greater than or equal to min connection lifetime"); - WriteHelpText(); config = null; return false; } return true; - void WriteHelpText() - { - Console.WriteLine(); - new HelpBuilder(new SystemConsole()).Write(cmd); - } - static IPEndPoint ParseEndpoint(string value) { try diff --git a/src/libraries/System.Net.Security/tests/StressTests/SslStress/SslStress.csproj b/src/libraries/System.Net.Security/tests/StressTests/SslStress/SslStress.csproj index a2c1d8dffa5691..ec077a4ac48326 100644 --- a/src/libraries/System.Net.Security/tests/StressTests/SslStress/SslStress.csproj +++ b/src/libraries/System.Net.Security/tests/StressTests/SslStress/SslStress.csproj @@ -3,12 +3,14 @@ Exe $(NetCoreAppCurrent) enable + + https://api.nuget.org/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json - + - \ No newline at end of file + diff --git a/src/tools/StressLogAnalyzer/src/Program.cs b/src/tools/StressLogAnalyzer/src/Program.cs index 00b4105e1d0f3b..88690222f9cbe1 100644 --- a/src/tools/StressLogAnalyzer/src/Program.cs +++ b/src/tools/StressLogAnalyzer/src/Program.cs @@ -56,7 +56,7 @@ private static unsafe int ReadFromMemoryMappedLog(ulong address, Span buff public static async Task Main(string[] args) { - CliConfiguration configuration = new(CreateRootCommand()); + CommandLineConfiguration configuration = new(CreateRootCommand()); ParseResult parsedArguments = configuration.Parse(args); while (true) @@ -86,25 +86,25 @@ public static async Task Main(string[] args) }; } - private static readonly CliArgument InputFileArgument = new CliArgument("log file") + private static readonly Argument InputFileArgument = new Argument("log file") { Description = "The memory-mapped stress log file to analyze", }; - private static readonly CliOption SingleRunOption = new CliOption("--single-run") + private static readonly Option SingleRunOption = new Option("--single-run") { Description = "Run the analyzer only once", }; - public static CliRootCommand CreateRootCommand() + public static RootCommand CreateRootCommand() { - var outputFile = new CliOption("-output", "-o") + var outputFile = new Option("-output", "-o") { Description = "Write output to a text file instead of the console", HelpName = "output file", }; - var valueRanges = new CliOption("-values", "-v") + var valueRanges = new Option("-values", "-v") { Arity = ArgumentArity.OneOrMore, DefaultValueFactory = argument => [], @@ -142,7 +142,7 @@ public static CliRootCommand CreateRootCommand() HelpName = "hex value or range", }; - var timeRanges = new CliOption("--time", "-t") + var timeRanges = new Option("--time", "-t") { Arity = ArgumentArity.OneOrMore, DefaultValueFactory = argument => new TimeRange(0, double.MaxValue), @@ -168,24 +168,24 @@ public static CliRootCommand CreateRootCommand() HelpName = "start time or range", }; - var allMessagesOption = new CliOption("--all", "-a") + var allMessagesOption = new Option("--all", "-a") { Description = "Print all messages from all threads" }; - var defaultMessagesOption = new CliOption("--defaultMessages", "-d") + var defaultMessagesOption = new Option("--defaultMessages", "-d") { Description = "Suppress default messages" }; - var levelFilter = new CliOption>("--level", "-l") + var levelFilter = new Option>("--level", "-l") { Arity = ArgumentArity.OneOrMore, DefaultValueFactory = argument => [], CustomParser = argument => { List levels = []; - foreach (CliToken token in argument.Tokens) + foreach (Token token in argument.Tokens) { foreach (string value in token.Value.Split(',')) { @@ -215,13 +215,13 @@ public static CliRootCommand CreateRootCommand() AllowMultipleArgumentsPerToken = true, }; - var prefixOption = new CliOption("--prefix", "-p") + var prefixOption = new Option("--prefix", "-p") { Description = "Search for all format strings with a specific prefix", HelpName = "format string" }; - var gcIndex = new CliOption("--gc", "-g") + var gcIndex = new Option("--gc", "-g") { Arity = ArgumentArity.OneOrMore, DefaultValueFactory = argument => null, @@ -242,7 +242,7 @@ public static CliRootCommand CreateRootCommand() HelpName = "gc index or range", }; - var ignoreFacilityOption = new CliOption("--ignore", "-i") + var ignoreFacilityOption = new Option("--ignore", "-i") { CustomParser = argument => { @@ -252,7 +252,7 @@ public static CliRootCommand CreateRootCommand() HelpName = "facility bitmap in hex", }; - var earliestOption = new CliOption("--earliest", "-e") + var earliestOption = new Option("--earliest", "-e") { Arity = ArgumentArity.ZeroOrMore, CustomParser = argument => @@ -263,7 +263,7 @@ public static CliRootCommand CreateRootCommand() HelpName = "thread id or GC heap number", }; - var threadFilter = new CliOption("--threads", "-tid") + var threadFilter = new Option("--threads", "-tid") { Arity = ArgumentArity.ZeroOrMore, DefaultValueFactory = argument => null, @@ -275,26 +275,26 @@ public static CliRootCommand CreateRootCommand() HelpName = "thread id or GC heap number", }; - var hexThreadId = new CliOption("--hexThreadId", "--hex") + var hexThreadId = new Option("--hexThreadId", "--hex") { DefaultValueFactory = argument => null, Description = "Print hex thread ids, e.g. 2a08 instead of GC12", }; - var formatFilter = new CliOption("--format", "-f") + var formatFilter = new Option("--format", "-f") { Arity = ArgumentArity.ZeroOrMore, Description = "Print the raw format strings along with the message. Use -f: to search for a specific format string", HelpName = "format string", }; - var printFormatStrings = new CliOption("--printFormatStrings", "-pf") + var printFormatStrings = new Option("--printFormatStrings", "-pf") { DefaultValueFactory = argument => null, Description = "Print the raw format strings along with the message", }; - var rootCommand = new CliRootCommand + var rootCommand = new RootCommand { InputFileArgument, outputFile,