Skip to content

Commit

Permalink
Add CookFlavor property for projects. (#7)
Browse files Browse the repository at this point in the history
* Add CookFlavor property for projects.

* Add support for multiple cook flavors. Also change BuildConfigBuildTarget's platform to an object so it can contain additional information (such as cook flavors).

* Add CookFlavor property for projects.

* Add support for multiple cook flavors. Also change BuildConfigBuildTarget's platform to an object so it can contain additional information (such as cook flavors).

* Fix exception when target platform is not Android.

* Refactor cook and pak + stage steps to loop over each cook flavor.

* Do not tag staged output files with cook flavor if platform does not use cook flavors.

* Copy Android binaries to Android_<CookFlavor> directory to avoid file conflict when all binaries are requested for testing.

* Fix file path separators for Mac.

* Fix code style inconsistencies.
  • Loading branch information
JasperDeLaat94 authored Nov 6, 2024
1 parent bd1f240 commit 260f20c
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public async void CanGenerateBuildGraphForProject()
{ $"GameConfigurations", $"DebugGame" },
{ $"ClientConfigurations", $"" },
{ $"ServerConfigurations", $"" },
{ $"AndroidGameCookFlavors", $"" },
{ $"AndroidClientCookFlavors", $"" },
{ $"MacPlatforms", $"IOS;Mac" },
{ $"StrictIncludes", $"false" },
{ $"StageDirectory", $"__REPOSITORY_ROOT__/Saved/StagedBuilds" },
Expand Down
218 changes: 139 additions & 79 deletions UET/Redpoint.Uet.BuildPipeline/BuildGraph/BuildGraph_Project.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static BuildConfigSourceGenerationContext Create(
new BuildConfigTestConverter<BuildConfigProjectDistribution>(serviceProvider),
new BuildConfigDeploymentConverter<BuildConfigPluginDistribution>(serviceProvider),
new BuildConfigDeploymentConverter<BuildConfigProjectDistribution>(serviceProvider),
new BuildConfigTargetPlatformConverter(),
}
});
}
Expand Down
21 changes: 21 additions & 0 deletions UET/Redpoint.Uet.Configuration/BuildConfigTargetPlatform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Redpoint.Uet.Configuration
{
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

public class BuildConfigTargetPlatform
{
/// <summary>
/// The platform name to build the project for.
/// </summary>
[JsonPropertyName("Platform")]
public string Platform { get; set; } = string.Empty;

/// <summary>
/// The flavors to cook an Android platform for. e.g. ASTC, DXT, ETC2, Multi.
/// </summary>
[JsonPropertyName("CookFlavors")]
[SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "This property is used for JSON serialization.")]
public string[]? CookFlavors { get; set; } = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
namespace Redpoint.Uet.Configuration
{
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Text.Json;

public class BuildConfigTargetPlatformConverter : JsonConverter<BuildConfigTargetPlatform[]>
{
public override BuildConfigTargetPlatform[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartArray)
{
throw new JsonException("Expected StartArray token");
}

var platforms = new List<BuildConfigTargetPlatform>();

while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
if (reader.TokenType == JsonTokenType.String)
{
platforms.Add(new BuildConfigTargetPlatform
{
Platform = reader.GetString()!
});
}
else if (reader.TokenType == JsonTokenType.StartObject)
{
var platform = new BuildConfigTargetPlatform();

while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
{
if (reader.TokenType != JsonTokenType.PropertyName)
{
throw new JsonException("Expected PropertyName token");
}

var propName = reader.GetString();
reader.Read();

switch (propName)
{
case nameof(BuildConfigTargetPlatform.Platform):
platform.Platform = reader.GetString()!;
break;
case nameof(BuildConfigTargetPlatform.CookFlavors):
if (reader.TokenType != JsonTokenType.StartArray)
{
throw new JsonException("Expected StartArray token");
}
List<string> cookFlavors = [];
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
cookFlavors.Add(reader.GetString()!);
}
platform.CookFlavors = cookFlavors.ToArray();
break;
}
}

platforms.Add(platform);
}
}

return platforms.ToArray();
}

