2019-12-26 23:01:54 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2019-10-22 15:08:57 -04:00
|
|
|
|
|
|
|
|
using AutomationTool;
|
2021-11-09 12:36:25 -05:00
|
|
|
using EpicGames.BuildGraph;
|
2019-10-22 15:08:57 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml;
|
2020-12-21 23:07:37 -04:00
|
|
|
using EpicGames.Core;
|
2021-06-11 18:20:44 -04:00
|
|
|
using UnrealBuildBase;
|
2021-12-10 15:36:47 -05:00
|
|
|
using System.Threading.Tasks;
|
2023-03-08 14:32:15 -05:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
using static AutomationTool.CommandUtils;
|
2019-10-22 15:08:57 -04:00
|
|
|
|
2021-12-10 16:56:09 -05:00
|
|
|
namespace AutomationTool.Tasks
|
2019-10-22 15:08:57 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parameters for a <see cref="WriteTextFileTask"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class WriteTextFileTaskParameters
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Path to the file to write.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter]
|
|
|
|
|
public FileReference File;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Optional, whether or not to append to the file rather than overwrite.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter(Optional = true)]
|
|
|
|
|
public bool Append;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The text to write to the file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter(Optional = true)]
|
|
|
|
|
public string Text;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If specified, causes the given list of files to be printed after the given message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.FileSpec)]
|
|
|
|
|
public string Files;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tag to be applied to build products of this task.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskParameter(Optional = true, ValidationType = TaskParameterValidationType.TagList)]
|
|
|
|
|
public string Tag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Writes text to a file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[TaskElement("WriteTextFile", typeof(WriteTextFileTaskParameters))]
|
2021-12-10 15:36:47 -05:00
|
|
|
public class WriteTextFileTask : BgTaskImpl
|
2019-10-22 15:08:57 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parameters for this task.
|
|
|
|
|
/// </summary>
|
|
|
|
|
WriteTextFileTaskParameters Parameters;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="InParameters">Parameters for this task.</param>
|
|
|
|
|
public WriteTextFileTask(WriteTextFileTaskParameters InParameters)
|
|
|
|
|
{
|
|
|
|
|
Parameters = InParameters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Execute the task.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Job">Information about the current job.</param>
|
|
|
|
|
/// <param name="BuildProducts">Set of build products produced by this node.</param>
|
|
|
|
|
/// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include.</param>
|
2021-12-10 15:36:47 -05:00
|
|
|
public override async Task ExecuteAsync(JobContext Job, HashSet<FileReference> BuildProducts, Dictionary<string, HashSet<FileReference>> TagNameToFileSet)
|
2019-10-22 15:08:57 -04:00
|
|
|
{
|
|
|
|
|
string FileText = Parameters.Text;
|
|
|
|
|
|
|
|
|
|
// If any files or tagsets are provided, add them to the text output.
|
|
|
|
|
if (!String.IsNullOrEmpty(Parameters.Files))
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(FileText))
|
|
|
|
|
{
|
|
|
|
|
FileText += Environment.NewLine;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-11 18:20:44 -04:00
|
|
|
HashSet<FileReference> Files = ResolveFilespec(Unreal.RootDirectory, Parameters.Files, TagNameToFileSet);
|
2019-10-22 15:08:57 -04:00
|
|
|
if (Files.Any())
|
|
|
|
|
{
|
|
|
|
|
FileText += string.Join(Environment.NewLine, Files.Select(f => f.FullName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure output folder exists.
|
|
|
|
|
if (!DirectoryReference.Exists(Parameters.File.Directory))
|
|
|
|
|
{
|
|
|
|
|
DirectoryReference.CreateDirectory(Parameters.File.Directory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Parameters.Append)
|
|
|
|
|
{
|
2023-03-08 14:32:15 -05:00
|
|
|
Logger.LogInformation("{Text}", string.Format("Appending text to file '{0}': {1}", Parameters.File, FileText));
|
2021-12-10 15:36:47 -05:00
|
|
|
await FileReference.AppendAllTextAsync(Parameters.File, Environment.NewLine + FileText);
|
2019-10-22 15:08:57 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-03-08 14:32:15 -05:00
|
|
|
Logger.LogInformation("{Text}", string.Format("Writing text to file '{0}': {1}", Parameters.File, FileText));
|
2021-12-10 15:36:47 -05:00
|
|
|
await FileReference.WriteAllTextAsync(Parameters.File, FileText);
|
2019-10-22 15:08:57 -04:00
|
|
|
}
|
2023-04-14 21:37:27 -04:00
|
|
|
|
|
|
|
|
// Apply the optional tag to the build products
|
|
|
|
|
foreach (string TagName in FindTagNamesFromList(Parameters.Tag))
|
|
|
|
|
{
|
|
|
|
|
FindOrAddTagSet(TagNameToFileSet, TagName).Add(Parameters.File);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add them to the set of build products
|
|
|
|
|
BuildProducts.Add(Parameters.File);
|
2019-10-22 15:08:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Output this task out to an XML writer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override void Write(XmlWriter Writer)
|
|
|
|
|
{
|
|
|
|
|
Write(Writer, Parameters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find all the tags which are used as inputs to this task
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The tag names which are read by this task</returns>
|
|
|
|
|
public override IEnumerable<string> FindConsumedTagNames()
|
|
|
|
|
{
|
|
|
|
|
foreach(string TagName in FindTagNamesFromFilespec(Parameters.Files))
|
|
|
|
|
{
|
|
|
|
|
yield return TagName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Find all the tags which are modified by this task
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The tag names which are modified by this task</returns>
|
|
|
|
|
public override IEnumerable<string> FindProducedTagNames()
|
|
|
|
|
{
|
|
|
|
|
return FindTagNamesFromList(Parameters.Tag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|