// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Collections.Generic; using System.Linq; using UnityEditor; namespace Microsoft.MixedReality.Toolkit.Build.Editor { public static class BuildInfoExtensions { /// /// Append symbols to the end of the 's. /// /// The string array to append. public static void AppendSymbols(this IBuildInfo buildInfo, params string[] symbol) { buildInfo.AppendSymbols((IEnumerable)symbol); } /// /// Append symbols to the end of the 's . /// /// The string collection to append. public static void AppendSymbols(this IBuildInfo buildInfo, IEnumerable symbols) { string[] toAdd = symbols.Except(buildInfo.BuildSymbols.Split(';')) .Where(symbol => !string.IsNullOrEmpty(symbol)).ToArray(); if (!toAdd.Any()) { return; } if (!string.IsNullOrEmpty(buildInfo.BuildSymbols)) { buildInfo.BuildSymbols += ";"; } buildInfo.BuildSymbols += string.Join(";", toAdd); } /// /// Remove symbols from the 's . /// /// The string collection to remove. public static void RemoveSymbols(this IBuildInfo buildInfo, IEnumerable symbolsToRemove) { string[] toKeep = buildInfo.BuildSymbols.Split(';').Except(symbolsToRemove).ToArray(); if (!toKeep.Any()) { return; } if (!string.IsNullOrEmpty(buildInfo.BuildSymbols)) { buildInfo.BuildSymbols = string.Empty; } buildInfo.BuildSymbols += string.Join(";", toKeep); } /// /// Does the contain any of the provided symbols in the ? /// /// The string array of symbols to match. /// True, if any of the provided symbols are in the public static bool HasAnySymbols(this IBuildInfo buildInfo, params string[] symbols) { if (string.IsNullOrEmpty(buildInfo.BuildSymbols)) { return false; } return buildInfo.BuildSymbols.Split(';').Intersect(symbols).Any(); } /// /// Does the contain any of the provided symbols in the ? /// /// The string collection of symbols to match. /// True, if any of the provided symbols are in the public static bool HasAnySymbols(this IBuildInfo buildInfo, IEnumerable symbols) { if (string.IsNullOrEmpty(buildInfo.BuildSymbols)) { return false; } return buildInfo.BuildSymbols.Split(';').Intersect(symbols).Any(); } /// /// Checks if the has any configuration symbols (i.e. debug, release, or master). /// /// True, if the contains debug, release, or master. public static bool HasConfigurationSymbol(this IBuildInfo buildInfo) { return buildInfo.HasAnySymbols( UnityPlayerBuildTools.BuildSymbolDebug, UnityPlayerBuildTools.BuildSymbolRelease, UnityPlayerBuildTools.BuildSymbolMaster); } /// /// Appends the 's without including debug, release or master. /// /// Symbols to append. public static void AppendWithoutConfigurationSymbols(this IBuildInfo buildInfo, string symbols) { buildInfo.AppendSymbols(symbols.Split(';').Except(new[] { UnityPlayerBuildTools.BuildSymbolDebug, UnityPlayerBuildTools.BuildSymbolRelease, UnityPlayerBuildTools.BuildSymbolMaster }).ToArray()); } /// /// Gets the BuildTargetGroup for the 's BuildTarget /// /// The BuildTargetGroup for the 's BuildTarget public static BuildTargetGroup GetGroup(this BuildTarget buildTarget) { switch (buildTarget) { case BuildTarget.WSAPlayer: return BuildTargetGroup.WSA; case BuildTarget.StandaloneWindows: case BuildTarget.StandaloneWindows64: return BuildTargetGroup.Standalone; default: return BuildTargetGroup.Unknown; } } } }