diff --git a/.gitignore b/.gitignore index 7043d58b0..3f287e6c9 100644 --- a/.gitignore +++ b/.gitignore @@ -101,6 +101,8 @@ crashlytics-build.properties chaintest.out TestResults_Edit.xml TestResults_Play.xml +Builds/ +PlatformCompileTestErrors/ # Temporary test files Assets/InitTestScene*.unity* diff --git a/Assets/SequenceSDK/Editor.meta b/Assets/SequenceSDK/Editor.meta new file mode 100644 index 000000000..7ec767b56 --- /dev/null +++ b/Assets/SequenceSDK/Editor.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c69089558d4b414195f1a76d05e6f863 +timeCreated: 1730928057 \ No newline at end of file diff --git a/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs b/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs new file mode 100644 index 000000000..d9539cead --- /dev/null +++ b/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; +using UnityEditor; +using UnityEditor.Build.Reporting; +using UnityEngine; + +namespace Sequence.Editor +{ + /// + /// This test will build the project for all platforms and check if the build is compiled successfully + /// + public static class SequencePlatformCompileTest + { + private const string BuildDirectory = "Builds"; + private static List _failedBuilds; + + [MenuItem("Sequence Dev/Platform Compile Test")] + public static void RunBuildTest() + { + BigInteger startEpochTime = new BigInteger(DateTimeOffset.Now.ToUnixTimeSeconds()); + ClearPreviousErrors(); + + string[] scenes = GetEnabledScenes(); + +#if UNITY_EDITOR_WIN + BuildPlatform(BuildTarget.StandaloneWindows64, $"{BuildDirectory}/WindowsBuild", scenes); +#endif +#if UNITY_EDITOR_OSX + BuildPlatform(BuildTarget.StandaloneOSX, $"{BuildDirectory}/MacOSBuild", scenes); + BuildPlatform(BuildTarget.iOS, $"{BuildDirectory}/iOSBuild", scenes); +#endif + BuildPlatform(BuildTarget.WebGL, $"{BuildDirectory}/WebGLBuild", scenes); + BuildPlatform(BuildTarget.Android, $"{BuildDirectory}/AndroidBuild", scenes); + + Debug.Log("Platform Compile Test Completed. Check the console for errors."); + foreach (var failedBuild in _failedBuilds) + { + Debug.LogError(failedBuild); + } + + BigInteger endEpochTime = new BigInteger(DateTimeOffset.Now.ToUnixTimeSeconds()); + Debug.Log($"Total Test Time: {endEpochTime - startEpochTime} seconds"); + } + + private static void ClearPreviousErrors() + { + _failedBuilds = new List(); + + string errorDirectory = "PlatformCompileTestErrors"; + if (Directory.Exists(errorDirectory)) + { + var txtFiles = Directory.GetFiles(errorDirectory, "*.txt"); + foreach (var file in txtFiles) + { + File.Delete(file); + } + } + else + { + Directory.CreateDirectory(errorDirectory); + } + } + + private static string[] GetEnabledScenes() + { + return EditorBuildSettings.scenes + .Where(scene => scene.enabled) + .Select(scene => scene.path) + .ToArray(); + } + + private static void BuildPlatform(BuildTarget target, string path, string[] scenes) + { + try + { + BuildReport report = BuildPipeline.BuildPlayer(scenes, path, target, BuildOptions.None); + + if (report.summary.result != BuildResult.Succeeded) + { + _failedBuilds.Add($"{target} build failed with {report.summary.totalErrors} errors. Please see {BuildDirectory}/{target}.txt for details."); + LogErrorsToFile(report, target); + } + } + finally + { + if (Directory.Exists(BuildDirectory)) + { + Directory.Delete(BuildDirectory, true); + } + } + } + + private static void LogErrorsToFile(BuildReport report, BuildTarget target) + { + string errorDirectory = "PlatformCompileTestErrors"; + if (!Directory.Exists(errorDirectory)) + { + Directory.CreateDirectory(errorDirectory); + } + + string errorFilePath = Path.Combine(errorDirectory, $"{target}.txt"); + + using (StreamWriter writer = new StreamWriter(errorFilePath, false)) + { + writer.WriteLine($"Build Time: {DateTime.Now:yyyy-MM-dd HH:mm:ss}"); + writer.WriteLine($"Platform: {target}"); + writer.WriteLine($"Build Errors Summary:"); + writer.WriteLine($"Total Errors: {report.summary.totalErrors}"); + writer.WriteLine(); + writer.WriteLine("Detailed Errors:"); + + foreach (var step in report.steps) + { + foreach (var message in step.messages) + { + if (message.type == LogType.Error) + { + writer.WriteLine($"[{message.type}] {message.content}"); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs.meta b/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs.meta new file mode 100644 index 000000000..989f0194d --- /dev/null +++ b/Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2179ce729f5144d897df0065aad79ff1 +timeCreated: 1730927874 \ No newline at end of file diff --git a/README.md b/README.md index 8c1c48eeb..d554eb0f5 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ Many of the tests, specifically those for our custom Ethereum client, make use o Before running tests, boot up the test chain with `make start-testchain`. You may find that you need to stop (control + c) the testchain and restart it when running the test suite again. +### Platform Compile Test +When making large amounts of changes or any changes that may impact builds (assemblies, dependencies, etc.), it is useful to confirm that the SDK still compiles on the [targeted platforms](#supported-platforms). To do this navigate to the top menu and click `Sequence Dev > Platform Compile Test`. This will build the project, and the currently selected scenes in the build settings, on all targeted platforms. All build errors encountered will be recorded in `PlatformCompileTestErrors/.txt`. The builds will be cleaned up once completed. This test doesn't run any tests against the individual builds; it only confirms that the project builds on a given platform. + ### Testing via command line It can sometimes be useful to quickly test the project via command line. This can be done without opening Unity or starting the testchain. #### One-Time Setup