-
Notifications
You must be signed in to change notification settings - Fork 1.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
Shutdown toolset compilers #43135
Shutdown toolset compilers #43135
Changes from all commits
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 |
---|---|---|
|
@@ -3,12 +3,18 @@ | |
|
||
using System.Reflection; | ||
using Microsoft.DotNet.Cli; | ||
using Microsoft.DotNet.Cli.Utils; | ||
using Microsoft.DotNet.CommandFactory; | ||
using NuGet.Configuration; | ||
|
||
namespace Microsoft.DotNet.BuildServer | ||
{ | ||
internal class VBCSCompilerServer : IBuildServer | ||
{ | ||
private static readonly string s_toolsetPackageName = "microsoft.net.sdk.compilers.toolset"; | ||
private static readonly string s_vbcsCompilerExeFileName = "VBCSCompiler.exe"; | ||
private static readonly string s_shutdownArg = "-shutdown"; | ||
|
||
internal static readonly string VBCSCompilerPath = Path.Combine( | ||
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. Can this be a 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's used in tests currently, I can add a comment. 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. No need for comment. Was just curious. |
||
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), | ||
"Roslyn", | ||
|
@@ -28,18 +34,46 @@ public VBCSCompilerServer(ICommandFactory commandFactory = null) | |
|
||
public void Shutdown() | ||
{ | ||
var command = _commandFactory | ||
.Create("exec", new[] { VBCSCompilerPath, "-shutdown" }) | ||
.CaptureStdOut() | ||
.CaptureStdErr(); | ||
List<string> errors = null; | ||
|
||
// Shutdown the compiler from the SDK. | ||
execute(_commandFactory.Create("exec", [VBCSCompilerPath, s_shutdownArg]), ref errors); | ||
|
||
// Shutdown toolset compilers. | ||
var nuGetPackageRoot = SettingsUtility.GetGlobalPackagesFolder(Settings.LoadDefaultSettings(root: null)); | ||
var toolsetPackageDirectory = Path.Join(nuGetPackageRoot, s_toolsetPackageName); | ||
if (Directory.Exists(toolsetPackageDirectory)) | ||
{ | ||
foreach (var versionDirectory in Directory.EnumerateDirectories(toolsetPackageDirectory)) | ||
{ | ||
var vbcsCompilerPath = Path.Join(versionDirectory, s_vbcsCompilerExeFileName); | ||
if (File.Exists(vbcsCompilerPath)) | ||
{ | ||
execute(CommandFactoryUsingResolver.Create(vbcsCompilerPath, [s_shutdownArg]), ref errors); | ||
} | ||
} | ||
} | ||
|
||
var result = command.Execute(); | ||
if (result.ExitCode != 0) | ||
if (errors?.Count > 0) | ||
{ | ||
throw new BuildServerException( | ||
string.Format( | ||
LocalizableStrings.ShutdownCommandFailed, | ||
result.StdErr)); | ||
string.Join(Environment.NewLine, errors))); | ||
} | ||
|
||
static void execute(ICommand command, ref List<string> errors) | ||
{ | ||
command = command | ||
.CaptureStdOut() | ||
.CaptureStdErr(); | ||
|
||
var result = command.Execute(); | ||
if (result.ExitCode != 0) | ||
{ | ||
errors ??= new List<string>(); | ||
errors.Add(result.StdErr); | ||
} | ||
} | ||
} | ||
} | ||
|
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.
(note that this PR targets release/9.0.1xx, but I'm unsure that's correct)
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.
Where did you want to ship this? 9.0.1xx is still open for checkins unless they are breaking changes or high risk.
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.
Ideally .NET 9 so it's shipped with the other torn sdk changes, I wasn't sure it meets the bar, but it shouldn't be high risk.