// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Linq;
using EpicGames.BuildGraph.Expressions;
namespace EpicGames.BuildGraph
{
///
/// Configuration for a label
///
public class BgLabelConfig
{
///
/// Name of this badge
///
public BgString? DashboardName { get; set; }
///
/// Category for this label
///
public BgString? DashboardCategory { get; set; }
///
/// Name of the badge in UGS
///
public BgString? UgsBadge { get; set; }
///
/// Path to the project folder in UGS
///
public BgString? UgsProject { get; set; }
///
/// Which change to show the badge for
///
public BgString? Change { get; set; }
///
/// Set of nodes that must be run for this label to be shown.
///
public BgList RequiredNodes { get; set; } = BgList.Empty;
///
/// Set of nodes that will be included in this label if present.
///
public BgList IncludedNodes { get; set; } = BgList.Empty;
}
///
/// Specification for a label
///
public class BgLabelSpec
{
private readonly BgLabelConfig _config;
internal BgLabelSpec(BgLabelConfig config)
{
_config = config;
}
internal void AddToGraph(BgExprContext context, BgGraph graph)
{
string? dashboardName = _config.DashboardName?.Compute(context);
string? dashboardCategory = _config.DashboardCategory?.Compute(context);
string? ugsBadge = _config.UgsBadge?.Compute(context);
string? ugsProject = _config.UgsBadge?.Compute(context);
BgLabelChange labelChange;
if (_config.Change is null)
{
labelChange = BgLabelChange.Current;
}
else
{
labelChange = Enum.Parse(_config.Change.Compute(context));
}
BgLabel label = new BgLabel(dashboardName, dashboardCategory, ugsBadge, ugsProject, labelChange);
label.RequiredNodes.UnionWith(_config.RequiredNodes.ComputeTags(context).Select(x => graph.TagNameToNodeOutput[x].ProducingNode));
label.IncludedNodes.UnionWith(_config.IncludedNodes.ComputeTags(context).Select(x => graph.TagNameToNodeOutput[x].ProducingNode));
graph.Labels.Add(label);
}
}
}