提交 501dbf61 编写于 作者: B Brett V. Forsgren 提交者: GitHub

Merge pull request #19566 from brettfo/bypass-setoptions

bypass command line argument passing if no command line parser is available
......@@ -11,6 +11,8 @@ internal abstract partial class AbstractProject
{
#region Options
private string _lastParsedCompilerOptions;
/// Can be null if there is no <see cref="CommandLineParserService" /> available.
private CommandLineArguments _lastParsedCommandLineArguments;
private CompilationOptions _currentCompilationOptions;
private ParseOptions _currentParseOptions;
......@@ -47,23 +49,27 @@ private void SetArgumentsCore(string commandLine, CommandLineArguments commandLi
#endregion
/// <summary>
/// Creates and sets new options using the last parsed command line arguments.
/// Creates and sets new options using the last parsed command line arguments. In the case that the last
/// parsed options are <see langword="null"/> then this call is a NOP.
/// </summary>
protected void UpdateOptions()
{
AssertIsForeground();
CommandLineArguments lastParsedCommandLineArguments = _lastParsedCommandLineArguments;
Contract.ThrowIfNull(lastParsedCommandLineArguments);
var newParseOptions = CreateParseOptions(lastParsedCommandLineArguments);
var newCompilationOptions = CreateCompilationOptions(lastParsedCommandLineArguments, newParseOptions);
if (newCompilationOptions == CurrentCompilationOptions && newParseOptions == CurrentParseOptions)
if (lastParsedCommandLineArguments != null)
{
return;
// do nothing if the last parsed arguments aren't present, which is the case for languages that don't
// export an ICommandLineParserService like F#
var newParseOptions = CreateParseOptions(lastParsedCommandLineArguments);
var newCompilationOptions = CreateCompilationOptions(lastParsedCommandLineArguments, newParseOptions);
if (newCompilationOptions == CurrentCompilationOptions && newParseOptions == CurrentParseOptions)
{
return;
}
SetOptions(newCompilationOptions, newParseOptions);
}
SetOptions(newCompilationOptions, newParseOptions);
}
/// <summary>
......
......@@ -120,10 +120,12 @@ public void SetOptions(string commandLineForOptions)
ExecuteForegroundAction(() =>
{
var commandLineArguments = SetArgumentsAndUpdateOptions(commandLineForOptions);
SetRuleSetFile(commandLineArguments.RuleSetPath);
PostSetOptions(commandLineArguments);
if (commandLineArguments != null)
{
// some languages (e.g., F#) don't expose a command line parser and this might be `null`
SetRuleSetFile(commandLineArguments.RuleSetPath);
PostSetOptions(commandLineArguments);
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册