-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove more private reflection from compiler #32257
Conversation
Use multi-target instead of reflection
This removes the remaining private reflection code from the compiler and replaces it with multi-targeting approaches.
CC @dotnet/roslyn-compiler for review |
var expectedCompilerPath = Path.Combine(clientDir, ServerNameCoreClr); | ||
expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet"; | ||
processArguments = $@"""{expectedCompilerPath}"" ""-pipename:{pipeName}"""; | ||
var serverPathWithoutExetnsion = Path.Combine(clientDir, "VBCSCompiler"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serverPathWithoutExetnsion [](start = 16, length = 26)
typo: Extension #Resolved
@@ -55,7 +56,7 @@ public enum TargetFramework | |||
|
|||
public static class TargetFrameworkUtil | |||
{ | |||
public static MetadataReference StandardCSharpReference => CoreClrShim.IsRunningOnCoreClr ? NetStandard20.MicrosoftCSharpRef : TestBase.CSharpDesktopRef; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CoreClrShim.IsRunningOnCoreClr [](start = 67, length = 30)
It looks like you're replacing all uses of CoreClrShim.IsRunningOnCoreClr
. Can that API be removed then? #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Scripting still uses it and pulling it out from there is a lot of work. It's on my list but wanted it to be a separate change as it's likely a bit of refactoring. #WontFix
_culture = new Lazy<CultureInfo>(() => new CultureInfo(culture, useUserOverride: false)); | ||
_uiCulture = new Lazy<CultureInfo>(() => new CultureInfo(uiCulture, useUserOverride: false)); | ||
#elif NETCOREAPP2_1 | ||
_culture = new Lazy<CultureInfo>(() => new CultureInfo(culture)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
)); [](start = 74, length = 3)
We used to have a distinction of useUserOverride:
being true or false. Did something change that allows us to no longer care? #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code here preferred the useUserOverride: false
approach. But when we went to netcoreapp1.1 originally that overload wasn't present and we were forced to pick a different one. Now with netcoreapp2.1 the overload is back and we can go with our original preferred approach. #ByDesign
/// This gets information about invoking a tool on the current runtime. This will attempt to | ||
/// execute a tool as an EXE when on desktop and using dotnet when on CoreClr. | ||
/// </summary> | ||
internal static (string ProcessFilePath, string CommandLineArguments, string ToolFilePath) GetProcessInfo(string toolFilePathWithoutExtension, string commandLineArguments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProcessFilePath [](start = 32, length = 15)
nit: tuple names should be lower-cased (parallel with parameter names) #Resolved
Debug.Assert(!toolFilePathWithoutExtension.EndsWith(".dll") && !toolFilePathWithoutExtension.EndsWith(".exe")); | ||
|
||
var toolFilePath = $"{toolFilePathWithoutExtension}.{ToolExtension}"; | ||
if (IsDotnetHost(out string pathToDotNet)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Dotnet vs. DotNet. This line has both conventions #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've confirmed that Dotnet is preferred. Will use that. #Resolved
/// Get the path to the dotnet executable. In the case the host did not provide this information | ||
/// in the environment this will return simply "dotnet". | ||
/// </summary> | ||
internal static string GetDotnetPathOrDefault() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal [](start = 8, length = 8)
private? #Resolved
/// Get the path to the dotnet executable. This will throw in the case it is not properly setup | ||
/// by the environment. | ||
/// </summary> | ||
internal static string GetDotnetPath() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal [](start = 8, length = 8)
private?
Same comment for IsDotnetHost
and DotnetHostPathEnvironmentName
above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 6)
@roslyn-compiler could I get one more review here? |
After more searching it is clear that DotNet is preferred in API signatures over Dotnet. Easy to see when you look at the reference source https://referencesource.microsoft.com/#q=dotnet
<Compile Include="..\..\Shared\NamedPipeUtil.cs" /> | ||
<Compile Include="..\..\Shared\BuildClient.cs"> | ||
<Link>BuildClient.cs</Link> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is documented in https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=vs-2017 as follows:
Link | Optional string. The notational path to be displayed when the file is physically located outside the influence of the project file.
Does this mean this only affects the build logs, not the behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure if it affects the build logs or not but it does affect the UI in Visual Studio. You can use this field to change how the file is displayed, and in what folder, in the VS solution explore.
The name for the named pipe used between MSBuild and VBCSCompiler is generated from a combination of values including the current user name, specifically `%USERNAME%`. It is possible for this value to have spaces in it and hence the argument must be quoted when passing it to the command line of VBCSCompiler instances. Regression initially introduced: dotnet#32257
The name for the named pipe used between MSBuild and VBCSCompiler is generated from a combination of values including the current user name, specifically `%USERNAME%`. It is possible for this value to have spaces in it and hence the argument must be quoted when passing it to the command line of VBCSCompiler instances. Regression initially introduced: dotnet#32257
Remove more private reflection from compiler
This change continues the removal of private reflection code from the compiler code base and instead relying on mulit-targeting to have detect the runtime. This also necessarily cleans up a number of our
#if
checks in the code base.Follow up to #31763