From d20a0376c084869ff40ea847722034faabffe938 Mon Sep 17 00:00:00 2001 From: Ashley Hauck Date: Mon, 9 Oct 2017 10:57:39 -0700 Subject: [PATCH] Factor DotnetHostInfo creation into a common method --- .../Core/MSBuildTask/InteractiveCompiler.cs | 31 +---------- .../Core/MSBuildTask/ManagedCompiler.cs | 54 ++++++++++--------- 2 files changed, 31 insertions(+), 54 deletions(-) diff --git a/src/Compilers/Core/MSBuildTask/InteractiveCompiler.cs b/src/Compilers/Core/MSBuildTask/InteractiveCompiler.cs index 38f6e22cfef..f1fbdbff249 100644 --- a/src/Compilers/Core/MSBuildTask/InteractiveCompiler.cs +++ b/src/Compilers/Core/MSBuildTask/InteractiveCompiler.cs @@ -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) { diff --git a/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs b/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs index 38229f54ee3..06d4267a8a4 100644 --- a/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs +++ b/src/Compilers/Core/MSBuildTask/ManagedCompiler.cs @@ -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); + /// /// Method for testing only /// -- GitLab