Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ crashlytics-build.properties
chaintest.out
TestResults_Edit.xml
TestResults_Play.xml
Builds/
PlatformCompileTestErrors/

# Temporary test files
Assets/InitTestScene*.unity*
Expand Down
3 changes: 3 additions & 0 deletions Assets/SequenceSDK/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 128 additions & 0 deletions Assets/SequenceSDK/Editor/SequencePlatformCompileTest.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// This test will build the project for all platforms and check if the build is compiled successfully
/// </summary>
public static class SequencePlatformCompileTest
{
private const string BuildDirectory = "Builds";
private static List<string> _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>();

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}");
}
}
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<build platform>.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
Expand Down