Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions src/Build.UnitTests/BackEnd/RedirectConsoleWriter_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Experimental;
using Shouldly;
using Xunit;

namespace Microsoft.Build.Engine.UnitTests.BackEnd
Expand All @@ -15,14 +17,15 @@ public class RedirectConsoleWriter_Tests
public async Task EmitConsoleMessages()
{
StringBuilder sb = new StringBuilder();
var writer = OutOfProcServerNode.RedirectConsoleWriter.Create(text => sb.Append(text));

writer.WriteLine("Line 1");
await Task.Delay(300);
writer.Write("Line 2");
writer.Dispose();
using (TextWriter writer = OutOfProcServerNode.RedirectConsoleWriter.Create(text => sb.Append(text)))
{
writer.WriteLine("Line 1");
await Task.Delay(300);
writer.Write("Line 2");
}

Assert.Equal($"Line 1{Environment.NewLine}Line 2", sb.ToString());
sb.ToString().ShouldBe($"Line 1{Environment.NewLine}Line 2");
}
}
}
21 changes: 11 additions & 10 deletions src/Build/BackEnd/Client/MSBuildClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public MSBuildClientExitResult Execute(CancellationToken cancellationToken)
CommunicationsUtilities.Trace("Server was not running. Starting server now.");
if (!TryLaunchServer())
{
_exitResult.MSBuildClientExitType = MSBuildClientExitType.LaunchError;
return _exitResult;
}
}
Expand Down Expand Up @@ -391,11 +392,11 @@ private bool TryLaunchServer()
NodeLauncher nodeLauncher = new NodeLauncher();
CommunicationsUtilities.Trace("Starting Server...");
Process msbuildProcess = nodeLauncher.Start(_msbuildLocation, string.Join(" ", msBuildServerOptions));
CommunicationsUtilities.Trace("Server started with PID: {0}", msbuildProcess?.Id);
CommunicationsUtilities.Trace($"Server started with PID: {msbuildProcess?.Id}");
}
catch (Exception ex)
{
CommunicationsUtilities.Trace("Failed to launch the msbuild server: {0}", ex);
CommunicationsUtilities.Trace($"Failed to launch the msbuild server: {ex}");
_exitResult.MSBuildClientExitType = MSBuildClientExitType.LaunchError;
return false;
}
Expand All @@ -422,7 +423,7 @@ private ServerNodeBuildCommand GetServerNodeBuildCommand()
}

// We remove env variable used to invoke MSBuild server as that might be equal to 1, so we do not get an infinite recursion here.
envVars[Traits.UseMSBuildServerEnvVarName] = "0";
envVars.Remove(Traits.UseMSBuildServerEnvVarName);

