Skip to content

Commit

Permalink
Merge branch 'release/0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesnick committed Jan 21, 2019
2 parents 9797b9b + 557499e commit 336b08b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/Cake.Unity.FSharp.Tests/UnityEditorArgumentsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ let ``CLI arguments with custom argument "login" of value "admin" should contain
[<Test>]
let ``CLI arguments with ExecuteMethod "Game.Build.Run" should contain "-executeMethod Game.Build.Run"`` () =
() |> UnityEditorArguments |> setExecuteMethod "Game.Build.Run" |> commandLineArguments |> should haveSubstring "-executeMethod Game.Build.Run"
[<Test>]
let ``default BatchMode value should be true`` () =
UnityEditorArguments().BatchMode |> should equal true
[<Test>]
let ``default Quit value should be true`` () =
UnityEditorArguments().Quit |> should equal true
2 changes: 1 addition & 1 deletion src/Cake.Unity/UnityAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void UnityBuild(this ICakeContext context, DirectoryPath projectPa
[CakeMethodAlias]
[CakeAliasCategory("Build")]
public static void UnityEditor(this ICakeContext context, FilePath unityEditorPath, UnityEditorArguments arguments) =>
new UnityEditor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools)
new UnityEditor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log)
.Run(unityEditorPath, arguments);

/// <summary>
Expand Down
77 changes: 69 additions & 8 deletions src/Cake.Unity/UnityEditor.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,89 @@
using System.Collections.Generic;
using System.IO;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Core.Tooling;

namespace Cake.Unity
{
internal class UnityEditor : Tool<UnityEditorSettings>
{
private readonly IFileSystem fileSystem;
private readonly ICakeEnvironment environment;
private readonly ICakeLog log;

public UnityEditor(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools)
: base(fileSystem, environment, processRunner, tools) =>
public UnityEditor(IFileSystem fileSystem, ICakeEnvironment environment, IProcessRunner processRunner, IToolLocator tools, ICakeLog log)
: base(fileSystem, environment, processRunner, tools)
{
this.fileSystem = fileSystem;
this.environment = environment;
this.log = log;
}

protected override string GetToolName() => "Unity Editor";

protected override IEnumerable<string> GetToolExecutableNames() => new[] { "Unity.exe" };

public void Run(FilePath unityEditorPath, UnityEditorArguments arguments) =>
Run(
new UnityEditorSettings(arguments, environment)
public void Run(FilePath unityEditorPath, UnityEditorArguments arguments)
{
WarnIfLogLocationNotSet(arguments);

try
{
Run(new UnityEditorSettings(arguments, environment) { ToolPath = unityEditorPath });
}
catch
{
if (arguments.LogFile == null)
{
log.Error("Execution of Unity Editor failed.");
log.Warning("Cannot forward log file to output because LogFile argument is missing.");
}
else
{
ToolPath = unityEditorPath,
},
new ProcessArgumentBuilder());
log.Error("Execution of Unity Editor failed.");
log.Error("Please analyze log below for the reasons of failure.");
ForwardLogFileToOutput(arguments.LogFile);
}

throw;
}
}

private void Run(UnityEditorSettings settings) => Run(settings, new ProcessArgumentBuilder());

private void ForwardLogFileToOutput(FilePath logPath)
{
var logFile = fileSystem.GetFile(logPath);

if (!logFile.Exists)
{
log.Warning("Unity Editor log file not found: {0}", logPath);
return;
}

foreach (var line in ReadLogSafe(logFile))
{
log.Information(line);
}
}

private static IEnumerable<string> ReadLogSafe(IFile file)
{
using (var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var reader = new StreamReader(stream))
while (!reader.EndOfStream)
yield return reader.ReadLine();
}

private void WarnIfLogLocationNotSet(UnityEditorArguments arguments)
{
if (arguments.LogFile == null)
{
log.Warning("LogFile is not specified by Unity Editor arguments.");
log.Warning("Please specify it for ability to forward Unity log to console.");
}
}
}
}
4 changes: 2 additions & 2 deletions src/Cake.Unity/UnityEditorArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class UnityEditorArguments
/// <para>Note that in batch mode, Unity sends a minimal version of its log output to the console. However, the Log Files still contain the full log information. You cannot open a project in batch mode while the Editor has the same project open; only a single instance of Unity can run at a time. </para>
/// <para>Tip: To check whether you are running the Editor or Standalone Player in batch mode, use the Application.isBatchMode operator. </para>
/// </summary>
public bool BatchMode { get; set; }
public bool BatchMode { get; set; } = true;

/// <summary>
/// Build a 32-bit standalone Windows player (for example, -buildWindowsPlayer path/to/your/build.exe).
Expand All @@ -42,7 +42,7 @@ public class UnityEditorArguments
/// <summary>
/// Quit the Unity Editor after other commands have finished executing. Note that this can cause error messages to be hidden (however, they still appear in the Editor.log file).
/// </summary>
public bool Quit { get; set; }
public bool Quit { get; set; } = true;

/// <summary>
/// <para>Custom arguments which can further be processed in Unity Editor script by calling System.Environment.GetCommandLineArgs method. </para>
Expand Down

0 comments on commit 336b08b

Please sign in to comment.