Skip to content

Commit

Permalink
make a forwarding node logger for TL and wire it up
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Mar 1, 2024
1 parent 377264d commit 8933ba5
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 4 deletions.
78 changes: 78 additions & 0 deletions src/MSBuild/TerminalLogger/TerminalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,3 +1004,81 @@ private int NodeIndexForContext(BuildEventContext context)

#endregion
}

internal sealed class TerminalLoggerNodeForwardingLogger : IForwardingLogger
{
public IEventRedirector? BuildEventRedirector { get; set; }
public int NodeId { get; set; }
public LoggerVerbosity Verbosity { get => LoggerVerbosity.Diagnostic; set { return; } }
public string? Parameters { get; set; }

public void Initialize(IEventSource eventSource, int nodeCount) => Initialize(eventSource);
public void Initialize(IEventSource eventSource)
{
eventSource.BuildStarted += ForwardEventUnconditionally;
eventSource.BuildFinished += ForwardEventUnconditionally;
eventSource.ProjectStarted += ForwardEventUnconditionally;
eventSource.ProjectFinished += ForwardEventUnconditionally;
eventSource.TargetStarted += ForwardEventUnconditionally;
eventSource.TargetFinished += ForwardEventUnconditionally;
eventSource.TaskStarted += TaskStarted;

eventSource.MessageRaised += MessageRaised;
eventSource.WarningRaised += ForwardEventUnconditionally;
eventSource.ErrorRaised += ForwardEventUnconditionally;

if (eventSource is IEventSource3 eventSource3)
{
eventSource3.IncludeTaskInputs();
}

if (eventSource is IEventSource4 eventSource4)
{
eventSource4.IncludeEvaluationPropertiesAndItems();
}
}

public void ForwardEventUnconditionally(object sender, BuildEventArgs e)
{
BuildEventRedirector?.ForwardEvent(e);
}

public void TaskStarted(object sender, TaskStartedEventArgs e)
{
// MSBuild tasks yield the build node, so forward this to the central node so it can update status
if (e.TaskName.Equals("MSBuild", StringComparison.OrdinalIgnoreCase))
{
BuildEventRedirector?.ForwardEvent(e);
}
}

public void MessageRaised(object sender, BuildMessageEventArgs e)
{
if (e.BuildEventContext is null)
{
return;
}

// SourceRoot additions are used in output reporting, so forward those along
if (e is TaskParameterEventArgs taskArgs)
{
if (taskArgs.Kind == TaskParameterMessageKind.AddItem)
{
if (taskArgs.ItemType.Equals("SourceRoot", StringComparison.OrdinalIgnoreCase))
{
BuildEventRedirector?.ForwardEvent(taskArgs);
}
}
}

// High-priority messages are rendered for each project, so forward those along
if (e.Message is not null && e.Importance == MessageImportance.High)
{
BuildEventRedirector?.ForwardEvent(e);
}
}

public void Shutdown()
{
}
}
9 changes: 5 additions & 4 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
using LoggerDescription = Microsoft.Build.Logging.LoggerDescription;
using SimpleErrorLogger = Microsoft.Build.Logging.SimpleErrorLogger.SimpleErrorLogger;
using TerminalLogger = Microsoft.Build.Logging.TerminalLogger.TerminalLogger;
using TerminalLoggerForwardingLogger = Microsoft.Build.Logging.TerminalLogger.TerminalLoggerNodeForwardingLogger;

#nullable disable

Expand Down Expand Up @@ -2951,13 +2952,13 @@ private static string GetProjectDirectory(string[] projectSwitchParameters)


/// <summary>
/// Identifies if there is rsp files near the project file
/// Identifies if there is rsp files near the project file
/// </summary>
/// <returns>true if there autoresponse file was found</returns>
private static bool CheckAndGatherProjectAutoResponseFile(CommandLineSwitches switchesFromAutoResponseFile, CommandLineSwitches commandLineSwitches, bool recursing, string commandLine)
{
bool found = false;

var projectDirectory = GetProjectDirectory(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Project]);

if (!recursing && !commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.NoAutoResponse])
Expand Down Expand Up @@ -3936,8 +3937,8 @@ private static void ProcessTerminalLogger(bool noConsoleLogger,
}
else
{
// For performance, register this logger using the forwarding logger mechanism.
DistributedLoggerRecord forwardingLoggerRecord = CreateForwardingLoggerRecord(logger, string.Join(";", TerminalLogger.ConfigurableForwardingLoggerParameters), LoggerVerbosity.Quiet);
LoggerDescription terminalLoggerDescription = new LoggerDescription(typeof(TerminalLoggerForwardingLogger).FullName, typeof(TerminalLoggerForwardingLogger).Assembly.FullName, null, null, LoggerVerbosity.Diagnostic);
DistributedLoggerRecord forwardingLoggerRecord = new DistributedLoggerRecord(logger, terminalLoggerDescription);
distributedLoggerRecords.Add(forwardingLoggerRecord);
}
}
Expand Down

0 comments on commit 8933ba5

Please sign in to comment.