// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
namespace UnrealBuildTool
{
///
/// Validates the various platforms to determine if they are ready for building
///
[ToolMode("ValidatePlatforms", ToolModeOptions.XmlConfig | ToolModeOptions.BuildPlatformsForValidation | ToolModeOptions.SingleInstance)]
class ValidatePlatformsMode : ToolMode
{
///
/// Platforms to validate
///
[CommandLine("-Platforms=", ListSeparator = '+')]
HashSet Platforms = new HashSet();
///
/// Whether to validate all platforms
///
[CommandLine("-AllPlatforms")]
bool bAllPlatforms = false;
///
/// Whether to output SDK versions.
///
[CommandLine("-OutputSDKs")]
bool bOutputSDKs = false;
///
/// Executes the tool with the given arguments
///
/// Command line arguments
/// Exit code
///
public override int Execute(CommandLineArguments Arguments, ILogger Logger)
{
// Output a message if there are any arguments that are still unused
Arguments.ApplyTo(this);
Arguments.CheckAllArgumentsUsed();
// If the -AllPlatforms argument is specified, add all the known platforms into the list
if(bAllPlatforms)
{
Platforms.UnionWith(UnrealTargetPlatform.GetValidPlatforms());
}
// Output a line for each registered platform
foreach (UnrealTargetPlatform Platform in Platforms)
{
UEBuildPlatform.TryGetBuildPlatform(Platform, out UEBuildPlatform? BuildPlatform);
string PlatformSDKString = "";
if (bOutputSDKs)
{
PlatformSDKString = BuildPlatform != null ? UEBuildPlatform.GetSDK(Platform)!.GetMainVersion() : "";
}
if (BuildPlatform != null && BuildPlatform.HasRequiredSDKsInstalled() == SDKStatus.Valid)
{
Logger.LogInformation("##PlatformValidate: {Platform} VALID {PlatformSdkString}", Platform.ToString(), PlatformSDKString);
}
else
{
Logger.LogInformation("##PlatformValidate: {Platform} INVALID {PlatformSdkString}", Platform.ToString(), PlatformSDKString);
}
}
return 0;
}
}
}