-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MSBuild server #7634
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
MSBuild server #7634
Conversation
Fixes #7374, #7373 Context MSBuild client is a new code path that is triggered with opt-in env variable. It sends the build request for execution to the MSBuild server node. This approach avoids to do execute targets and tasks into a short-living process from CLI tools like .NET SDK and MSBuild.exe. Changes Made This PR implements a new MSBuild client classes able to communicate with MSBuild server node via the named pipe. Testing Manually tested. Automatic tests will be added in another PR. Co-authored-by: Forgind <Forgind@users.noreply.github.com> Co-authored-by: Roman Konecny <rokonecn@microsoft.com>
* Some instrumentation * Add more details to ETW * Use class-wide variables
donJoseLuis
left a comment
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.
my review's timebox expired. Please take a look at my comments, I only managed to review 5/28 files.
* Added cancelation feature
Forgind
left a comment
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.
Just need to review OutOfProcServerNode
* Fix control sequence emission * Some cleanup
…he (#7655) * Solving memory leak by reusing BuildManager and ProjectRoolElementCache * Do not clear project root element cache if in auto reload.
* Add giant test for MSBuild Server * Add comm traces * Remove test that uses MSBUILDNOINPROCNODE flag: it checks the wrong behavior. * Add comments about WaitForExit and set a timeout for the process execution. Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com> Co-authored-by: Roman Konecny <rokonecn@microsoft.com>
…build into feature/msbuild-server
* Added cancellation support for client. * Added cancellation support for client. * Fixing wrong merge * Removed "Cancelled" exit type * Resolving comments
* Handle race condition * Clean running server nodes in tests.
Fixes #7658 Context See #7658 Changes Made MSBuild Server clients detects: ConsoleBufferWidth, AcceptAnsiColorCodes, ConsoleIsScreen, ConsoleBackgroundColor of current console and sent it to Server in ServerNodeBuildCommand. Server overrides ConsoleConfigueation so our loggers can get target console configuration. Testing Manual Notes There are no expected functional changes for NON Server and hence also VS scenarios. Co-authored-by: Forgind <Forgind@users.noreply.github.com> Co-authored-by: AR-May <67507805+AR-May@users.noreply.github.com>
…build into feature/msbuild-server
* Send command line as string[] in dotnet builds.
* Fixed some commented issues
* Update doc * Fixed typo * Fixed another typo * Update documentation/MSBuild-Server.md Co-authored-by: Forgind <Forgind@users.noreply.github.com> * Update documentation/MSBuild-Server.md Co-authored-by: Forgind <Forgind@users.noreply.github.com> * Update documentation/MSBuild-Server.md Co-authored-by: Forgind <Forgind@users.noreply.github.com> * Update documentation/MSBuild-Server.md Co-authored-by: Forgind <Forgind@users.noreply.github.com> * Update documentation/MSBuild-Server.md Co-authored-by: Forgind <Forgind@users.noreply.github.com> * Update documentation/MSBuild-Server.md Co-authored-by: Forgind <Forgind@users.noreply.github.com> * Resolving comments Co-authored-by: Forgind <Forgind@users.noreply.github.com>
…build into feature/msbuild-server # Conflicts: # src/Build/BackEnd/Client/MSBuildClient.cs
…/msbuild-server # Conflicts: # src/Build/PublicAPI/netstandard/PublicAPI.Unshipped.txt
* Reduces allocations in case the tracing is not enabled * Resolving comment
|
Notes from call with @rokonec going over the headlines on this:
|
Forgind
left a comment
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.
🚢
| processStartInfo.RedirectStandardInput = true; | ||
| processStartInfo.RedirectStandardOutput = true; | ||
| processStartInfo.RedirectStandardError = true; | ||
| processStartInfo.CreateNoWindow = (creationFlags | BackendNativeMethods.CREATENOWINDOW) == BackendNativeMethods.CREATENOWINDOW; |
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.
| processStartInfo.CreateNoWindow = (creationFlags | BackendNativeMethods.CREATENOWINDOW) == BackendNativeMethods.CREATENOWINDOW; | |
| processStartInfo.CreateNoWindow = (creationFlags & BackendNativeMethods.CREATENOWINDOW) == BackendNativeMethods.CREATENOWINDOW; |
?
| /// </summary> | ||
| internal sealed class ServerNodeBuildCommand : INodePacket | ||
| { | ||
| private string _commandLine = default!; |
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'd prefer just disabling nullable here if that's viable, but it isn't critical.
| { | ||
| Console.CancelKeyPress += Console_CancelKeyPress; | ||
|
|
||
| DebuggerLaunchCheck(); |
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's better to break into the client or just wait to break into the server...it's useful to be able to debug anything that might be going wrong, but server was supposed to be mostly invisible, and that'd be visible.
|
|
||
| // Now write in the actual packet length | ||
| memoryStream.Position = 1; | ||
| _binaryWriter.Write(packetStreamLength - 5); |
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 5 come from?
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 code was inspired by NodeEndpointOutOfProcBase.RunReadLoop and has meaning of size of header (byte: packet type, int32: sizeInBytes).
|
|
||
| public class TransientTestProcess : TransientTestState | ||
| { | ||
| private readonly int _processId; |
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: process IDs can be reused, so it'd be better to keep a Process object (which internally keeps an OS handle open so that the PID can't be reused until the Process object is cleaned up).
| public class SleepingTask : Microsoft.Build.Utilities.Task | ||
| { | ||
| public int SleepTime { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Sleep for SleepTime milliseconds. | ||
| /// </summary> | ||
| /// <returns>Success on success.</returns> | ||
| public override bool Execute() | ||
| { | ||
| Thread.Sleep(SleepTime); | ||
| return !Log.HasLoggedErrors; | ||
| } | ||
| } | ||
|
|
||
| public class ProcessIdTask : Microsoft.Build.Utilities.Task | ||
| { | ||
| [Output] | ||
| public int Pid { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Log the id for this process. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public override bool Execute() | ||
| { | ||
| Pid = Process.GetCurrentProcess().Id; | ||
| return true; | ||
| } | ||
| } |
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 think we have both of these in some test assembly somewhere, but they're tiny so reimplementing is probably ok.
| { | ||
| try | ||
| { | ||
| IntPtr stdOut = NativeMethodsShared.GetStdHandle(NativeMethodsShared.STD_OUTPUT_HANDLE); |
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.
TIL this is a handle you're not supposed to dispose: https://docs.microsoft.com/en-us/windows/console/getstdhandle#handle-disposal
Fixes #7315.
Context
Adding an opt-in feature for executing the build in MSBuild server. With this feature turned on, MSBuild sends the build request for execution to the MSBuild server node. This approach avoids to execute targets and tasks into a short-living process from CLI tools like .NET SDK and MSBuild.exe.
Changes Made
This PR implements: