-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Include default RSP files for core compilers #80993
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
Changes from 6 commits
cb1c532
92d3e66
a3c20e6
9db4d4f
35e173a
4ae086d
e31f948
a3348be
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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| using Microsoft.Build.Utilities; | ||
| using Microsoft.CodeAnalysis.CommandLine; | ||
| using System.Runtime.InteropServices; | ||
| using System.IO; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.BuildTasks | ||
| { | ||
|
|
@@ -200,10 +201,19 @@ protected override string ToolNameWithoutExtension | |
| /// </summary> | ||
| protected override void AddResponseFileCommands(CommandLineBuilderExtension commandLine) | ||
| { | ||
| // Pass sdkpath if we are invoking core compiler from framework to preserve the behavior that framework compiler would have. | ||
| // Pass sdkpath and csc.rsp if we are invoking core compiler from framework to preserve the behavior that framework compiler would have. | ||
| if (IsSdkFrameworkToCoreBridgeTask) | ||
| { | ||
| commandLine.AppendSwitchIfNotNull("/sdkpath:", RuntimeEnvironment.GetRuntimeDirectory()); | ||
|
|
||
| if (!NoConfig) | ||
| { | ||
| var rspFile = Path.Combine(Path.GetDirectoryName(typeof(ManagedCompiler).Assembly.Location)!, "csc.rsp"); | ||
| if (File.Exists(rspFile)) | ||
| { | ||
| commandLine.AppendSwitchIfNotNull("@", rspFile); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| commandLine.AppendSwitchIfNotNull("/lib:", AdditionalLibPaths, ","); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -22,5 +22,10 @@ | |||
| <InternalsVisibleTo Include="Microsoft.Build.Tasks.CodeAnalysis.Sdk.UnitTests" /> | ||||
| </ItemGroup> | ||||
|
|
||||
| <ItemGroup> | ||||
| <None Include="$(MSBuildThisFileDirectory)..\..\..\CSharp\csc\csc.rsp" CopyToOutputDirectory="PreserveNewest" /> | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is inspired by other projects that include csc.rsp:
It works by not copying the file if it's not modified, so the builds are more performant
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is great, but I still would like to understand how exactly this option works. Other projects could have made a mistake. Since these files are not build artifacts, it doesn't feel appropriate to me to copy files only when they are newer. BTW, what exactly does it mean for a file to be newer for the purpose of this operation?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file is copied to the output directory only if the source file has newer timestamp than the target file (the one in the output directory of the project). I think this is the common default for many MSBuild operations. It's documented here: https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=vs-2022#none Looks like we could use IfDifferent (but that's a newer option: dotnet/docs#44059); or Always. |
||||
| <None Include="$(MSBuildThisFileDirectory)..\..\..\VisualBasic\vbc\vbc.rsp" CopyToOutputDirectory="PreserveNewest" /> | ||||
| </ItemGroup> | ||||
|
|
||||
| <Import Project="..\..\..\..\Dependencies\Contracts\Microsoft.CodeAnalysis.Contracts.projitems" Label="Shared" /> | ||||
| </Project> | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -187,8 +187,8 @@ End Module | |
| Assert.Contains(ExecutionConditionUtil.IsWindows ? "vbc.exe" : "vbc", result.Output); | ||
| } | ||
|
|
||
| [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
| public void StdLib_Csc(bool useSharedCompilation, bool disableSdkPath) | ||
| [Theory, PairwiseData, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
| public void StdLib_Csc(bool useSharedCompilation, bool disableSdkPath, bool noConfig) | ||
| { | ||
| if (_msbuildExecutable == null) return; | ||
|
|
||
|
|
@@ -199,35 +199,49 @@ public void StdLib_Csc(bool useSharedCompilation, bool disableSdkPath) | |
| new Dictionary<string, string> | ||
| { | ||
| { "File.cs", """ | ||
| using System.Linq; | ||
| System.Console.WriteLine("Hello from file"); | ||
| """ }, | ||
| { "Test.csproj", $""" | ||
| <Project> | ||
| <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Csc" AssemblyFile="{_buildTaskDll}" /> | ||
| <Target Name="CustomTarget"> | ||
| <Csc Sources="File.cs" UseSharedCompilation="{useSharedCompilation}" DisableSdkPath="{disableSdkPath}" /> | ||
| <Csc Sources="File.cs" UseSharedCompilation="{useSharedCompilation}" DisableSdkPath="{disableSdkPath}" NoConfig="{noConfig}" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It avoids exponential amount of test runs since I added new input. See https://aarnott.github.io/Xunit.Combinatorial/docs/combinatorial-vs-pairwise.html. The pairwise ones should be the interesting ones (I've verified the test still fails without the product change for example).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not find 8 cases too much and would be more comfortable with covering full matrix. I am uncomfortable with a situation when an "external" tool decides what combinations our tests cover and that combinations possibly changing between versions of that tool. My recommendation is to use full matrix or explicitly specifying combinations covered by the test. |
||
| </Target> | ||
| </Project> | ||
| """ }, | ||
| }); | ||
| _output.WriteLine(result.Output); | ||
|
|
||
| if (disableSdkPath) | ||
| if (disableSdkPath || noConfig) | ||
| { | ||
| Assert.NotEqual(0, result.ExitCode); | ||
| // Either error CS0006: Metadata file could not be found | ||
| // or error CS0518: Predefined type is not defined or imported | ||
| Assert.Contains("error CS", result.Output); | ||
| if (disableSdkPath && noConfig) | ||
| { | ||
| // error CS0246: The type or namespace name 'System' could not be found | ||
| Assert.Contains("error CS0246", result.Output); | ||
| } | ||
| else if (disableSdkPath) | ||
| { | ||
| // error CS0006: Metadata file could not be found | ||
| Assert.Contains("error CS0006", result.Output); | ||
| } | ||
| else | ||
| { | ||
| // error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' | ||
| Assert.Contains("error CS0234", result.Output); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| Assert.Equal(0, result.ExitCode); | ||
| Assert.Contains(useSharedCompilation ? "server processed compilation" : "using command line tool by design", result.Output); | ||
| } | ||
|
|
||
| Assert.Contains(useSharedCompilation ? "server processed compilation" : "using command line tool by design", result.Output); | ||
| } | ||
|
|
||
| [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
| public void StdLib_Vbc(bool useSharedCompilation, bool disableSdkPath) | ||
| [Theory, PairwiseData, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
| public void StdLib_Vbc(bool useSharedCompilation, bool disableSdkPath, bool noConfig) | ||
| { | ||
| if (_msbuildExecutable == null) return; | ||
|
|
||
|
|
@@ -240,31 +254,136 @@ public void StdLib_Vbc(bool useSharedCompilation, bool disableSdkPath) | |
| { "File.vb", """ | ||
| Public Module Program | ||
| Public Sub Main() | ||
| System.Console.WriteLine("Hello from file") | ||
| Console.WriteLine("Hello from file") | ||
| End Sub | ||
| End Module | ||
| """ }, | ||
| { "Test.vbproj", $""" | ||
| <Project> | ||
| <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="{_buildTaskDll}" /> | ||
| <Target Name="CustomTarget"> | ||
| <Vbc Sources="File.vb" UseSharedCompilation="{useSharedCompilation}" DisableSdkPath="{disableSdkPath}" /> | ||
| <Vbc Sources="File.vb" UseSharedCompilation="{useSharedCompilation}" DisableSdkPath="{disableSdkPath}" NoConfig="{noConfig}" /> | ||
| </Target> | ||
| </Project> | ||
| """ }, | ||
| }); | ||
| _output.WriteLine(result.Output); | ||
|
|
||
| if (disableSdkPath) | ||
| if (disableSdkPath || noConfig) | ||
| { | ||
| Assert.NotEqual(0, result.ExitCode); | ||
| // error BC2017: could not find library 'Microsoft.VisualBasic.dll' | ||
| Assert.Contains("error BC2017", result.Output); | ||
| if (disableSdkPath) | ||
| { | ||
| // error BC2017: could not find library 'Microsoft.VisualBasic.dll' | ||
| Assert.Contains("error BC2017", result.Output); | ||
| } | ||
| else | ||
| { | ||
| Assert.True(noConfig); | ||
| // error BC30451: 'Console' is not declared. It may be inaccessible due to its protection level. | ||
| Assert.Contains("error BC30451", result.Output); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| Assert.Equal(0, result.ExitCode); | ||
| Assert.Contains(useSharedCompilation ? "server processed compilation" : "using command line tool by design", result.Output); | ||
| } | ||
|
|
||
| Assert.Contains(useSharedCompilation ? "server processed compilation" : "using command line tool by design", result.Output); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that both RSPs are included: the default <c>csc.rsp</c> (which has <c>/r:System.Data.OracleClient</c>), | ||
| /// and the custom RSP (which has <c>/warnaserror+</c> so we get an error for using an obsolete type). | ||
| /// </summary> | ||
| [Theory, PairwiseData] | ||
| public void CustomRsp_Csc(bool includeCustomRsp, bool useSharedCompilation, bool noConfig) | ||
| { | ||
| if (_msbuildExecutable == null) return; | ||
|
|
||
| var result = RunCommandLineCompiler( | ||
| _msbuildExecutable, | ||
| "/m /nr:false /t:CustomTarget Test.csproj", | ||
| _tempDirectory, | ||
| new Dictionary<string, string> | ||
| { | ||
| { "File.cs", """ | ||
| new System.Data.OracleClient.OracleConnection(""); | ||
| """ }, | ||
| { "custom.rsp", """ | ||
| /warnaserror+ | ||
| """ }, | ||
| { "Test.csproj", $""" | ||
| <Project> | ||
| <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Csc" AssemblyFile="{_buildTaskDll}" /> | ||
| <Target Name="CustomTarget"> | ||
| <Csc Sources="File.cs" UseSharedCompilation="{useSharedCompilation}" ResponseFiles="{(includeCustomRsp ? "custom.rsp" : "")}" NoConfig="{noConfig}" /> | ||
| </Target> | ||
| </Project> | ||
| """ }, | ||
| }); | ||
| _output.WriteLine(result.Output); | ||
|
|
||
| Assert.Equal(!includeCustomRsp && !noConfig, 0 == result.ExitCode); | ||
| if (noConfig) | ||
| { | ||
| // error CS0234: The type or namespace name 'Data' does not exist in the namespace 'System' | ||
| Assert.Contains("error CS0234", result.Output); | ||
| } | ||
| else | ||
| { | ||
| // warning CS0618: The type is obsolete | ||
| Assert.Contains($"{(includeCustomRsp ? "error" : "warning")} CS0618", result.Output); | ||
| } | ||
|
|
||
| Assert.Contains(useSharedCompilation ? "server processed compilation" : "using command line tool by design", result.Output); | ||
| } | ||
|
|
||
| /// <inheritdoc cref="CustomRsp_Csc"/> | ||
| [Theory, PairwiseData] | ||
| public void CustomRsp_Vbc(bool includeCustomRsp, bool useSharedCompilation, bool noConfig) | ||
| { | ||
| if (_msbuildExecutable == null) return; | ||
|
|
||
| var result = RunCommandLineCompiler( | ||
| _msbuildExecutable, | ||
| "/m /nr:false /t:CustomTarget Test.vbproj", | ||
| _tempDirectory, | ||
| new Dictionary<string, string> | ||
| { | ||
| { "File.vb", """ | ||
| Public Module Program | ||
| Public Sub Main() | ||
| Dim x As Object = New System.Data.OracleClient.OracleConnection("") | ||
| End Sub | ||
| End Module | ||
| """ }, | ||
| { "custom.rsp", """ | ||
| /warnaserror+ | ||
| """ }, | ||
| { "Test.vbproj", $""" | ||
| <Project> | ||
| <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc" AssemblyFile="{_buildTaskDll}" /> | ||
| <Target Name="CustomTarget"> | ||
| <Vbc Sources="File.vb" UseSharedCompilation="{useSharedCompilation}" ResponseFiles="{(includeCustomRsp ? "custom.rsp" : "")}" NoConfig="{noConfig}" /> | ||
| </Target> | ||
| </Project> | ||
| """ }, | ||
| }); | ||
| _output.WriteLine(result.Output); | ||
|
|
||
| Assert.Equal(!includeCustomRsp && !noConfig, 0 == result.ExitCode); | ||
| if (noConfig) | ||
| { | ||
| // error BC30002: Type 'System.Data.OracleClient.OracleConnection' is not defined. | ||
| Assert.Contains("error BC30002", result.Output); | ||
| } | ||
| else | ||
| { | ||
| // warning BC40000: The type is obsolete | ||
| Assert.Contains($"{(includeCustomRsp ? "error" : "warning")} BC40000", result.Output); | ||
| } | ||
|
|
||
| Assert.Contains(useSharedCompilation ? "server processed compilation" : "using command line tool by design", result.Output); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
| using Microsoft.CodeAnalysis.BuildTasks.UnitTests; | ||
| using Roslyn.Test.Utilities; | ||
|
|
@@ -11,6 +12,8 @@ namespace Microsoft.CodeAnalysis.BuildTasks.Sdk.UnitTests; | |
|
|
||
| public sealed class CscTests | ||
| { | ||
| private static string RspFilePath => Path.Combine(Path.GetDirectoryName(typeof(ManagedCompiler).Assembly.Location)!, "csc.rsp"); | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
| public void StdLib() | ||
| { | ||
|
|
@@ -19,7 +22,7 @@ public void StdLib() | |
| Sources = MSBuildUtil.CreateTaskItems("test.cs"), | ||
| }; | ||
|
|
||
| AssertEx.Equal($"/sdkpath:{RuntimeEnvironment.GetRuntimeDirectory()} /out:test.exe test.cs", csc.GenerateResponseFileContents()); | ||
| AssertEx.Equal($"/sdkpath:{RuntimeEnvironment.GetRuntimeDirectory()} @{RspFilePath} /out:test.exe test.cs", csc.GenerateResponseFileContents()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
|
|
@@ -31,6 +34,6 @@ public void StdLib_DisableSdkPath() | |
| DisableSdkPath = true, | ||
| }; | ||
|
|
||
| AssertEx.Equal($"/sdkpath:{RuntimeEnvironment.GetRuntimeDirectory()} /nosdkpath /out:test.exe test.cs", csc.GenerateResponseFileContents()); | ||
| AssertEx.Equal($"/sdkpath:{RuntimeEnvironment.GetRuntimeDirectory()} @{RspFilePath} /nosdkpath /out:test.exe test.cs", csc.GenerateResponseFileContents()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.IO; | ||
| using System.Runtime.InteropServices; | ||
| using Microsoft.CodeAnalysis.BuildTasks.UnitTests; | ||
| using Roslyn.Test.Utilities; | ||
|
|
@@ -11,6 +12,8 @@ namespace Microsoft.CodeAnalysis.BuildTasks.Sdk.UnitTests; | |
|
|
||
| public sealed class VbcTests | ||
| { | ||
| private static string RspFilePath => Path.Combine(Path.GetDirectoryName(typeof(ManagedCompiler).Assembly.Location)!, "vbc.rsp"); | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
| public void StdLib() | ||
| { | ||
|
|
@@ -19,7 +22,7 @@ public void StdLib() | |
| Sources = MSBuildUtil.CreateTaskItems("test.vb"), | ||
| }; | ||
|
|
||
| AssertEx.Equal($"/sdkpath:{RuntimeEnvironment.GetRuntimeDirectory()} /optionstrict:custom /out:test.exe test.vb", vbc.GenerateResponseFileContents()); | ||
| AssertEx.Equal($"/sdkpath:{RuntimeEnvironment.GetRuntimeDirectory()} @{RspFilePath} /optionstrict:custom /out:test.exe test.vb", vbc.GenerateResponseFileContents()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79907")] | ||
|
|
@@ -31,6 +34,6 @@ public void StdLib_DisableSdkPath() | |
| DisableSdkPath = true, | ||
| }; | ||
|
|
||
| AssertEx.Equal($"/sdkpath:{RuntimeEnvironment.GetRuntimeDirectory()} /optionstrict:custom /nosdkpath /out:test.exe test.vb", vbc.GenerateResponseFileContents()); | ||
| AssertEx.Equal($"/sdkpath:{RuntimeEnvironment.GetRuntimeDirectory()} @{RspFilePath} /optionstrict:custom /nosdkpath /out:test.exe test.vb", vbc.GenerateResponseFileContents()); | ||
| } | ||
| } | ||
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.
How is the defaut RSP file specified in the framework based build?
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.
It is deployed alongside
csc.exe. The compiler then checks the file exists and includes it automatically:roslyn/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs
Lines 130 to 133 in a065eae
I first tried to do that for the core compiler too but that would be a breaking change (could cause errors if the DLLs specified in the response file do not exist).
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.
Overall I get what this PR is trying to accomplish and why we need to do it. What I'm trying to square in my mind is how we limit it to the cases that need it and think through the cases going forward.
Short term you're attaching this logic to coming from the bridge task which makes sense. And really the only way I can see us getting this in now is doing exactly this. In the long term though I'm not sure that is the right approach. Love or hate the raw
<Csc>in targets files customers do it. As customers migrate frommsbuildtodotnet buildI'm guessing the need for raw<Csc>in targets will remain. Hence over the long term I think we will need to support this when running underdotnet build. That is harder because there is no way, today at least, to find the sdk reference path (see teams chat). That means we can't do a no args compile indotnet build.Basically I think in the long term we'll need support for the
dotnet buildinfra to provide path to the appropriateMicrosoft.NetCore.App.Refpackage. That would then translate to/sdkpathand we could have a simple default.rspfor the core compiler. Then<Csc>would work there. This is a change across a few components so we probably should start tracking that.Now that I typed a lot ... back to what to do about this PR
I'm thinking that we should probably only do this when:
/noconfigNoConfigis not passed (yes a double negative)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.
@rainersigwald, @baronfel this is why I've been aksing about finding the sdk path inside of
dotnet buildThere 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 not sure what you mean by this. The Csc task doesn't see the current TargetFramework (and adding a new parameter for it could introduce more breaks as we seen recently). And the SDK passes
NoConfig=truewhen TF is specified, so it sounds like (3) supersedes (2)?Regarding (1) and (3), those are what this PR indeed checks. Specifically, only the bridge task will include the default csc.rsp if it exists and
NoConfig==false.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.
It's one of the existing arguments. See here
Where is that done? If that is already the case then I'd feel better.
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.
Ah interesting, thanks!
Well, the SDK passes NoConfig=true always here.