-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix build task custom compiler logic #80948
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
09b9f48
01b628a
4a29883
bc6eb81
3fcf492
af017a0
8bc0f6c
f6a8ac2
a7f71fe
f498c4a
2b235a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| using System.Linq; | ||
| using Microsoft.CodeAnalysis.Test.Utilities; | ||
| using Roslyn.Test.Utilities; | ||
| using Roslyn.Utilities; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
|
|
@@ -119,72 +120,151 @@ protected static ProcessResult RunCommandLineCompiler( | |
| additionalEnvironmentVars); | ||
| } | ||
|
|
||
| /// <param name="overrideToolExe"> | ||
| /// Setting ToolExe to "csc.exe" should use the built-in compiler regardless of apphost being used or not. | ||
| /// </param> | ||
| [Theory, CombinatorialData] | ||
| public void SdkBuild_Csc(bool useSharedCompilation) | ||
| [WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2615118")] | ||
| public void SdkBuild_Csc(bool useSharedCompilation, bool overrideToolExe, bool useAppHost) | ||
| { | ||
| var result = RunMsbuild( | ||
| "/v:n /m /nr:false /t:Build /restore Test.csproj", | ||
| _tempDirectory, | ||
| new Dictionary<string, string> | ||
| if (!ManagedToolTask.IsBuiltinToolRunningOnCoreClr && !useAppHost) | ||
| { | ||
| _output.WriteLine("Skipping test case: netfx compiler always uses apphost."); | ||
| return; | ||
| } | ||
|
|
||
| var originalAppHost = Path.Combine(ManagedToolTask.GetToolDirectory(), $"csc{PlatformInformation.ExeExtension}"); | ||
| var backupAppHost = originalAppHost + ".bak"; | ||
| if (!useAppHost) | ||
| { | ||
| _output.WriteLine($"Apphost: {originalAppHost}"); | ||
| File.Move(originalAppHost, backupAppHost); | ||
| } | ||
|
|
||
| ProcessResult? result; | ||
|
|
||
| try | ||
| { | ||
| result = RunMsbuild( | ||
| "/v:n /m /nr:false /t:Build /restore Test.csproj" + | ||
| (overrideToolExe ? $" /p:CscToolExe=csc{PlatformInformation.ExeExtension}" : ""), | ||
| _tempDirectory, | ||
| new Dictionary<string, string> | ||
| { | ||
| { "File.cs", """ | ||
| class Program { static void Main() { System.Console.WriteLine("Hello from file"); } } | ||
| """ }, | ||
| { "Test.csproj", $""" | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Csc" AssemblyFile="{_buildTaskDll}" /> | ||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <UseSharedCompilation>{useSharedCompilation}</UseSharedCompilation> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """ }, | ||
| }); | ||
| } | ||
| finally | ||
| { | ||
| if (!useAppHost) | ||
| { | ||
| { "File.cs", """ | ||
| class Program { static void Main() { System.Console.WriteLine("Hello from file"); } } | ||
| """ }, | ||
| { "Test.csproj", $""" | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Csc" AssemblyFile="{_buildTaskDll}" /> | ||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <UseSharedCompilation>{useSharedCompilation}</UseSharedCompilation> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """ }, | ||
| }); | ||
| File.Move(backupAppHost, originalAppHost); | ||
| } | ||
| } | ||
|
|
||
| if (result == null) return; | ||
|
|
||
| _output.WriteLine(result.Output); | ||
|
|
||
| Assert.Equal(0, result.ExitCode); | ||
| Assert.Contains(useSharedCompilation ? "server processed compilation" : "using command line tool by design", result.Output); | ||
| Assert.DoesNotContain("csc.dll", result.Output); | ||
| Assert.Contains(ExecutionConditionUtil.IsWindows ? "csc.exe" : "csc", result.Output); | ||
|
|
||
| if (useAppHost) | ||
| { | ||
| Assert.DoesNotContain("csc.dll", result.Output); | ||
| Assert.Contains($"csc{PlatformInformation.ExeExtension}", result.Output); | ||
| } | ||
| else | ||
| { | ||
| Assert.Contains("csc.dll", result.Output); | ||
| Assert.DoesNotContain("csc.exe", result.Output); | ||
|
||
| } | ||
| } | ||
|
|
||
| /// <param name="overrideToolExe"> | ||
| /// Setting ToolExe to "vbc.exe" should use the built-in compiler regardless of apphost being used or not. | ||
| /// </param> | ||
| [Theory, CombinatorialData] | ||
| public void SdkBuild_Vbc(bool useSharedCompilation) | ||
| [WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2615118")] | ||
| public void SdkBuild_Vbc(bool useSharedCompilation, bool overrideToolExe, bool useAppHost) | ||
| { | ||
| var result = RunMsbuild( | ||
| "/v:n /m /nr:false /t:Build /restore Test.vbproj", | ||
| _tempDirectory, | ||
| new Dictionary<string, string> | ||
| if (!ManagedToolTask.IsBuiltinToolRunningOnCoreClr && !useAppHost) | ||
| { | ||
| _output.WriteLine("Skipping test case: netfx compiler always uses apphost."); | ||
| return; | ||
| } | ||
|
|
||
| var originalAppHost = Path.Combine(ManagedToolTask.GetToolDirectory(), $"vbc{PlatformInformation.ExeExtension}"); | ||
| var backupAppHost = originalAppHost + ".bak"; | ||
| if (!useAppHost) | ||
| { | ||
| File.Move(originalAppHost, backupAppHost); | ||
| } | ||
|
|
||
| ProcessResult? result; | ||
|
|
||
| try | ||
| { | ||
| result = RunMsbuild( | ||
| "/v:n /m /nr:false /t:Build /restore Test.vbproj" + | ||
| (overrideToolExe ? $" /p:VbcToolExe=vbc{PlatformInformation.ExeExtension}" : ""), | ||
| _tempDirectory, | ||
| new Dictionary<string, string> | ||
| { | ||
| { "File.vb", """ | ||
| Public Module Program | ||
| Public Sub Main() | ||
| System.Console.WriteLine("Hello from file") | ||
| End Sub | ||
| End Module | ||
| """ }, | ||
| { "Test.vbproj", $""" | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="{_buildTaskDll}" /> | ||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <UseSharedCompilation>{useSharedCompilation}</UseSharedCompilation> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """ }, | ||
| }); | ||
| } | ||
| finally | ||
| { | ||
| if (!useAppHost) | ||
| { | ||
| { "File.vb", """ | ||
| Public Module Program | ||
| Public Sub Main() | ||
| System.Console.WriteLine("Hello from file") | ||
| End Sub | ||
| End Module | ||
| """ }, | ||
| { "Test.vbproj", $""" | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="{_buildTaskDll}" /> | ||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <UseSharedCompilation>{useSharedCompilation}</UseSharedCompilation> | ||
| </PropertyGroup> | ||
| </Project> | ||
| """ }, | ||
| }); | ||
| File.Move(backupAppHost, originalAppHost); | ||
| } | ||
| } | ||
|
|
||
| if (result == null) return; | ||
|
|
||
| _output.WriteLine(result.Output); | ||
|
|
||
| Assert.Equal(0, result.ExitCode); | ||
| Assert.Contains(useSharedCompilation ? "server processed compilation" : "using command line tool by design", result.Output); | ||
| Assert.DoesNotContain("vbc.dll", result.Output); | ||
| Assert.Contains(ExecutionConditionUtil.IsWindows ? "vbc.exe" : "vbc", result.Output); | ||
|
|
||
| if (useAppHost) | ||
| { | ||
| Assert.DoesNotContain("vbc.dll", result.Output); | ||
| Assert.Contains($"vbc{PlatformInformation.ExeExtension}", result.Output); | ||
| } | ||
| else | ||
| { | ||
| Assert.Contains("vbc.dll", result.Output); | ||
| Assert.DoesNotContain("vbc.exe", result.Output); | ||
| } | ||
| } | ||
|
|
||
| [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
|
|
||
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 would just check against
AppHostToolNameonly. Not sure there is vale in supportingCscToolExecomparing tocsc.dll.Uh oh!
There was an error while loading. Please reload this page.
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.
That's what I had before I realized it doesn't work. If
ToolExeis not overridden by a customer, it is equal toToolName(e.g.,csc.dll) and soToolExe == AppHostToolNameisfalse, which would lead toUsingBuiltinToolbeingfalsewhich is wrong. There are tests for that.Uh oh!
There was an error while loading. Please reload this page.
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.
You're right it also means we now support a scenario where customer explicitly sets
ToolExe = "csc.dll"(but only if apphost is disabled) but I don't see a simple way around that.