提交 d20a0376 编写于 作者: A Ashley Hauck

Factor DotnetHostInfo creation into a common method

上级 e4584e21
......@@ -191,21 +191,7 @@ private DotnetHost DotnetHostInfo
AddCommandLineCommands(commandLineBuilder);
var commandLine = commandLineBuilder.ToString();
// ToolExe delegates back to ToolName if the override is not
// set. So, if ToolExe == ToolName, we know ToolExe is not
// explicitly overriden. So, if both ToolPath is unset and
// ToolExe == ToolName, we know nothing is overridden, and
// we can use our own csc.
if (string.IsNullOrEmpty(ToolPath) && ToolExe == ToolName)
{
_dotnetHostInfo = DotnetHost.CreateManagedInvocationTool(ToolName, commandLine);
}
else
{
// Explicitly provided ToolPath or ToolExe, don't try to
// figure anything out
_dotnetHostInfo = DotnetHost.CreateNativeInvocationTool(Path.Combine(ToolPath ?? "", ToolExe), commandLine);
}
_dotnetHostInfo = ManagedCompiler.CreateDotnetHostInfo(ToolPath, ToolExe, ToolName, commandLine);
}
return _dotnetHostInfo;
}
......@@ -215,20 +201,7 @@ private DotnetHost DotnetHostInfo
protected abstract string ToolNameWithoutExtension { get; }
protected sealed override string ToolName
{
get
{
if (CoreClrShim.IsRunningOnCoreClr)
{
return $"{ToolNameWithoutExtension}.dll";
}
else
{
return $"{ToolNameWithoutExtension}.exe";
}
}
}
protected sealed override string ToolName => ManagedCompiler.GenerateToolName(ToolNameWithoutExtension);
protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
{
......
......@@ -409,6 +409,25 @@ public string LangVersion
#endregion
internal static DotnetHost CreateDotnetHostInfo(string toolPath, string toolExe, string toolName, string commandLine)
{
// ToolExe delegates back to ToolName if the override is not
// set. So, if ToolExe == ToolName, we know ToolExe is not
// explicitly overriden. So, if both ToolPath is unset and
// ToolExe == ToolName, we know nothing is overridden, and
// we can use our own csc.
if (string.IsNullOrEmpty(toolPath) && toolExe == toolName)
{
return DotnetHost.CreateManagedInvocationTool(toolName, commandLine);
}
else
{
// Explicitly provided ToolPath or ToolExe, don't try to
// figure anything out
return DotnetHost.CreateNativeInvocationTool(Path.Combine(toolPath ?? "", toolExe), commandLine);
}
}
private DotnetHost _dotnetHostInfo;
private DotnetHost DotnetHostInfo
{
......@@ -420,21 +439,7 @@ private DotnetHost DotnetHostInfo
AddCommandLineCommands(commandLineBuilder);
var commandLine = commandLineBuilder.ToString();
// ToolExe delegates back to ToolName if the override is not
// set. So, if ToolExe == ToolName, we know ToolExe is not
// explicitly overriden. So, if both ToolPath is unset and
// ToolExe == ToolName, we know nothing is overridden, and
// we can use our own csc.
if (string.IsNullOrEmpty(ToolPath) && ToolExe == ToolName)
{
_dotnetHostInfo = DotnetHost.CreateManagedInvocationTool(ToolName, commandLine);
}
else
{
// Explicitly provided ToolPath or ToolExe, don't try to
// figure anything out
_dotnetHostInfo = DotnetHost.CreateNativeInvocationTool(Path.Combine(ToolPath ?? "", ToolExe), commandLine);
}
_dotnetHostInfo = CreateDotnetHostInfo(ToolPath, ToolExe, ToolName, commandLine);
}
return _dotnetHostInfo;
}
......@@ -442,21 +447,20 @@ private DotnetHost DotnetHostInfo
protected abstract string ToolNameWithoutExtension { get; }
protected sealed override string ToolName
internal static string GenerateToolName(string toolNameWithoutExtension)
{
get
if (CoreClrShim.IsRunningOnCoreClr)
{
if (CoreClrShim.IsRunningOnCoreClr)
{
return $"{ToolNameWithoutExtension}.dll";
}
else
{
return $"{ToolNameWithoutExtension}.exe";
}
return $"{toolNameWithoutExtension}.dll";
}
else
{
return $"{toolNameWithoutExtension}.exe";
}
}
protected sealed override string ToolName => GenerateToolName(ToolNameWithoutExtension);
/// <summary>
/// Method for testing only
/// </summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册