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

[UTY-2393] Port build system module to new CodeWriter #1242

Merged
merged 7 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- The `CodeGenerationLib` has been migrated to the new `CodeWriter`.
- Added support for defining namespaces, structs, classes, enums and methods in the new CodeWriter. [#1239](https://github.com/spatialos/gdk-for-unity/pull/1239)
- Ported test-project to new CodeWriter. [#1241](https://github.com/spatialos/gdk-for-unity/pull/1241)
- Ported build system module to new CodeWriter. [#1242](https://github.com/spatialos/gdk-for-unity/pull/1242)

## `0.3.2` - 2019-12-23

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Improbable.Gdk.CodeGenerator
{
public static class BuildSystemAssemblyGenerator
{
public static string Generate()
{
return @"{
""name"": ""Improbable.Gdk.Generated.BuildSystem"",
""references"": [
""Improbable.Gdk.BuildSystem"",
""Improbable.Gdk.Tools""
],
""includePlatforms"": [
""Editor""
],
""excludePlatforms"": [],
""allowUnsafeCode"": false
}
";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System.Collections.Generic;
using System.Linq;
using Improbable.Gdk.CodeGeneration.CodeWriter;

namespace Improbable.Gdk.CodeGenerator
{
public static class UnityWorkerMenuGenerator
{
public static string Generate(List<string> workerTypes)
{
return CodeWriter.Populate(cgw =>
{
cgw.UsingDirectives(
"System",
"Improbable.Gdk.BuildSystem",
"Improbable.Gdk.BuildSystem.Configuration",
"Improbable.Gdk.Tools",
"UnityEditor",
"UnityEngine"
);

cgw.Namespace("Improbable", ns =>
{
ns.Type("internal static class BuildWorkerMenu", buildWorkerMenu =>
{
buildWorkerMenu.Line(new[]
{
"private const string LocalMenu = \"Build for local\";",
"private const string CloudMenu = \"Build for cloud\";"
});

buildWorkerMenu.Initializer("private static readonly string[] AllWorkers = new string[]", () =>
{
return workerTypes.Select(workerType => $@"""{workerType}""");
});

for (var i = 0; i < workerTypes.Count; i++)
{
var workerType = workerTypes[i];
var workerTypeString = $@"""{workerType}""";

buildWorkerMenu.Method($"public static void BuildLocal{workerType}()", m =>
{
m.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + LocalMenu + ""/{workerType}"", false, EditorConfig.MenuOffset + {i})");
paulbalaji marked this conversation as resolved.
Show resolved Hide resolved
m.Line($@"MenuBuildLocal(new[] {{ {workerTypeString} }});");
});

buildWorkerMenu.Method($"public static void BuildCloud{workerType}()", m =>
{
m.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + CloudMenu + ""/{workerType}"", false, EditorConfig.MenuOffset + {i})");
m.Line($@"MenuBuildCloud(new[] {{ {workerTypeString} }});");
});
}

buildWorkerMenu.Method("public static void BuildLocalAll()", m =>
{
m.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + LocalMenu + ""/All workers"", false, EditorConfig.MenuOffset + {workerTypes.Count})");
m.Line("MenuBuildLocal(AllWorkers);");
});

buildWorkerMenu.Method("public static void BuildCloudAll()", m =>
{
m.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + CloudMenu + ""/All workers"", false, EditorConfig.MenuOffset + {workerTypes.Count})");
m.Line("MenuBuildCloud(AllWorkers);");
});

buildWorkerMenu.Method("public static void Clean()", m =>
{
m.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/Clean all workers"", false, EditorConfig.MenuOffset + {workerTypes.Count})");
m.Line("MenuCleanAll();");
});

buildWorkerMenu.Method("private static void MenuBuildLocal(string[] filteredWorkerTypes)", m =>
{
m.Line("WorkerBuilder.MenuBuild(BuildEnvironment.Local, filteredWorkerTypes);");
});

buildWorkerMenu.Method("private static void MenuBuildCloud(string[] filteredWorkerTypes)", m =>
{
m.Line("WorkerBuilder.MenuBuild(BuildEnvironment.Cloud, filteredWorkerTypes);");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading through this again - these seem mostly redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - could just call WorkerBuild.MenuBuild directly


buildWorkerMenu.Method("private static void MenuCleanAll()", m =>
paulbalaji marked this conversation as resolved.
Show resolved Hide resolved
{
m.Line(new[]
{
"WorkerBuilder.Clean();",
"Debug.Log(\"Clean completed\");"
});
});
});
});
}).Format();
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ public WorkerGenerationJob(string baseOutputDir, IFileSystem fileSystem, Details
protected override void RunImpl()
{
logger.Info($"Generating {WorkerFileName}.");
var unityWorkerMenuGenerator = new UnityWorkerMenuGenerator();
var workerCode = unityWorkerMenuGenerator.Generate(workerTypesToGenerate);
var workerCode = UnityWorkerMenuGenerator.Generate(workerTypesToGenerate);
AddContent(Path.Combine(relativeEditorPath, WorkerFileName), workerCode);

logger.Info($"Generating {BuildSystemFileName}.");
var buildSystemAssemblyGenerator = new BuildSystemAssemblyGenerator();
var assemblyCode = buildSystemAssemblyGenerator.Generate();
var assemblyCode = BuildSystemAssemblyGenerator.Generate();
AddContent(Path.Combine(relativeOutputPath, BuildSystemFileName), assemblyCode);

logger.Info($"Generating {WorkerListFileName}.");
Expand Down

This file was deleted.

This file was deleted.