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

Commit

Permalink
Modular codegen first pass (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Brynes authored Sep 9, 2019
1 parent ed70551 commit 677cab9
Show file tree
Hide file tree
Showing 74 changed files with 325 additions and 185 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
### Internal

- Added test coverage for `WorkerType` attribute and its interplay with `[Require]` fields in the `test-project`. [#1147](https://github.com/spatialos/gdk-for-unity/pull/1147)
- Refactored internals of code generation for modular codegen. [#1151](https://github.com/spatialos/gdk-for-unity/pull/1151).
- Use `dotnet new` to generate a skeleton project then link in the various modules from each package.
- This project is created in the `build/codegen` directory and is then executed to actually generate the code.

## `0.2.8` - 2019-09-02

Expand Down
5 changes: 0 additions & 5 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ PROJECT_DIR="$(pwd)"
mkdir -p "${PROJECT_DIR}/logs/"

CODE_GEN_LIB_TEST_RESULTS_FILE="${PROJECT_DIR}/logs/code-gen-lib-test-results.xml"
CODE_GENERATOR_TEST_RESULTS_FILE="${PROJECT_DIR}/logs/code-generator-test-results.xml"
EDITMODE_TEST_RESULTS_FILE="${PROJECT_DIR}/logs/editmode-test-results.xml"
PLAYMODE_TEST_RESULTS_FILE="${PROJECT_DIR}/logs/playmode-test-results.xml"
TEST_PROJECT_EDITMODE_TEST_RESULTS_FILE="${PROJECT_DIR}/logs/test-project-editmode-test-results.xml"
Expand All @@ -26,10 +25,6 @@ dotnet test \
--logger:"nunit;LogFilePath=${CODE_GEN_LIB_TEST_RESULTS_FILE}" \
workers/unity/Packages/io.improbable.gdk.tools/.CodeGenerator/CodeGeneration/CodeGeneration.csproj

dotnet test \
--logger:"nunit;LogFilePath=${CODE_GENERATOR_TEST_RESULTS_FILE}" \
workers/unity/Packages/io.improbable.gdk.tools/.CodeGenerator/GdkCodeGenerator/GdkCodeGenerator.csproj

echo "--- Testing Unity: Editmode :writing_hand:"

pushd "workers/unity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class PartialDatabase
{
public static bool TryGetPartial(string typeName, out string content)
{
var resourceName = "GdkCodeGenerator.Partials." + typeName;
var resourceName = "CodeGen." + typeName;
content = null;

var assembly = Assembly.GetExecutingAssembly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void Launch(bool shouldConnectLocally, string runtimeIp)
// Ensure an android device/emulator is present
if (RedirectedProcess.Command(adbPath)
.InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
.WithArgs("get-state").Run() != 0)
.WithArgs("get-state").Run().ExitCode != 0)
{
Debug.LogError("No Android device/emulator detected.");
return;
Expand All @@ -45,7 +45,7 @@ public static void Launch(bool shouldConnectLocally, string runtimeIp)
// Install apk on connected phone / emulator
if (RedirectedProcess.Command(adbPath)
.InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
.WithArgs("install", "-r", $"\"{apkPath}\"").Run() != 0)
.WithArgs("install", "-r", $"\"{apkPath}\"").Run().ExitCode != 0)
{
Debug.LogError(
"Failed to install the apk on the device/emulator. If the application is already installed on your device/emulator, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static class iOSLaunchUtils
private static readonly Regex nameRegex = new Regex("^(.+) \\[");
private static readonly Regex simulatorUIDRegex = new Regex("\\[([a-zA-Z0-9\\-]+)\\] \\(Simulator\\)$");
private static readonly Regex deviceUIDRegex = new Regex("\\[([a-zA-Z0-9\\-]+)\\]$");

public static Dictionary<string, string> RetrieveAvailableiOSSimulators()
{
var availableSimulators = new Dictionary<string, string>();

// Check if we have a physical device connected
var exitCode = RedirectedProcess.Command("instruments")
var result = RedirectedProcess.Command("instruments")
.WithArgs("-s", "devices")
.AddOutputProcessing(message =>
{
Expand All @@ -44,7 +44,7 @@ public static Dictionary<string, string> RetrieveAvailableiOSSimulators()
.RedirectOutputOptions(OutputRedirectBehaviour.None)
.Run();

if (exitCode != 0)
if (result.ExitCode != 0)
{
Debug.LogError("Failed to find iOS Simulators. Make sure you have the Command line tools for XCode (https://developer.apple.com/download/more/) installed and check the logs.");
}
Expand All @@ -55,7 +55,7 @@ public static Dictionary<string, string> RetrieveAvailableiOSSimulators()
public static Dictionary<string, string> RetrieveAvailableiOSDevices()
{
var availableDevices = new Dictionary<string, string>();
var exitCode = RedirectedProcess.Command("instruments")
var result = RedirectedProcess.Command("instruments")
.WithArgs("-s", "devices")
.AddOutputProcessing(message =>
{
Expand All @@ -68,14 +68,14 @@ public static Dictionary<string, string> RetrieveAvailableiOSDevices()
.RedirectOutputOptions(OutputRedirectBehaviour.None)
.Run();

if (exitCode != 0)
if (result.ExitCode != 0)
{
Debug.LogError("Failed to find connected iOS devices. Make sure you have the Command line tools for XCode (https://developer.apple.com/download/more/) installed and check the logs.");
}

return availableDevices;
}

public static void Build(string developmentTeamId)
{
try
Expand Down Expand Up @@ -105,10 +105,10 @@ public static void Build(string developmentTeamId)
EditorUtility.ClearProgressBar();
}
}

public static void Launch(bool shouldConnectLocally, string deviceId, string runtimeIp, bool useSimulator)
{
try
try
{
EditorUtility.DisplayProgressBar("Preparing your Mobile Client", "Preparing launch arguments", 0.0f);

Expand All @@ -127,15 +127,16 @@ public static void Launch(bool shouldConnectLocally, string deviceId, string run
Debug.LogError($"Was unable to read and modify {xcTestRunPath}.");
return;
}

if (useSimulator)
{
EditorUtility.DisplayProgressBar("Launching Mobile Client", "Start iOS Simulator", 0.5f);

// Start simulator
if (RedirectedProcess.Command("xcrun")
.WithArgs("instruments", "-w", deviceId, "-t", "Blank")
.Run() != 0)
.Run()
.ExitCode != 0)
{
Debug.LogError("Was unable to start iOS Simulator.");
return;
Expand All @@ -160,11 +161,11 @@ public static void Launch(bool shouldConnectLocally, string deviceId, string run
{
Directory.Delete(directory, true);
}

EditorUtility.ClearProgressBar();
}
}

private static bool TryBuildXCodeProject(string developmentTeamId)
{
return RedirectedProcess.Command("xcodebuild")
Expand All @@ -174,7 +175,8 @@ private static bool TryBuildXCodeProject(string developmentTeamId)
"-scheme", "Unity-iPhone",
$"DEVELOPMENT_TEAM={developmentTeamId}",
"-allowProvisioningUpdates")
.Run() == 0;
.Run()
.ExitCode == 0;
}

private static bool TryLaunchApplication(string deviceId, string filePath)
Expand Down Expand Up @@ -204,17 +206,17 @@ private static bool TryGetXCTestRunPath(bool useSimulator, out string xctestrunP
xctestrunPath = string.Empty;
return false;
}

var files = Directory.GetFiles(DerivedDataPath, "*.xctestrun", SearchOption.AllDirectories);
xctestrunPath = useSimulator
? files.FirstOrDefault(file => file.Contains("iphonesimulator"))
? files.FirstOrDefault(file => file.Contains("iphonesimulator"))
: files.FirstOrDefault(file => file.Contains("iphoneos"));

return !string.IsNullOrEmpty(xctestrunPath);
}

private static bool TryModifyEnvironmentVariables(string filePath, string arguments)
{
{
/*
* How to add SpatialOS arguments to the game as iOS environment variables
* The xctestrun file contains the launch arguments for your game
Expand All @@ -233,7 +235,7 @@ private static bool TryModifyEnvironmentVariables(string filePath, string argume
* <string>+environment local +receptionistHost 192.168.0.10 </string>
* </dict>
*/

try
{
var doc = new XmlDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Improbable Worlds Ltd.",
"classifications": [ "SpatialOS", "GDK for Unity" ],
"identity": "Improbable.Gdk.CodeGenerator",
"name": "SpatialOS GDK for Unity CodeGenerator template",
"shortName": "gdk-for-unity-codegen",
"tags": {
"language": "C#",
"type": "item"
},
"symbols": {
"code-gen-lib-path": {
"type": "parameter",
"replaces": "{code-gen-lib-path}",
"datatype": "text",
"isRequired": true,
"description": "The path to the CodeGeneration base library."
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<StartupObject>Improbable.Gdk.CodeGenerator.CodeGenerator</StartupObject>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Generated\**" />
<EmbeddedResource Remove="Generated\**" />
<None Remove="Generated\**" />
<Compile Remove="dependencies\**" />
<EmbeddedResource Remove="dependencies\**" />
<None Remove="dependencies\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Mono.Options" Version="5.3.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.CodeDom" Version="4.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="{code-gen-lib-path}" />
</ItemGroup>
<UsingTask TaskName="Improbable.TextTemplating.TransformAllTask" AssemblyFile="dependencies/Improbable.TextTemplating/Improbable.TextTemplating.dll" />
<Target Name="Code Template Generation" BeforeTargets="BeforeBuild">
<TransformAllTask InputFiles="@(T4Files)" ProjectDirectory="$(MSBuildProjectDirectory)" Imports="Improbable.Gdk.CodeGeneration.Jobs;Improbable.Gdk.CodeGeneration.Utils" ClassNameSpace="Improbable.Gdk.CodeGenerator">
<Output TaskParameter="OutputFiles" PropertyName="GeneratedFiles" />
</TransformAllTask>
<ItemGroup>
<Compile Include="$(GeneratedFiles)" />
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2015
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GdkCodeGenerator", "GdkCodeGenerator\GdkCodeGenerator.csproj", "{0E99E545-DB2F-4A39-B428-471858BC6010}"
ProjectSection(ProjectDependencies) = postProject
{69CD28E2-1217-47A9-BFFE-6D82701C4839} = {69CD28E2-1217-47A9-BFFE-6D82701C4839}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.TextTemplating", "Mono.TextTemplating\Mono.TextTemplating.csproj", "{79A38ECA-045D-4C5A-A180-E3E0B37ADFB9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Improbable.TextTemplating", "Improbable.TextTemplating\Improbable.TextTemplating.csproj", "{69CD28E2-1217-47A9-BFFE-6D82701C4839}"
Expand All @@ -20,10 +15,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0E99E545-DB2F-4A39-B428-471858BC6010}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E99E545-DB2F-4A39-B428-471858BC6010}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E99E545-DB2F-4A39-B428-471858BC6010}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E99E545-DB2F-4A39-B428-471858BC6010}.Release|Any CPU.Build.0 = Release|Any CPU
{79A38ECA-045D-4C5A-A180-E3E0B37ADFB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79A38ECA-045D-4C5A-A180-E3E0B37ADFB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79A38ECA-045D-4C5A-A180-E3E0B37ADFB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

This file was deleted.

Binary file not shown.
Loading

0 comments on commit 677cab9

Please sign in to comment.