Skip to content
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

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/Cli/dotnet/BuildServer/VBCSCompilerServer.cs
Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member Author

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.

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a private static too? The inconsistency between the fields is itching at me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in tests currently, I can add a comment.

Copy link
Member

Choose a reason for hiding this comment

The 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",
Expand All @@ -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);
}
}
}
}
Expand Down