Skip to content

Commit

Permalink
Log more information from build script
Browse files Browse the repository at this point in the history
  • Loading branch information
webbertakken committed Dec 1, 2019
1 parent 2becab2 commit 5d2af92
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions test-project/Assets/Editor/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@

static class Builder
{
private static string EOL = Environment.NewLine;

private static void ParseCommandLineArguments(out Dictionary<string, string> providedArguments)
{
providedArguments = new Dictionary<string, string>();
string[] args = Environment.GetCommandLineArgs();

// Output args in console
Debug.Log("Arguments given: ");
foreach (string arg in args) {
Debug.Log(arg);
}
Console.WriteLine(
$"{EOL}" +
$"###########################{EOL}" +
$"# Parsing settings #{EOL}" +
$"###########################{EOL}" +
$"{EOL}"
);

// Extract flags with optional values
for (int current = 0, next = 1; current < args.Length; current++, next++) {
Expand All @@ -27,10 +31,11 @@ private static void ParseCommandLineArguments(out Dictionary<string, string> pro
string flag = args[current].TrimStart('-');

// Parse optional value
bool flagHasValue = next >= args.Length || !args[next].StartsWith("-");
bool flagHasValue = next < args.Length && !args[next].StartsWith("-");
string value = flagHasValue ? args[next].TrimStart('-') : "";

// Assign
Console.WriteLine($"Found flag \"{flag}\" with value \"{value}\".");
providedArguments.Add(flag, value);
}
}
Expand All @@ -40,12 +45,12 @@ private static Dictionary<string, string> GetValidatedOptions()
ParseCommandLineArguments(out var validatedOptions);

if (!validatedOptions.TryGetValue("projectPath", out var projectPath)) {
Debug.Log("Missing argument -projectPath");
Console.WriteLine("Missing argument -projectPath");
EditorApplication.Exit(110);
}

if (!validatedOptions.TryGetValue("buildTarget", out var buildTarget)) {
Debug.Log("Missing argument -buildTarget");
Console.WriteLine("Missing argument -buildTarget");
EditorApplication.Exit(120);
}

Expand All @@ -54,17 +59,17 @@ private static Dictionary<string, string> GetValidatedOptions()
}

if (!validatedOptions.TryGetValue("customBuildPath", out var customBuildPath)) {
Debug.Log("Missing argument -customBuildPath");
Console.WriteLine("Missing argument -customBuildPath");
EditorApplication.Exit(130);
}

string defaultCustomBuildName = "TestBuild";
if (!validatedOptions.TryGetValue("customBuildName", out var customBuildName)) {
Debug.Log($"Missing argument -customBuildName, defaulting to {defaultCustomBuildName}.");
Console.WriteLine($"Missing argument -customBuildName, defaulting to {defaultCustomBuildName}.");
validatedOptions.Add("customBuildName", defaultCustomBuildName);
}
else if (customBuildName == "") {
Debug.Log($"Invalid argument -customBuildName, defaulting to {defaultCustomBuildName}.");
Console.WriteLine($"Invalid argument -customBuildName, defaulting to {defaultCustomBuildName}.");
validatedOptions.Add("customBuildName", defaultCustomBuildName);
}

Expand Down Expand Up @@ -100,8 +105,7 @@ public static void BuildProject()

private static void ReportSummary(BuildSummary summary)
{
var EOL = Environment.NewLine;
Debug.Log(
Console.WriteLine(
$"{EOL}" +
$"###########################{EOL}" +
$"# Build results #{EOL}" +
Expand All @@ -118,22 +122,22 @@ private static void ReportSummary(BuildSummary summary)
private static void ExitWithResult(BuildResult result)
{
if (result == BuildResult.Succeeded) {
Debug.Log("Build succeeded!");
Console.WriteLine("Build succeeded!");
EditorApplication.Exit(0);
}

if (result == BuildResult.Failed) {
Debug.Log("Build failed!");
Console.WriteLine("Build failed!");
EditorApplication.Exit(101);
}

if (result == BuildResult.Cancelled) {
Debug.Log("Build cancelled!");
Console.WriteLine("Build cancelled!");
EditorApplication.Exit(102);
}

if (result == BuildResult.Unknown) {
Debug.Log("Build result is unknown!");
Console.WriteLine("Build result is unknown!");
EditorApplication.Exit(103);
}
}
Expand Down

0 comments on commit 5d2af92

Please sign in to comment.