From ad24f072ed435500e81a82591260320fe25e3ce2 Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Sun, 6 Nov 2022 14:30:06 -0500 Subject: [PATCH 1/7] Copy build-related logs into the content build directory --- Options/OptionBuildAddressables.cs | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Options/OptionBuildAddressables.cs b/Options/OptionBuildAddressables.cs index f1d0e09..efdbc0c 100644 --- a/Options/OptionBuildAddressables.cs +++ b/Options/OptionBuildAddressables.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.IO; using UnityEngine; using sttz.Trimmer.BaseOptions; using UnityEditor.Build.Reporting; @@ -15,6 +16,8 @@ using UnityEditor.AddressableAssets; using UnityEditor.Build; using UnityEditor; +using UnityEngine.AddressableAssets; +using IOPath = System.IO.Path; namespace sttz.Trimmer.Options { @@ -132,6 +135,46 @@ protected override void Configure() } } + /// + /// Option to copy certain Addressables-related build logs into the output directory. + /// + /// + /// Addressables exposes a detailed timeline of its build process through + /// a file located at Library/com.unity.addressables/AddressablesBuildTEP.json. + /// This file is overwritten with each Addressables build, + /// which can complicate analysis if your project involves multiple build profiles. + /// This option, if enabled, will copy the aforementioned file + /// to the location given by TODO + /// + /// + public class OptionCopyBuildTimelineToOutputDirectory : OptionToggle + { + protected override void Configure() + { + DefaultValue = false; + } + } + + /// + /// Option to copy certain Addressables-related build logs into the output directory. + /// + /// + /// Addressables exposes a detailed timeline of its build process through + /// a file located at Library/com.unity.addressables/AddressablesBuildTEP.json. + /// This file is overwritten with each Addressables build, + /// which can complicate analysis if your project involves multiple build profiles. + /// This option, if enabled, will copy the aforementioned file + /// to the location given by TODO + /// + /// + public class OptionCopyBuildLayoutToOutputDirectory : OptionToggle + { + protected override void Configure() + { + DefaultValue = false; + } + } + override public BuildPlayerOptions PrepareBuild(BuildPlayerOptions options, OptionInclusion inclusion) { options = base.PrepareBuild(options, inclusion); @@ -182,6 +225,26 @@ void BuildAddressables() // Build! AddressableAssetSettings.BuildPlayerContent(out result); + + if (GetChild() is { Value: true }) { + // Copy the build timeline to the output directory + const string BuildTimelineFilename = "AddressablesBuildTEP.json"; + var buildLogLibraryPath = IOPath.Combine(Addressables.LibraryPath, BuildTimelineFilename); + var localBuildPath = settings.profileSettings.GetValueByName(settings.activeProfileId, AddressableAssetSettings.kLocalBuildPath); + var localBuildPathResolved = settings.profileSettings.EvaluateString(settings.activeProfileId, localBuildPath); + var buildLogDataPath = IOPath.Combine(localBuildPathResolved, BuildTimelineFilename); + File.Copy(buildLogLibraryPath, buildLogDataPath); + } + + if (GetChild() is { Value: true }) { + // Copy the build timeline to the output directory + const string BuildLayoutFilename = "buildlayout.txt"; + var buildLogLibraryPath = IOPath.Combine(Addressables.LibraryPath, BuildLayoutFilename); + var localBuildPath = settings.profileSettings.GetValueByName(settings.activeProfileId, AddressableAssetSettings.kLocalBuildPath); + var localBuildPathResolved = settings.profileSettings.EvaluateString(settings.activeProfileId, localBuildPath); + var buildLogDataPath = IOPath.Combine(localBuildPathResolved, BuildLayoutFilename); + File.Copy(buildLogLibraryPath, buildLogDataPath); + } } finally { // Clear intermediate data and restore overrides From eff6f13c9f2b425cea0d272b692ba564fa00f4ed Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Sun, 6 Nov 2022 15:23:20 -0500 Subject: [PATCH 2/7] Only copy the build logs if they actually exist --- Options/OptionBuildAddressables.cs | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Options/OptionBuildAddressables.cs b/Options/OptionBuildAddressables.cs index ada177b..c1c8296 100644 --- a/Options/OptionBuildAddressables.cs +++ b/Options/OptionBuildAddressables.cs @@ -10,13 +10,13 @@ using System.IO; using UnityEngine; using sttz.Trimmer.BaseOptions; -using UnityEditor.Build.Reporting; using UnityEditor.AddressableAssets.Settings; using UnityEditor.AddressableAssets.Build; using UnityEditor.AddressableAssets; using UnityEditor.Build; using UnityEditor; using UnityEngine.AddressableAssets; +using IOFile = System.IO.File; using IOPath = System.IO.Path; namespace sttz.Trimmer.Options @@ -226,24 +226,27 @@ void BuildAddressables() // Build! AddressableAssetSettings.BuildPlayerContent(out result); + var localBuildPath = settings.RemoteCatalogBuildPath.GetValue(settings); if (GetChild() is { Value: true }) { // Copy the build timeline to the output directory - const string BuildTimelineFilename = "AddressablesBuildTEP.json"; - var buildLogLibraryPath = IOPath.Combine(Addressables.LibraryPath, BuildTimelineFilename); - var localBuildPath = settings.profileSettings.GetValueByName(settings.activeProfileId, AddressableAssetSettings.kLocalBuildPath); - var localBuildPathResolved = settings.profileSettings.EvaluateString(settings.activeProfileId, localBuildPath); - var buildLogDataPath = IOPath.Combine(localBuildPathResolved, BuildTimelineFilename); - File.Copy(buildLogLibraryPath, buildLogDataPath); + const string BuildTimelineFilename = "AddressablesBuildTEP.json"; + var buildTimelineSource = IOPath.Combine(Addressables.LibraryPath, BuildTimelineFilename); + + if (IOFile.Exists(buildTimelineSource)) { + var buildTimelineDestination = IOPath.Combine(localBuildPath, BuildTimelineFilename); + File.Copy(buildTimelineSource, buildTimelineDestination); + } } - + if (GetChild() is { Value: true }) { - // Copy the build timeline to the output directory + // Copy the build layout to the output directory const string BuildLayoutFilename = "buildlayout.txt"; - var buildLogLibraryPath = IOPath.Combine(Addressables.LibraryPath, BuildLayoutFilename); - var localBuildPath = settings.profileSettings.GetValueByName(settings.activeProfileId, AddressableAssetSettings.kLocalBuildPath); - var localBuildPathResolved = settings.profileSettings.EvaluateString(settings.activeProfileId, localBuildPath); - var buildLogDataPath = IOPath.Combine(localBuildPathResolved, BuildLayoutFilename); - File.Copy(buildLogLibraryPath, buildLogDataPath); + var buildLayoutSource = IOPath.Combine(Addressables.LibraryPath, BuildLayoutFilename); + + if (IOFile.Exists(buildLayoutSource)) { + var buildLayoutDestination = IOPath.Combine(localBuildPath, BuildLayoutFilename); + File.Copy(buildLayoutSource, buildLayoutDestination); + } } } finally { // Restore overrides From f51676e77b9d31f6e5b598bf6d80a55d07e91775 Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Sun, 6 Nov 2022 15:34:27 -0500 Subject: [PATCH 3/7] Add clarifying comments --- Options/OptionBuildAddressables.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Options/OptionBuildAddressables.cs b/Options/OptionBuildAddressables.cs index c1c8296..2565fb3 100644 --- a/Options/OptionBuildAddressables.cs +++ b/Options/OptionBuildAddressables.cs @@ -131,7 +131,8 @@ protected override void Configure() } /// - /// Option to copy certain Addressables-related build logs into the output directory. + /// Option to copy the generated build timeline to the output directory + /// to simplify analysis later. /// /// /// Addressables exposes a detailed timeline of its build process through @@ -139,7 +140,7 @@ protected override void Configure() /// This file is overwritten with each Addressables build, /// which can complicate analysis if your project involves multiple build profiles. /// This option, if enabled, will copy the aforementioned file - /// to the location given by TODO + /// to the directory given by . /// /// public class OptionCopyBuildTimelineToOutputDirectory : OptionToggle @@ -151,17 +152,23 @@ protected override void Configure() } /// - /// Option to copy certain Addressables-related build logs into the output directory. + /// Option to copy the generated build layout to the output directory + /// to simplify analysis later. /// /// - /// Addressables exposes a detailed timeline of its build process through - /// a file located at Library/com.unity.addressables/AddressablesBuildTEP.json. + /// + /// Addressables provides a detailed layout of the asset bundles it produces in + /// a file located at Library/com.unity.addressables/buildlayout.txt. /// This file is overwritten with each Addressables build, /// which can complicate analysis if your project involves multiple build profiles. /// This option, if enabled, will copy the aforementioned file - /// to the location given by TODO + /// to the directory given by . + /// + /// + /// If build layouts are disabled, this option will do nothing. + /// /// - /// + /// public class OptionCopyBuildLayoutToOutputDirectory : OptionToggle { protected override void Configure() @@ -226,6 +233,7 @@ void BuildAddressables() // Build! AddressableAssetSettings.BuildPlayerContent(out result); + // Copy relevant logs to the build directory for easier analysis, if requested var localBuildPath = settings.RemoteCatalogBuildPath.GetValue(settings); if (GetChild() is { Value: true }) { // Copy the build timeline to the output directory From c03abaf12afefd25f9b9c12f7d21bc074b26988d Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Sun, 6 Nov 2022 15:37:31 -0500 Subject: [PATCH 4/7] Mitigate a potential (if unlikely) NRE --- Options/OptionBuildAddressables.cs | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Options/OptionBuildAddressables.cs b/Options/OptionBuildAddressables.cs index 2565fb3..e9a3144 100644 --- a/Options/OptionBuildAddressables.cs +++ b/Options/OptionBuildAddressables.cs @@ -234,26 +234,28 @@ void BuildAddressables() AddressableAssetSettings.BuildPlayerContent(out result); // Copy relevant logs to the build directory for easier analysis, if requested - var localBuildPath = settings.RemoteCatalogBuildPath.GetValue(settings); - if (GetChild() is { Value: true }) { - // Copy the build timeline to the output directory - const string BuildTimelineFilename = "AddressablesBuildTEP.json"; - var buildTimelineSource = IOPath.Combine(Addressables.LibraryPath, BuildTimelineFilename); + var localBuildPath = settings.RemoteCatalogBuildPath?.GetValue(settings); + if (localBuildPath != null) { // little bit of insurance against a malformed settings file + if (GetChild() is { Value: true }) { + // Copy the build timeline to the output directory + const string BuildTimelineFilename = "AddressablesBuildTEP.json"; + var buildTimelineSource = IOPath.Combine(Addressables.LibraryPath, BuildTimelineFilename); - if (IOFile.Exists(buildTimelineSource)) { - var buildTimelineDestination = IOPath.Combine(localBuildPath, BuildTimelineFilename); - File.Copy(buildTimelineSource, buildTimelineDestination); + if (IOFile.Exists(buildTimelineSource)) { + var buildTimelineDestination = IOPath.Combine(localBuildPath, BuildTimelineFilename); + File.Copy(buildTimelineSource, buildTimelineDestination); + } } - } - if (GetChild() is { Value: true }) { - // Copy the build layout to the output directory - const string BuildLayoutFilename = "buildlayout.txt"; - var buildLayoutSource = IOPath.Combine(Addressables.LibraryPath, BuildLayoutFilename); + if (GetChild() is { Value: true }) { + // Copy the build layout to the output directory + const string BuildLayoutFilename = "buildlayout.txt"; + var buildLayoutSource = IOPath.Combine(Addressables.LibraryPath, BuildLayoutFilename); - if (IOFile.Exists(buildLayoutSource)) { - var buildLayoutDestination = IOPath.Combine(localBuildPath, BuildLayoutFilename); - File.Copy(buildLayoutSource, buildLayoutDestination); + if (IOFile.Exists(buildLayoutSource)) { + var buildLayoutDestination = IOPath.Combine(localBuildPath, BuildLayoutFilename); + File.Copy(buildLayoutSource, buildLayoutDestination); + } } } } finally { From 1809c5677c16a7c19742b02722e29114afae4a8d Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Sun, 6 Nov 2022 16:13:24 -0500 Subject: [PATCH 5/7] Allow the exact destination of the Addressables logs to be customized --- Options/OptionBuildAddressables.cs | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Options/OptionBuildAddressables.cs b/Options/OptionBuildAddressables.cs index e9a3144..188f706 100644 --- a/Options/OptionBuildAddressables.cs +++ b/Options/OptionBuildAddressables.cs @@ -139,15 +139,16 @@ protected override void Configure() /// a file located at Library/com.unity.addressables/AddressablesBuildTEP.json. /// This file is overwritten with each Addressables build, /// which can complicate analysis if your project involves multiple build profiles. - /// This option, if enabled, will copy the aforementioned file - /// to the directory given by . + /// This option, if not empty, will copy the aforementioned file + /// to the directory given by the value, + /// as resolved by the profile. /// /// - public class OptionCopyBuildTimelineToOutputDirectory : OptionToggle + public class OptionCopyBuildTimelineToOutputDirectory : OptionString { protected override void Configure() { - DefaultValue = false; + DefaultValue = AddressableAssetSettings.kLocalBuildPathValue; } } @@ -161,19 +162,20 @@ protected override void Configure() /// a file located at Library/com.unity.addressables/buildlayout.txt. /// This file is overwritten with each Addressables build, /// which can complicate analysis if your project involves multiple build profiles. - /// This option, if enabled, will copy the aforementioned file - /// to the directory given by . + /// This option, if not empty, will copy the aforementioned file + /// to the directory given by the value, + /// as resolved by the profile. /// /// /// If build layouts are disabled, this option will do nothing. /// /// /// - public class OptionCopyBuildLayoutToOutputDirectory : OptionToggle + public class OptionCopyBuildLayoutToOutputDirectory : OptionString { protected override void Configure() { - DefaultValue = false; + DefaultValue = AddressableAssetSettings.kLocalBuildPathValue; } } @@ -234,29 +236,16 @@ void BuildAddressables() AddressableAssetSettings.BuildPlayerContent(out result); // Copy relevant logs to the build directory for easier analysis, if requested - var localBuildPath = settings.RemoteCatalogBuildPath?.GetValue(settings); - if (localBuildPath != null) { // little bit of insurance against a malformed settings file - if (GetChild() is { Value: true }) { - // Copy the build timeline to the output directory - const string BuildTimelineFilename = "AddressablesBuildTEP.json"; - var buildTimelineSource = IOPath.Combine(Addressables.LibraryPath, BuildTimelineFilename); - - if (IOFile.Exists(buildTimelineSource)) { - var buildTimelineDestination = IOPath.Combine(localBuildPath, BuildTimelineFilename); - File.Copy(buildTimelineSource, buildTimelineDestination); - } - } - - if (GetChild() is { Value: true }) { - // Copy the build layout to the output directory - const string BuildLayoutFilename = "buildlayout.txt"; - var buildLayoutSource = IOPath.Combine(Addressables.LibraryPath, BuildLayoutFilename); + var buildTimelineDestinationExpression = GetChild()?.Value; + if (!string.IsNullOrEmpty(buildTimelineDestinationExpression)) + { + CopyBuildLogFile(settings, "AddressablesBuildTEP.json", buildTimelineDestinationExpression); + } - if (IOFile.Exists(buildLayoutSource)) { - var buildLayoutDestination = IOPath.Combine(localBuildPath, BuildLayoutFilename); - File.Copy(buildLayoutSource, buildLayoutDestination); - } - } + var buildLayoutDestinationExpression = GetChild()?.Value; + if (!string.IsNullOrEmpty(buildLayoutDestinationExpression)) + { + CopyBuildLogFile(settings, "buildlayout.txt", buildLayoutDestinationExpression); } } finally { // Restore overrides @@ -277,6 +266,17 @@ void BuildAddressables() Debug.Log($"Built {result.LocationCount} Addressable assets in {result.Duration}s to {result.OutputPath}"); } + + void CopyBuildLogFile(AddressableAssetSettings settings, string fileName, string destination) + { + var sourcePath = IOPath.Combine(Addressables.LibraryPath, fileName); + + if (IOFile.Exists(sourcePath)) + { + var destinationPath = settings.profileSettings.EvaluateString(settings.activeProfileId, destination); + File.Copy(sourcePath, IOPath.Combine(destinationPath, fileName)); + } + } } } From bff8003d84a5b7ebaf1f5b8163e3005738aeba6c Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Mon, 7 Nov 2022 09:14:24 -0500 Subject: [PATCH 6/7] Change the default value --- Options/OptionBuildAddressables.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Options/OptionBuildAddressables.cs b/Options/OptionBuildAddressables.cs index 188f706..f1c95f5 100644 --- a/Options/OptionBuildAddressables.cs +++ b/Options/OptionBuildAddressables.cs @@ -148,7 +148,7 @@ public class OptionCopyBuildTimelineToOutputDirectory : OptionString { protected override void Configure() { - DefaultValue = AddressableAssetSettings.kLocalBuildPathValue; + DefaultValue = "[UnityEngine.AddressableAssets.Addressables.BuildPath]"; } } @@ -175,7 +175,7 @@ public class OptionCopyBuildLayoutToOutputDirectory : OptionString { protected override void Configure() { - DefaultValue = AddressableAssetSettings.kLocalBuildPathValue; + DefaultValue = "[UnityEngine.AddressableAssets.Addressables.BuildPath]"; } } From 19ec476e45fab7a518c17d0264763e6041a0bd3b Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Mon, 7 Nov 2022 09:16:48 -0500 Subject: [PATCH 7/7] Change a word --- Options/OptionBuildAddressables.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Options/OptionBuildAddressables.cs b/Options/OptionBuildAddressables.cs index f1c95f5..3cbe5b4 100644 --- a/Options/OptionBuildAddressables.cs +++ b/Options/OptionBuildAddressables.cs @@ -167,7 +167,7 @@ protected override void Configure() /// as resolved by the profile. /// /// - /// If build layouts are disabled, this option will do nothing. + /// If build layout reports are disabled, this option will do nothing. /// /// ///