You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
[FYI] Leon.Huang Original CL Desc ----------------------------------------------------------------- Unreal Build Tool: Update PluginDescriptor to have parity with FPluginDescriptor in terms of handling custom JSON fields. The order in which the original fields are written to disk is preserved. When saving the PluginDescriptor to disk, the same order is followed and any new entries are added to the end of the plugin file. Note: PluginDescriptor.Save and PluginDescriptor.Save2 will exist concurrently for now. There are still parts of UBT that use PluginDescriptor.Write and the refactor to create a unified Save function will come later as a lot of testing still needs to be done. JsonObject: - Introduced AddOrSetFieldValue() methods overloaded on value types to add/set fields in JsonObject. - Changed the underlying data structure of JsonObject from Dictionary<string,Object?> to OrderedDictionary to guarantee that order of all .uplugin fields (default and custom) are preserved - Made the JsonObject constructor that takes an OrderedDictionary private to ensure type safety of values passed to JsonObject - Introduced ToJsonString() for JsonObject that serializes the JsonObject to match the formatting of .uplugin IMPORTANT: The ToJsonString() method uses the JavaScriptEncoder.UnsafeRelaxedJsonEscaping encoder for Utf8JsonWriter. This allows +,<,>,&,` etc characters to be written properly for .uplugins. As per MS docs, with this encoding, none of the contents should be written to HTML or a script. - Introduced JsonObjectTests that unit tested JsonObject to ensure previous behavior was maintained. PluginDescriptor - Added a JsonObject field that acts as the cache of all fields that were read from a file or parsed from a json string. - Cached JsonObject records the order of all fields that were read and captures custom fields in the .uplugin - Introduced Save2(), the new save algorithm that writes all fields (default and custom) to disk. - Deleted the private default constructor because it didn't seem to be used anywhere. - Introduced PluginDescriptorTests to ensure previous behavior is maintained. In particular when dealing with a .uplugin with only default fields, results of Save() and Save2() are the same. Descriptor Files: - Introduced ToJsonObject() methods to replace the previous JsonWriter patterns of writing the descriptor data. - Introduced the UpdateJsonObject pattern which mimics the old WriteArray pattern of writing data to a JsonWriter. #rb: Mark.Winter, Joe.Kirchoff #jira: none #test: Developed this in a TDD style with unit tests for all the major functions. Also reviewed output of created .uplugins and diffed them. [CL 26111662 by leon huang in ue5-main branch]
97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using EpicGames.Core;
|
|
|
|
namespace UnrealBuildTool
|
|
{
|
|
/// <summary>
|
|
/// Stores custom build steps to be executed by a project or plugin
|
|
/// </summary>
|
|
public class CustomBuildSteps
|
|
{
|
|
Dictionary<UnrealTargetPlatform, string[]> HostPlatformToCommands = new Dictionary<UnrealTargetPlatform, string[]>();
|
|
|
|
/// <summary>
|
|
/// Construct a custom build steps object from a Json object.
|
|
/// </summary>
|
|
public CustomBuildSteps(JsonObject RawObject)
|
|
{
|
|
foreach (string HostPlatformName in RawObject.KeyNames)
|
|
{
|
|
UnrealTargetPlatform Platform;
|
|
if (UnrealTargetPlatform.TryParse(HostPlatformName, out Platform))
|
|
{
|
|
HostPlatformToCommands.Add(Platform, RawObject.GetStringArrayField(HostPlatformName));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reads a list of build steps from a Json project or plugin descriptor
|
|
/// </summary>
|
|
/// <param name="RawObject">The json descriptor object</param>
|
|
/// <param name="FieldName">Name of the field to read</param>
|
|
/// <param name="OutBuildSteps">Output variable to store the sorted dictionary that was read</param>
|
|
/// <returns>True if the field was read (and OutBuildSteps is set), false otherwise.</returns>
|
|
public static bool TryRead(JsonObject RawObject, string FieldName, [NotNullWhen(true)] out CustomBuildSteps? OutBuildSteps)
|
|
{
|
|
JsonObject? BuildStepsObject;
|
|
if (RawObject.TryGetObjectField(FieldName, out BuildStepsObject))
|
|
{
|
|
OutBuildSteps = new CustomBuildSteps(BuildStepsObject);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
OutBuildSteps = null;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reads a list of build steps from a Json project or plugin descriptor
|
|
/// </summary>
|
|
/// <param name="Writer">Writer to receive json output</param>
|
|
/// <param name="FieldName">Name of the field to read</param>
|
|
/// <returns>True if the field was read (and OutBuildSteps is set), false otherwise.</returns>
|
|
public void Write(JsonWriter Writer, string FieldName)
|
|
{
|
|
Writer.WriteObjectStart(FieldName);
|
|
foreach (KeyValuePair<UnrealTargetPlatform, string[]> Pair in HostPlatformToCommands.OrderBy(x => x.Key.ToString()))
|
|
{
|
|
Writer.WriteArrayStart(Pair.Key.ToString());
|
|
foreach (string Line in Pair.Value)
|
|
{
|
|
Writer.WriteValue(Line);
|
|
}
|
|
Writer.WriteArrayEnd();
|
|
}
|
|
Writer.WriteObjectEnd();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to get the commands for a given host platform
|
|
/// </summary>
|
|
/// <param name="HostPlatform">The host platform to look for</param>
|
|
/// <param name="OutCommands">Array of commands</param>
|
|
/// <returns>True if a list of commands was generated</returns>
|
|
public bool TryGetCommands(UnrealTargetPlatform HostPlatform, [NotNullWhen(true)] out string[]? OutCommands)
|
|
{
|
|
string[]? Commands;
|
|
if (HostPlatformToCommands.TryGetValue(HostPlatform, out Commands) && Commands.Length > 0)
|
|
{
|
|
OutCommands = Commands;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
OutCommands = null;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|