Merge pull request #530 from livarcocc/native_help_crash
compile-native and compile-csc crash when invoked with --help
This commit is contained in:
commit
3b9828404e
4 changed files with 57 additions and 5 deletions
|
@ -32,11 +32,17 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
|
|||
IReadOnlyList<string> resources = Array.Empty<string>();
|
||||
IReadOnlyList<string> sources = Array.Empty<string>();
|
||||
string outputName = null;
|
||||
var help = false;
|
||||
var returnCode = 0;
|
||||
string helpText = null;
|
||||
|
||||
try
|
||||
{
|
||||
ArgumentSyntax.Parse(args, syntax =>
|
||||
{
|
||||
syntax.HandleHelp = false;
|
||||
syntax.HandleErrors = false;
|
||||
|
||||
commonOptions = CommonCompilerOptionsExtensions.Parse(syntax);
|
||||
|
||||
assemblyInfoOptions = AssemblyInfoOptions.Parse(syntax);
|
||||
|
@ -49,16 +55,30 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
|
|||
|
||||
syntax.DefineOptionList("resource", ref resources, "Resources to embed");
|
||||
|
||||
syntax.DefineOption("h|help", ref help, "Help for compile native.");
|
||||
|
||||
syntax.DefineParameterList("source-files", ref sources, "Compilation sources");
|
||||
|
||||
helpText = syntax.GetHelpText();
|
||||
|
||||
if (tempOutDir == null)
|
||||
{
|
||||
syntax.ReportError("Option '--temp-output' is required");
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (ArgumentSyntaxException)
|
||||
catch (ArgumentSyntaxException exception)
|
||||
{
|
||||
return ExitFailed;
|
||||
Console.Error.WriteLine(exception.Message);
|
||||
help = true;
|
||||
returnCode = ExitFailed;
|
||||
}
|
||||
|
||||
if (help)
|
||||
{
|
||||
Console.WriteLine(helpText);
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
var translated = TranslateCommonOptions(commonOptions);
|
||||
|
|
|
@ -17,6 +17,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
public string AppDepSDKPath { get; set; }
|
||||
public string IlcPath { get; set; }
|
||||
|
||||
public bool IsHelp { get; set; }
|
||||
public int ReturnCode { get; set; }
|
||||
|
||||
public NativeCompileSettings GetNativeCompileSettings()
|
||||
{
|
||||
var config = NativeCompileSettings.Default;
|
||||
|
|
|
@ -19,6 +19,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
string ilcPath = null;
|
||||
string appDepSdk = null;
|
||||
string logPath = null;
|
||||
var help = false;
|
||||
string helpText = null;
|
||||
var returnCode = 0;
|
||||
|
||||
IReadOnlyList<string> references = Array.Empty<string>();
|
||||
IReadOnlyList<string> linklib = Array.Empty<string>();
|
||||
|
@ -27,6 +30,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
{
|
||||
ArgumentSyntax.Parse(args, syntax =>
|
||||
{
|
||||
syntax.HandleHelp = false;
|
||||
syntax.HandleErrors = false;
|
||||
|
||||
syntax.DefineOption("output", ref outputDirectory, "Output Directory for native executable.");
|
||||
syntax.DefineOption("temp-output", ref temporaryOutputDirectory, "Directory for intermediate files.");
|
||||
|
||||
|
@ -48,12 +54,17 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
// Optional Log Path
|
||||
syntax.DefineOption("logpath", ref logPath, "Use to dump Native Compilation Logs to a file.");
|
||||
|
||||
syntax.DefineOption("h|help", ref help, "Help for compile native.");
|
||||
|
||||
syntax.DefineParameter("INPUT_ASSEMBLY", ref inputAssembly,
|
||||
"The managed input assembly to compile to native.");
|
||||
|
||||
helpText = syntax.GetHelpText();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(inputAssembly))
|
||||
{
|
||||
syntax.ReportError("Input Assembly is a required parameter.");
|
||||
help = true;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration))
|
||||
|
@ -65,6 +76,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
catch (ArgumentException)
|
||||
{
|
||||
syntax.ReportError($"Invalid Configuration Option: {configuration}");
|
||||
help = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,13 +89,27 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
catch (ArgumentException)
|
||||
{
|
||||
syntax.ReportError($"Invalid Mode Option: {mode}");
|
||||
help = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (ArgumentSyntaxException)
|
||||
catch (ArgumentSyntaxException exception)
|
||||
{
|
||||
//return ExitFailed;
|
||||
Console.Error.WriteLine(exception.Message);
|
||||
help = true;
|
||||
returnCode = 1;
|
||||
}
|
||||
|
||||
if (help)
|
||||
{
|
||||
Console.WriteLine(helpText);
|
||||
|
||||
return new ArgValues
|
||||
{
|
||||
IsHelp = help,
|
||||
ReturnCode = returnCode
|
||||
};
|
||||
}
|
||||
|
||||
Console.WriteLine($"Input Assembly: {inputAssembly}");
|
||||
|
|
|
@ -32,6 +32,9 @@ namespace Microsoft.DotNet.Tools.Compiler.Native
|
|||
try
|
||||
{
|
||||
var cmdLineArgs = ArgumentsParser.Parse(args);
|
||||
|
||||
if (cmdLineArgs.IsHelp) return cmdLineArgs.ReturnCode;
|
||||
|
||||
var config = cmdLineArgs.GetNativeCompileSettings();
|
||||
|
||||
DirectoryExtensions.CleanOrCreateDirectory(config.OutputDirectory);
|
||||
|
|
Loading…
Reference in a new issue