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 all 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,93 @@
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.Annotate($@"MenuItem(EditorConfig.ParentMenu + ""/"" + LocalMenu + ""/{workerType}"", false, EditorConfig.MenuOffset + {i})")
.Method($"public static void BuildLocal{workerType}()", () => new[]
{
$@"MenuBuildLocal(new[] {{ {workerTypeString} }});"
});

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

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

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

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

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

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

buildWorkerMenu.Method("private static void MenuCleanAll()", () => 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.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Improbable.Gdk.CodeGeneration.CodeWriter.Scopes;

namespace CodeGenerationLib.CodeWriter.Scopes
Expand Down Expand Up @@ -35,5 +36,10 @@ public void Method(string declaration, Action<MethodBlock> populate)
{
ParentBlock.Add(new MethodBlock(declaration, populate, Annotation));
}

public void Method(string declaration, Func<IEnumerable<string>> populate)
{
ParentBlock.Add(new MethodBlock(declaration, populate, Annotation));
}
}
}