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 1 commit
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
25 changes: 24 additions & 1 deletion src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public void TerminalLoggerWithTlAutoIsOff(string tlValue)
ShouldNotBeTerminalLog(output);
}


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

[WindowsFullFrameworkOnlyTheory]
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved
[InlineData("1")]
[InlineData("0")]
public void TerminalLoggerOnInvalidProjectBuild(string msbuildinprocnodeState)
{
var projectFile = _env.CreateFile(_env.CreateFolder(createFolder: true), "myProjBroken.proj", $"""
<Project>
<Target Name='Build'>
<RegisterAssembly Assemblies="nonexistent.dll" />
</Target>
</Project>
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved
""");
string cmd = $"{projectFile.Path} -logger:{typeof(MockLogger).FullName},{typeof(MockLogger).Assembly.Location};ReportTelemetry";
_env.SetEnvironmentVariable("MSBUILDNOINPROCNODE", msbuildinprocnodeState);

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

success.ShouldBeFalse();
ShouldBeTerminalLog(output);
output.ShouldContain("Cannot register assembly \"nonexistent.dll\" - file doesn't exist.");
}

private static void ShouldBeTerminalLog(string output) => output.ShouldContain("\x1b[?25l");
private static void ShouldNotBeTerminalLog(string output) => output.ShouldNotContain("\x1b[?25l");
}
23 changes: 13 additions & 10 deletions src/MSBuild/TerminalLogger/TerminalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,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,9 +491,18 @@ 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)
UpdateNodeStatus(buildEventContext, nodeStatus);
}
}

private void UpdateNodeStatus(BuildEventContext buildEventContext, NodeStatus? nodeStatus)
{
lock (_lock)
{
int nodeIndex = NodeIndexForContext(buildEventContext);
if (_nodes != null && _nodes.Length - 1 >= nodeIndex)
{
_nodes[NodeIndexForContext(buildEventContext)] = nodeStatus;
_nodes[nodeIndex] = nodeStatus;
}
}
}
Expand All @@ -517,10 +523,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