// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq; namespace UnrealBuildTool { /// /// Attribute which can be applied to a TargetRules-dervied class to indicate which platforms it supports /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class SupportedPlatformGroupsAttribute : SupportedPlatformsAttribute { /// /// Initialize the attribute with a list of platform groups /// /// Variable-length array of platform group arguments [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments", Justification = "Unneeded")] public SupportedPlatformGroupsAttribute(params string[] platformGroups) : base(GetPlatformsForGroups(platformGroups)) { } private static string[] GetPlatformsForGroups(params string[] platformGroups) { HashSet supportedPlatforms = new(); try { foreach (string name in platformGroups) { if (UnrealPlatformGroup.TryParse(name, out UnrealPlatformGroup group)) { supportedPlatforms.UnionWith(UnrealTargetPlatform.GetValidPlatforms().Where(x => x.IsInGroup(group))); continue; } throw new BuildException(String.Format("The platform group name {0} is not a valid platform group name. Valid names are ({1})", name, String.Join(",", UnrealPlatformGroup.GetValidGroupNames()))); } } catch (BuildException ex) { EpicGames.Core.ExceptionUtils.AddContext(ex, $"while parsing a SupportedPlatformGroups attribute '{String.Join(',', platformGroups)}'"); throw; } return supportedPlatforms.Select(x => x.ToString()).ToArray(); } } }