Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 741ba6a

Browse files
authored
Redirected process changes required for deployment launcher fixes (#888)
1 parent f54d7cd commit 741ba6a

File tree

8 files changed

+323
-135
lines changed

8 files changed

+323
-135
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
- `InterestTemplate` provides functionality to ergonomically add, replace and clear queries from an Interest component.
1515
- `InterestQuery` reduces boilerplate code required to construct interest queries.
1616
- `Constraint` contains static methods to easily create constraints for an interest query.
17+
- Added a `WithTimeout(TimeSpan timeout)` method to the `RedirectedProcess` class. This allows you to set a timeout for the underlying process execution.
18+
- Added a `Improbable.Gdk.Core.Collections.Result<T, E>` struct to represent a result which can either contain a value `T` or an error `E`.
1719

1820
### Changed
1921

2022
- The player lifecycle module now dynamically queries for PlayerCreator entities, and sends requests to a random one each time. This removes the reliance on a hardcoded PlayerCreator Entity ID.
2123
- Removed the `Type` suffix from player lifecycle schema types.
24+
- `RedirectedProcess.RunAsync()` now takes a `CancellationToken?` as a parameter. This token can be used to cancel the underlying process.
2225

2326
### Fixed
2427

2528
- Fixed an issue where player creation requests could retry infinitely without logging failure.
29+
- Fixed an issue where if you called `RedirectedProcess.Command(...)` in a non-main thread, it would throw an exception.
2630

2731
### Internal
2832

workers/unity/Packages/com.improbable.gdk.buildsystem/WorkerBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ private static void Zip(string zipAbsolutePath, string basePath, bool useCompres
274274
using (new ShowProgressBarScope($"Package {basePath}"))
275275
{
276276
RedirectedProcess.Command(Common.SpatialBinary)
277+
.InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
277278
.WithArgs("file", "zip", $"--output=\"{Path.GetFullPath(zipAbsolutePath)}\"",
278279
$"--basePath=\"{Path.GetFullPath(basePath)}\"", "\"**\"",
279280
$"--compression={useCompression}")
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
3+
namespace Improbable.Gdk.Core.Collections
4+
{
5+
/// <summary>
6+
/// A type to represent a result. Can either have a success value or an error, but not both.
7+
/// </summary>
8+
/// <typeparam name="T">The type of the success value.</typeparam>
9+
/// <typeparam name="E">The type of the error.</typeparam>
10+
public struct Result<T, E>
11+
{
12+
private T okValue;
13+
private E errorValue;
14+
15+
private bool isOkay;
16+
17+
/// <summary>
18+
/// True if the result contains a success, false otherwise.
19+
/// </summary>
20+
public bool IsOkay => isOkay;
21+
22+
/// <summary>
23+
/// True if the result contains an error, false otherwise.
24+
/// </summary>
25+
public bool IsError => !isOkay;
26+
27+
/// <summary>
28+
/// Creates a result which contains a success value.
29+
/// </summary>
30+
/// <param name="value">The value of the result.</param>
31+
/// <returns>The result object.</returns>
32+
public static Result<T, E> Ok(T value)
33+
{
34+
return new Result<T, E>
35+
{
36+
okValue = value,
37+
isOkay = true
38+
};
39+
}
40+
41+
/// <summary>
42+
/// Creates a result which contains an error.
43+
/// </summary>
44+
/// <param name="error">The value of the error.</param>
45+
/// <returns>The result object.</returns>
46+
public static Result<T, E> Error(E error)
47+
{
48+
return new Result<T, E>
49+
{
50+
errorValue = error,
51+
isOkay = false
52+
};
53+
}
54+
55+
/// <summary>
56+
/// Attempts to get the success value from the result.
57+
/// </summary>
58+
/// <returns>The success value of the result.</returns>
59+
/// <exception cref="InvalidOperationException">Thrown if the result contains an error.</exception>
60+
public T Unwrap()
61+
{
62+
if (!isOkay)
63+
{
64+
throw new InvalidOperationException("Cannot unwrap a result value which has an error.");
65+
}
66+
67+
return okValue;
68+
}
69+
70+
/// <summary>
71+
/// Attempts to get the error from the result.
72+
/// </summary>
73+
/// <returns>The error from the result.</returns>
74+
/// <exception cref="InvalidOperationException">Thrown if result contains a success value.</exception>
75+
public E UnwrapError()
76+
{
77+
if (isOkay)
78+
{
79+
throw new InvalidOperationException("Cannot unwrap a result error which has a value.");
80+
}
81+
82+
return errorValue;
83+
}
84+
}
85+
}

workers/unity/Packages/com.improbable.gdk.core/Collections/Result.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/unity/Packages/com.improbable.gdk.mobile/Editor/LaunchMenu.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ private static void LaunchMobileClient()
3939
}
4040

4141
// Ensure an android device/emulator is present
42-
if (RedirectedProcess.Command(adbPath).WithArgs("get-state").Run() != 0)
42+
if (RedirectedProcess.Command(adbPath)
43+
.InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
44+
.WithArgs("get-state").Run() != 0)
4345
{
4446
Debug.LogError("No Android device/emulator detected.");
4547
return;
4648
}
4749

4850
// Install apk on connected phone / emulator
49-
if (RedirectedProcess.Command(adbPath).WithArgs("install", "-r", $"\"{apkPath}\"").Run() != 0)
51+
if (RedirectedProcess.Command(adbPath)
52+
.InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
53+
.WithArgs("install", "-r", $"\"{apkPath}\"").Run() != 0)
5054
{
5155
Debug.LogError("Failed to install the apk on the device/emulator. If the application is already installed on your device/emulator, " +
5256
"try uninstalling it before launching the mobile client.");
@@ -69,6 +73,7 @@ private static void LaunchMobileClient()
6973
RedirectedProcess.Command(adbPath)
7074
.WithArgs("shell", "am", "start", "-S", "-n", $"{bundleId}/com.unity3d.player.UnityPlayerActivity",
7175
"-e", "\"arguments\"", $"\\\"{arguments.ToString()}\\\"")
76+
.InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
7277
.Run();
7378

7479
EditorUtility.DisplayProgressBar("Launching Mobile Client", "Done", 1.0f);

workers/unity/Packages/com.improbable.gdk.tools/DownloadCoreSdk.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ private static DownloadResult Download()
130130

131131
using (new ShowProgressBarScope($"Installing SpatialOS libraries, version {Common.CoreSdkVersion}..."))
132132
{
133-
exitCode = RedirectedProcess.Command(Common.DotNetBinary).WithArgs(ConstructArguments()).Run();
133+
exitCode = RedirectedProcess.Command(Common.DotNetBinary)
134+
.InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
135+
.WithArgs(ConstructArguments())
136+
.Run();
134137
if (exitCode != 0)
135138
{
136139
Debug.LogError($"Failed to download SpatialOS Core Sdk version {Common.CoreSdkVersion}. You can use SpatialOS -> Download CoreSDK (force) to retry this.");

workers/unity/Packages/com.improbable.gdk.tools/GenerateCode.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ private static void Generate()
104104
break;
105105
case RuntimePlatform.LinuxEditor:
106106
case RuntimePlatform.OSXEditor:
107-
// Ensure the schema compiler is executable.
108-
var _ = RedirectedProcess.Command("chmod").WithArgs("+x", $"\"{schemaCompilerPath}\"").Run();
107+
RedirectedProcess.Command("chmod")
108+
.WithArgs("+x", $"\"{schemaCompilerPath}\"")
109+
.InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
110+
.Run();
109111
break;
110112
default:
111113
throw new PlatformNotSupportedException(

0 commit comments

Comments
 (0)