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

Fix TL failure on MSBUILDNOINPROCNODE env variable #9388

Merged
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
20 changes: 17 additions & 3 deletions src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ public class TerminalLoggerConfiguration_Tests : IDisposable
private readonly TestEnvironment _env;

private readonly string _cmd;
private readonly ITestOutputHelper _output;

public TerminalLoggerConfiguration_Tests(ITestOutputHelper output)
{
_env = TestEnvironment.Create(output);
_output = output;

// Ignore environment variables that may have been set by the environment where the tests are running.
_env.SetEnvironmentVariable("MSBUILDLIVELOGGER", null);
Expand Down Expand Up @@ -113,7 +111,6 @@ public void TerminalLoggerWithTlAutoIsOff(string tlValue)
ShouldNotBeTerminalLog(output);
}


[Fact]
public void TerminalLoggerDefaultByEnv()
{
Expand Down Expand Up @@ -232,6 +229,23 @@ public void TerminalLoggerDefaultOff(string defaultValue)
ShouldNotBeTerminalLog(output);
}

[Theory]
[InlineData("1")]
[InlineData("0")]
public void TerminalLoggerOnInvalidProjectBuild(string msbuildinprocnodeState)
{
_ = _env.SetEnvironmentVariable("MSBUILDNOINPROCNODE", msbuildinprocnodeState);

string output = RunnerUtilities.ExecMSBuild(
$"{_cmd} -tl:true",
out bool success);

success.ShouldBeTrue();
ShouldBeTerminalLog(output);
output.ShouldContain("Build succeeded.");
}

private static void ShouldBeTerminalLog(string output) => output.ShouldContain("\x1b[?25l");

private static void ShouldNotBeTerminalLog(string output) => output.ShouldNotContain("\x1b[?25l");
}
32 changes: 18 additions & 14 deletions src/MSBuild/TerminalLogger/TerminalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,16 @@ internal TerminalLogger(ITerminal terminal)
public LoggerVerbosity Verbosity { get => LoggerVerbosity.Minimal; set { } }

/// <inheritdoc/>
public string Parameters { get => ""; set { } }
public string Parameters
{
get => ""; set { }
}

/// <inheritdoc/>
public void Initialize(IEventSource eventSource, int nodeCount)
{
_nodes = new NodeStatus[nodeCount];
// When MSBUILDNOINPROCNODE enabled, NodeId's reported by build start with 2. We need to reserve an extra spot for this case.
_nodes = new NodeStatus[nodeCount + 1];

Initialize(eventSource);
}
Expand Down Expand Up @@ -339,10 +343,7 @@ private void ProjectFinished(object sender, ProjectFinishedEventArgs e)
// Mark node idle until something uses it again
if (_restoreContext is null)
{
lock (_lock)
{
_nodes[NodeIndexForContext(buildEventContext)] = null;
}
UpdateNodeStatus(buildEventContext, null);
}

ProjectContext c = new(buildEventContext);
Expand Down Expand Up @@ -494,10 +495,16 @@ private void TargetStarted(object sender, TargetStartedEventArgs e)

string projectFile = Path.GetFileNameWithoutExtension(e.ProjectFile);
NodeStatus nodeStatus = new(projectFile, project.TargetFramework, e.TargetName, project.Stopwatch);
lock (_lock)
{
_nodes[NodeIndexForContext(buildEventContext)] = nodeStatus;
}
UpdateNodeStatus(buildEventContext, nodeStatus);
}
}

private void UpdateNodeStatus(BuildEventContext buildEventContext, NodeStatus? nodeStatus)
{
lock (_lock)
{
int nodeIndex = NodeIndexForContext(buildEventContext);
_nodes[nodeIndex] = nodeStatus;
}
}

Expand All @@ -517,10 +524,7 @@ private void TaskStarted(object sender, TaskStartedEventArgs e)
if (_restoreContext is null && buildEventContext is not null && e.TaskName == "MSBuild")
{
// This will yield the node, so preemptively mark it idle
lock (_lock)
{
_nodes[NodeIndexForContext(buildEventContext)] = null;
}
UpdateNodeStatus(buildEventContext, null);

if (_projects.TryGetValue(new ProjectContext(buildEventContext), out Project? project))
{
Expand Down