return new ServerNodeBuildCommand(
_commandLine,
Expand Down Expand Up @@ -453,8 +454,8 @@ private void HandleCancellation()
/// </summary>
private void HandlePacketPumpError(MSBuildClientPacketPump packetPump)
{
CommunicationsUtilities.Trace("MSBuild client error: packet pump unexpectedly shut down: {0}", packetPump.PacketPumpException);
throw packetPump.PacketPumpException ?? new Exception("Packet pump unexpectedly shut down");
CommunicationsUtilities.Trace($"MSBuild client error: packet pump unexpectedly shut down: {packetPump.PacketPumpException}");
throw packetPump.PacketPumpException ?? new InternalErrorException("Packet pump unexpectedly shut down");
}

/// <summary>
Expand Down Expand Up @@ -495,7 +496,7 @@ private void HandleServerNodeConsoleWrite(ServerNodeConsoleWrite consoleWrite)

private void HandleServerNodeBuildResult(ServerNodeBuildResult response)
{
CommunicationsUtilities.Trace("Build response received: exit code {0}, exit type '{1}'", response.ExitCode, response.ExitType);
CommunicationsUtilities.Trace($"Build response received: exit code {response.ExitCode}, exit type '{response.ExitType}'");
_exitResult.MSBuildClientExitType = MSBuildClientExitType.Success;
_exitResult.MSBuildAppExitTypeString = response.ExitType;
_buildFinished = true;
Expand All @@ -514,26 +515,26 @@ private bool TryConnectToServer(int timeout)
int[] handshakeComponents = _handshake.RetrieveHandshakeComponents();
for (int i = 0; i < handshakeComponents.Length; i++)
{
CommunicationsUtilities.Trace("Writing handshake part {0} ({1}) to pipe {2}", i, handshakeComponents[i], _pipeName);
CommunicationsUtilities.Trace($"Writing handshake part {i} ({handshakeComponents[i]}) to pipe {_pipeName}");
_nodeStream.WriteIntForHandshake(handshakeComponents[i]);
}

// This indicates that we have finished all the parts of our handshake; hopefully the endpoint has as well.
_nodeStream.WriteEndOfHandshakeSignal();

CommunicationsUtilities.Trace("Reading handshake from pipe {0}", _pipeName);
CommunicationsUtilities.Trace($"Reading handshake from pipe {_pipeName}");

#if NETCOREAPP2_1_OR_GREATER || MONO
_nodeStream.ReadEndOfHandshakeSignal(false, 1000);
#else
_nodeStream.ReadEndOfHandshakeSignal(false);
#endif

CommunicationsUtilities.Trace("Successfully connected to pipe {0}...!", _pipeName);
CommunicationsUtilities.Trace($"Successfully connected to pipe {_pipeName}...!");
}
catch (Exception ex)
{
CommunicationsUtilities.Trace("Failed to connect to server: {0}", ex);
CommunicationsUtilities.Trace($"Failed to connect to server: {ex}");
_exitResult.MSBuildClientExitType = MSBuildClientExitType.ConnectionError;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/Client/MSBuildClientPacketPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private void RunReadLoop(Stream localStream, ManualResetEvent localPacketPumpShu
#if FEATURE_APM
result = localStream.BeginRead(headerByte, 0, headerByte.Length, null, null);
#else
readTask = CommunicationsUtilities.ReadAsync(localStream, headerByte, headerByte.Length);
readTask = CommunicationsUtilities.ReadAsync(localStream, headerByte, headerByte.Length);
#endif
}
}
Expand Down
14 changes: 0 additions & 14 deletions src/Build/BackEnd/Node/OutOfProcServerNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.IO;
using System.Threading;
Expand Down Expand Up @@ -67,18 +66,11 @@ public delegate (int exitCode, string exitType) BuildCallback(
/// </summary>
private Exception? _shutdownException = null;

/// <summary>
/// Flag indicating if we should debug communications or not.
/// </summary>
private readonly bool _debugCommunications;

private string _serverBusyMutexName = default!;

public OutOfProcServerNode(BuildCallback buildFunction)
{
_buildFunction = buildFunction;
new Dictionary<string, string>();
_debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1");

_receivedPackets = new ConcurrentQueue<INodePacket>();
_packetReceivedEvent = new AutoResetEvent(false);
Expand Down Expand Up @@ -253,12 +245,6 @@ private void OnLinkStatusChanged(INodeEndpoint endpoint, LinkStatus status)
_shutdownEvent.Set();
break;

case LinkStatus.Inactive:
break;

case LinkStatus.Active:
break;

default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2692,8 +2692,8 @@ private static void StartLocalNode(CommandLineSwitches commandLineSwitches, bool
else
{
exitType = Execute(commandLine);
exitCode = exitType == ExitType.Success ? 0 : 1;
}

exitCode = exitType == ExitType.Success ? 0 : 1;

return (exitCode, exitType.ToString());
Expand Down
11 changes: 0 additions & 11 deletions src/Shared/CommunicationsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,6 @@ internal ServerNodeHandshake(HandshakeOptions nodeType)
{
}

/// <summary>
/// Compute stable hash as integer
/// </summary>
private static int ComputeHandshakeHash(string fromString)
{
using var sha = SHA256.Create();
var bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(fromString));

return BitConverter.ToInt32(bytes, 0);
}

public override int[] RetrieveHandshakeComponents()
{
return new int[]
Expand Down
1 change: 0 additions & 1 deletion src/Shared/NodeEndpointOutOfProcBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Microsoft.Build.Shared;
#if FEATURE_SECURITY_PERMISSIONS || FEATURE_PIPE_SECURITY
using System.Security.AccessControl;
using System.Linq;
#endif
#if FEATURE_PIPE_SECURITY && FEATURE_NAMED_PIPE_SECURITY_CONSTRUCTOR
using System.Security.Principal;
Expand Down