Skip to content

Commit

Permalink
Merge branch 'release/0.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesnick committed Jan 24, 2019
2 parents 336b08b + e5e9942 commit 0645b4c
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 28 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ The API is not in any way final and will change.

Examples
-------

```csharp
#addin Cake.Unity

Task("Default").Does(() =>
UnityEditor(
2018, 3,
new UnityEditorArguments
{
ProjectPath = "A:/UnityProject",
BuildWindowsPlayer = "A:/Build/game.exe",
LogFile = "A:/Build/unity.log",
},
new UnityEditorSettings
{
RealTimeLog = true,
}));

RunTarget("Default");
```

```csharp
#addin Cake.Unity

Expand Down
12 changes: 7 additions & 5 deletions src/Cake.Unity/SeekerOfEditors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public IReadOnlyCollection<UnityEditorDescriptor> Seek()
var candidates = globber.GetFiles(searchPattern).ToList();

log.Debug("Found {0} candidates.", candidates.Count);
log.Debug(string.Empty);

var editors =
from candidatePath in candidates
Expand All @@ -45,7 +46,6 @@ from candidatePath in candidates

private UnityVersion DetermineVersion(FilePath editorPath)
{
log.Debug(string.Empty);
log.Debug("Determining version of Unity Editor at path {0}...", editorPath);

var fileVersion = FileVersionInfo.GetVersionInfo(editorPath.FullPath);
Expand All @@ -54,10 +54,10 @@ private UnityVersion DetermineVersion(FilePath editorPath)

if (year <= 0 || stream <= 0 || update < 0)
{
log.Warning(
"Unity Editor file version {0} at path {1} is incorrect. Expected first two parts to be positive numbers and third one to be non negative.",
$"{year}.{stream}.{update}.{fileVersion.FilePrivatePart}",
editorPath.FullPath);
log.Warning("Unity Editor file version {0} is incorrect.", $"{year}.{stream}.{update}.{fileVersion.FilePrivatePart}");
log.Warning("Expected first two numbers to be positive and third one to be non negative.");
log.Warning("Path: {0}", editorPath.FullPath);
log.Warning(string.Empty);
return null;
}

Expand All @@ -69,12 +69,14 @@ private UnityVersion DetermineVersion(FilePath editorPath)
{
var version = new UnityVersion(year, stream, update, suffix.Value.character, suffix.Value.number);
log.Debug("Result Unity Editor version (full): {0}", version);
log.Debug(string.Empty);
return version;
}
else
{
var version = new UnityVersion(year, stream, update);
log.Debug("Result Unity Editor version (short): {0}", version);
log.Debug(string.Empty);
return version;
}
}
Expand Down
172 changes: 168 additions & 4 deletions src/Cake.Unity/UnityAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static void UnityBuild(this ICakeContext context, DirectoryPath projectPa
tool.Run(context, projectPath, platform);
}



/// <summary>
/// Executes Unity Editor via command-line interface.
/// </summary>
Expand All @@ -35,21 +37,183 @@ public static void UnityBuild(this ICakeContext context, DirectoryPath projectPa
/// <example>
/// <code>
/// var unityEditor = FindUnityEditor(2018, 3) ?? throw new Exception("Cannot find Unity Editor 2018.3.");
///
/// UnityEditor(unityEditor.Path, new UnityEditorArguments
/// {
/// BatchMode = true,
/// ProjectPath = "A:/UnityProject",
/// BuildWindowsPlayer = "A:/Build/game.exe",
/// LogFile = "A:/Build/unity.log",
/// Quit = true,
/// });
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build")]
public static void UnityEditor(this ICakeContext context, FilePath unityEditorPath, UnityEditorArguments arguments) =>
public static void UnityEditor(this ICakeContext context,
FilePath unityEditorPath, UnityEditorArguments arguments) =>
UnityEditor(context, unityEditorPath, arguments, new UnityEditorSettings());

/// <summary>
/// Executes Unity Editor via command-line interface.
/// </summary>
/// <param name="unityEditorPath">Path to Unity Editor executable.</param>
/// <param name="arguments">Unity Editor command-line arguments.</param>
/// <param name="settings">Settings which affect how Unity Editor should be executed.</param>
/// <example>
/// <code>
/// var unityEditor = FindUnityEditor(2018, 3) ?? throw new Exception("Cannot find Unity Editor 2018.3.");
///
/// UnityEditor(
/// unityEditor.Path,
/// new UnityEditorArguments
/// {
/// ProjectPath = "A:/UnityProject",
/// BuildWindowsPlayer = "A:/Build/game.exe",
/// LogFile = "A:/Build/unity.log",
/// },
/// new UnityEditorSettings
/// {
/// RealTimeLog = true,
/// });
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build")]
public static void UnityEditor(this ICakeContext context,
FilePath unityEditorPath, UnityEditorArguments arguments, UnityEditorSettings settings) =>
new UnityEditor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log)
.Run(unityEditorPath, arguments, settings);

/// <summary>
/// Executes Unity Editor via command-line interface.
/// </summary>
/// <param name="unityEditor">Unity Editor descriptor provided by a FindUnityEditor method.</param>
/// <param name="arguments">Unity Editor command-line arguments.</param>
/// <param name="settings">Optional settings which affect how Unity Editor should be executed.</param>
/// <example>
/// <code>
/// UnityEditor(
/// FindUnityEditor(2018, 3) ?? throw new Exception("Cannot find Unity Editor 2018.3."),
/// new UnityEditorArguments
/// {
/// ProjectPath = "A:/UnityProject",
/// BuildWindowsPlayer = "A:/Build/game.exe",
/// LogFile = "A:/Build/unity.log",
/// },
/// new UnityEditorSettings
/// {
/// RealTimeLog = true,
/// });
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build")]
public static void UnityEditor(this ICakeContext context,
UnityEditorDescriptor unityEditor, UnityEditorArguments arguments, UnityEditorSettings settings = null) =>
new UnityEditor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log)
.Run(unityEditor, arguments, settings ?? new UnityEditorSettings());

/// <summary>
/// <para>Executes Unity Editor via command-line interface.</para>
/// <para>Determines Unity Editor location automatically by specified version.</para>
/// </summary>
/// <param name="versionYear">Year part of Unity version aka major version.</param>
/// <param name="versionStream">Stream part of Unity version aka minor version.</param>
/// <param name="arguments">Unity Editor command-line arguments.</param>
/// <param name="settings">Optional settings which affect how Unity Editor should be executed.</param>
/// <example>
/// <code>
/// UnityEditor(
/// 2018, 3,
/// new UnityEditorArguments
/// {
/// ProjectPath = "A:/UnityProject",
/// BuildWindowsPlayer = "A:/Build/game.exe",
/// LogFile = "A:/Build/unity.log",
/// },
/// new UnityEditorSettings
/// {
/// RealTimeLog = true,
/// });
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build")]
public static void UnityEditor(this ICakeContext context,
int versionYear, int versionStream, UnityEditorArguments arguments, UnityEditorSettings settings = null) =>
new UnityEditor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log)
.Run(unityEditorPath, arguments);
.Run(
context.FindUnityEditor(versionYear, versionStream)
?? throw new Exception($"Failed to locate Unity Editor {versionYear}.{versionStream}. Try to specify it's path explicitly."),
arguments,
settings ?? new UnityEditorSettings());

/// <summary>
/// <para>Executes Unity Editor via command-line interface.</para>
/// <para>Determines Unity Editor location automatically by specified version.</para>
/// </summary>
/// <param name="versionYear">Year part of Unity version aka major version.</param>
/// <param name="arguments">Unity Editor command-line arguments.</param>
/// <param name="settings">Optional settings which affect how Unity Editor should be executed.</param>
/// <example>
/// <code>
/// UnityEditor(
/// 2018,
/// new UnityEditorArguments
/// {
/// ProjectPath = "A:/UnityProject",
/// BuildWindowsPlayer = "A:/Build/game.exe",
/// LogFile = "A:/Build/unity.log",
/// },
/// new UnityEditorSettings
/// {
/// RealTimeLog = true,
/// });
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build")]
public static void UnityEditor(this ICakeContext context,
int versionYear, UnityEditorArguments arguments, UnityEditorSettings settings = null) =>
new UnityEditor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log)
.Run(
context.FindUnityEditor(versionYear)
?? throw new Exception($"Failed to locate Unity Editor {versionYear}. Try to specify it's path explicitly."),
arguments,
settings ?? new UnityEditorSettings());

/// <summary>
/// <para>Executes Unity Editor via command-line interface.</para>
/// <para>Determines location of latest available Unity Editor automatically.</para>
/// </summary>
/// <param name="arguments">Unity Editor command-line arguments.</param>
/// <param name="settings">Optional settings which affect how Unity Editor should be executed.</param>
/// <example>
/// <code>
/// UnityEditor(
/// new UnityEditorArguments
/// {
/// ProjectPath = "A:/UnityProject",
/// BuildWindowsPlayer = "A:/Build/game.exe",
/// LogFile = "A:/Build/unity.log",
/// },
/// new UnityEditorSettings
/// {
/// RealTimeLog = true,
/// });
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("Build")]
public static void UnityEditor(this ICakeContext context,
UnityEditorArguments arguments, UnityEditorSettings settings = null) =>
new UnityEditor(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Log)
.Run(
context.FindUnityEditor()
?? throw new Exception("Failed to locate Unity Editor. Try to specify it's path explicitly."),
arguments,
settings ?? new UnityEditorSettings());



/// <summary>
/// Locates installed Unity Editor with latest version.
Expand Down
Loading

0 comments on commit 0645b4c

Please sign in to comment.