// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Reflection; using System.Threading.Tasks; using EpicGames.Core; using Microsoft.Extensions.Logging; using UnrealBuildTool.Artifacts; namespace UnrealBuildTool { abstract class ActionExecutor : IDisposable { public abstract string Name { get; } protected static double MemoryPerActionBytesOverride { get; private set; } = 0.0; readonly LogEventParser Parser; public ActionExecutor(ILogger Logger) { Parser = new LogEventParser(Logger); Parser.AddMatchersFromAssembly(Assembly.GetExecutingAssembly()); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (disposing) { Parser.Dispose(); } } /// /// Allow targets to override the expected amount of memory required for compiles, used to control the number /// of parallel action processes. /// /// public static void SetMemoryPerActionOverride(double MemoryPerActionOverrideGB) { MemoryPerActionBytesOverride = Math.Max(MemoryPerActionBytesOverride, MemoryPerActionOverrideGB * 1024 * 1024 * 1024); } /// /// Execute the given actions /// /// Actions to be executed /// Logger for output /// Cache used to read/write action outputs. /// True if the build succeeded, false otherwise public abstract Task ExecuteActionsAsync(IEnumerable ActionsToExecute, ILogger Logger, IActionArtifactCache? actionArtifactCache = null); /// /// When completed, get a populated telemetry event for this executor /// /// public abstract TelemetryExecutorEvent? GetTelemetryEvent(); /// /// Post a telemetry event if enabled /// public void PostTelemetryEvent() { TelemetryExecutorEvent? telemetryEvent = GetTelemetryEvent(); if (telemetryEvent != null) { TelemetryService.Get().RecordEvent(telemetryEvent); } } /// /// Will verify that produced items exists on disk /// public virtual bool VerifyOutputs => true; protected void WriteToolOutput(string Line) { lock (Parser) { Parser.WriteLine(Line); } } protected void FlushToolOutput() { lock (Parser) { Parser.Flush(); } } } }