public override void Write(Utf8JsonWriter writer, BuildConfigTargetPlatform[] value, JsonSerializerOptions options)
{
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BuildConfigPluginBuildTarget
/// </summary>
[JsonPropertyName("Platforms")]
[SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "This property is used for JSON serialization.")]
public string[] Platforms { get; set; } = Array.Empty<string>();
public BuildConfigTargetPlatform[] Platforms { get; set; } = [];

/// <summary>
/// If not specified, defaults to ["Development", "Shipping"].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Redpoint.Uet.Configuration.Project
{
using Redpoint.Uet.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

Expand All @@ -17,7 +18,7 @@ public class BuildConfigProjectBuildTarget
/// </summary>
[JsonPropertyName("Platforms")]
[SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "This property is used for JSON serialization.")]
public string[] Platforms { get; set; } = Array.Empty<string>();
public BuildConfigTargetPlatform[] Platforms { get; set; } = [];

/// <summary>
/// If not specified, defaults to ["Development", "Shipping"].
Expand Down
14 changes: 12 additions & 2 deletions UET/uet/Commands/Build/DefaultBuildSpecificationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private struct TargetConfig
public required string Targets;
public required string TargetPlatforms;
public required string Configurations;
public required string CookFlavors;
}

private bool VerifySourceFilesDoNotExceedSubmissionPathLimit(
Expand Down Expand Up @@ -114,18 +115,21 @@ private static TargetConfig ComputeTargetConfig(string name, BuildConfigProjectB
Targets = string.Empty,
TargetPlatforms = string.Empty,
Configurations = string.Empty,
CookFlavors = string.Empty,
};
}

var targets = target.Targets ?? new[] { $"Unreal{name}" };
var targetPlatforms = FilterIncompatiblePlatforms(target.Platforms, localExecutor);
var targetPlatforms = FilterIncompatiblePlatforms(target.Platforms.Select(x => x.Platform).ToArray(), localExecutor);
var configurations = target.Configurations ?? new[] { "Development", "Shipping" };
var cookFlavors = target.Platforms.FirstOrDefault(x => x.Platform == "Android")?.CookFlavors ?? [];

return new TargetConfig
{
Targets = string.Join(";", targets),
TargetPlatforms = string.Join(";", targetPlatforms),
Configurations = string.Join(";", configurations),
CookFlavors = string.Join(";", cookFlavors),
};
}

Expand All @@ -138,18 +142,20 @@ private static TargetConfig ComputeTargetConfig(string name, BuildConfigPluginBu
Targets = string.Empty,
TargetPlatforms = string.Empty,
Configurations = string.Empty,
CookFlavors = string.Empty,
};
}

var targets = new[] { $"Unreal{name}" };
var targetPlatforms = FilterIncompatiblePlatforms(target.Platforms, localExecutor);
var targetPlatforms = FilterIncompatiblePlatforms(target.Platforms.Select(x => x.Platform).ToArray(), localExecutor);
var configurations = target.Configurations ?? new[] { "Development", "Shipping" };

return new TargetConfig
{
Targets = string.Join(";", targets),
TargetPlatforms = string.Join(";", targetPlatforms),
Configurations = string.Join(";", configurations),
CookFlavors = string.Empty,
};
}

Expand Down Expand Up @@ -623,6 +629,8 @@ public async Task<BuildSpecification> BuildConfigProjectToBuildSpecAsync(
{ $"GameConfigurations", gameConfig.Configurations },
{ $"ClientConfigurations", clientConfig.Configurations },
{ $"ServerConfigurations", serverConfig.Configurations },
{ $"AndroidGameCookFlavors", gameConfig.CookFlavors },
{ $"AndroidClientCookFlavors", clientConfig.CookFlavors },
{ $"MacPlatforms", $"IOS;Mac" },
{ $"StrictIncludes", strictIncludes ? "true" : "false" },

Expand Down Expand Up @@ -824,6 +832,8 @@ public BuildSpecification ProjectPathSpecToBuildSpec(
{ $"GameConfigurations", gameConfigurations },
{ $"ClientConfigurations", string.Empty },
{ $"ServerConfigurations", string.Empty },
{ $"AndroidGameCookFlavors", string.Empty },
{ $"AndroidClientCookFlavors", string.Empty },
{ $"MacPlatforms", $"IOS;Mac" },
{ $"StrictIncludes", strictIncludes ? "true" : "false" },

Expand Down

0 comments on commit 260f20c

Please sign in to comment.