// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Xml; using EpicGames.Core; namespace AutomationTool.Tasks { /// /// Parameters for a task that launches ZenServer /// public class ZenLaunchTaskParameters { /// /// The project for which to launch ZenServer /// [TaskParameter] public FileReference Project { get; set; } } /// /// Launches ZenServer /// [TaskElement("ZenLaunch", typeof(ZenLaunchTaskParameters))] public class ZenLaunchTask : BgTaskImpl { /// /// Ensures that ZenServer is running on this current machine. This is needed before running any oplog commands /// This passes the sponsor'd process Id to launch zen. /// This ensures that zen does not live longer than the lifetime of a particular a process that needs Zen to be running /// /// public static void ZenLaunch(FileReference projectFile) { // Get the ZenLaunch executable path FileReference zenLaunchExe = ResolveFile(String.Format("Engine/Binaries/{0}/ZenLaunch{1}", HostPlatform.Current.HostEditorPlatform.ToString(), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")); StringBuilder zenLaunchCommandline = new StringBuilder(); zenLaunchCommandline.AppendFormat("{0} -SponsorProcessID={1}", CommandUtils.MakePathSafeToUseWithCommandLine(projectFile.FullName), Environment.ProcessId); CommandUtils.RunAndLog(CommandUtils.CmdEnv, zenLaunchExe.FullName, zenLaunchCommandline.ToString(), Options: CommandUtils.ERunOptions.Default); } /// /// Parameters for the task /// readonly ZenLaunchTaskParameters _parameters; /// /// Constructor. /// /// Parameters for this task public ZenLaunchTask(ZenLaunchTaskParameters parameters) { _parameters = parameters; } /// /// ExecuteAsync the task. /// /// Information about the current job /// Set of build products produced by this node. /// Mapping from tag names to the set of files they include public override Task ExecuteAsync(JobContext job, HashSet buildProducts, Dictionary> tagNameToFileSet) { ZenLaunch(_parameters.Project); return Task.CompletedTask; } /// /// Output this task out to an XML writer. /// public override void Write(XmlWriter writer) { Write(writer, _parameters); } /// /// Find all the tags which are used as inputs to this task /// /// The tag names which are read by this task public override IEnumerable FindConsumedTagNames() { yield break; } /// /// Find all the tags which are modified by this task /// /// The tag names which are modified by this task public override IEnumerable FindProducedTagNames() { yield break; } } }