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

[4/5] Port modules to new CodegenJob model #1276

Merged
merged 5 commits into from
Feb 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ public class Test
public TestCodegenJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore, bool force)
: base(baseOutputDir, fileSystem, detailsStore, force)
{
AddOutputFile(relativeOutputPath);
AddOutputFile(relativeTemplateOutputPath);
AddJobTarget(relativeOutputPath, () => TestContent);
AddJobTarget(relativeTemplateOutputPath, () => ModularCodegenTestGenerator.Generate());
}

protected override void RunImpl()
{
AddContent(relativeOutputPath, TestContent);
AddContent(relativeTemplateOutputPath, ModularCodegenTestGenerator.Generate().Format());
// base CodegenJob runs jobs
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Improbable.Gdk.CodeGenerator
{
public class WorkerGenerationJob : CodegenJob
{
private readonly List<string> workerTypesToGenerate;
private const string WorkerTypeFlag = "+workerType";
private const string WorkerFileName = "WorkerMenu.cs";
private const string WorkerListFileName = "WorkerMenu.txt";
Expand All @@ -25,33 +24,23 @@ public WorkerGenerationJob(string baseOutputDir, IFileSystem fileSystem, Details
const string jobName = nameof(WorkerGenerationJob);
Logger.Info($"Initialising {jobName}.");

workerTypesToGenerate = ExtractWorkerTypes(CodeGeneratorOptions.Instance.WorkerJsonDirectory);
var workerTypesToGenerate = ExtractWorkerTypes(CodeGeneratorOptions.Instance.WorkerJsonDirectory);

var outputFilePaths = new List<string>
{
Path.Combine(relativeEditorPath, WorkerFileName),
Path.Combine(relativeEditorPath, WorkerListFileName),
Path.Combine(relativeOutputPath, BuildSystemFileName)
};

AddOutputFiles(outputFilePaths);
Logger.Info($"Added {outputFilePaths.Count} job output files.");
Logger.Trace($"Adding job target {WorkerFileName}.");
AddJobTarget(Path.Combine(relativeEditorPath, WorkerFileName),
() => UnityWorkerMenuGenerator.Generate(workerTypesToGenerate));

Logger.Info($"Finished initialising {jobName}.");
}
Logger.Trace($"Adding job target for {BuildSystemFileName}.");
AddJobTarget(Path.Combine(relativeEditorPath, BuildSystemFileName),
() => BuildSystemAssemblyGenerator.Generate());

protected override void RunImpl()
{
Logger.Info($"Generating {WorkerFileName}.");
var workerCode = UnityWorkerMenuGenerator.Generate(workerTypesToGenerate).Format();
AddContent(Path.Combine(relativeEditorPath, WorkerFileName), workerCode);
Logger.Trace($"Adding job target for {WorkerListFileName}.");
AddJobTarget(Path.Combine(relativeOutputPath, WorkerListFileName),
() => string.Join(Environment.NewLine, workerTypesToGenerate));

Logger.Info($"Generating {BuildSystemFileName}.");
var assemblyCode = BuildSystemAssemblyGenerator.Generate();
AddContent(Path.Combine(relativeOutputPath, BuildSystemFileName), assemblyCode);
Logger.Info("Added 3 job targets.");
paulbalaji marked this conversation as resolved.
Show resolved Hide resolved

Logger.Info($"Generating {WorkerListFileName}.");
AddContent(Path.Combine(relativeEditorPath, WorkerListFileName), string.Join(Environment.NewLine, workerTypesToGenerate));
Logger.Info($"Finished initialising {jobName}.");
paulbalaji marked this conversation as resolved.
Show resolved Hide resolved
}

private List<string> ExtractWorkerTypes(string path)
Expand All @@ -61,7 +50,7 @@ private List<string> ExtractWorkerTypes(string path)
var workerTypes = new List<string>();

var fileNames = Directory.EnumerateFiles(path, "*.json").ToList();
Logger.Trace($"Found {fileNames.Count()} worker json files:\n - {string.Join("\n - ", fileNames)}");
Logger.Trace($"Found {fileNames.Count} worker json files:\n - {string.Join("\n - ", fileNames)}");

foreach (var fileName in fileNames)
{
Expand Down Expand Up @@ -97,5 +86,10 @@ private List<string> ExtractWorkerTypes(string path)
Logger.Info($"Found {workerTypes.Count} worker types:\n - {string.Join("\n - ", workerTypes)}");
paulbalaji marked this conversation as resolved.
Show resolved Hide resolved
return workerTypes;
}

protected override void RunImpl()
{
// base CodegenJob runs jobs
}
}
}
Loading