Esempio n. 1
0
 public void PopulateFields(DetailsStore store)
 {
     FieldDetails = raw.Fields
                    .Select(field => new UnityFieldDetails(field, store))
                    .ToList()
                    .AsReadOnly();
 }
        public UnityFieldDetails(Field field, DetailsStore store)
        {
            PascalCaseName = Formatting.SnakeCaseToPascalCase(field.Identifier.Name);
            CamelCaseName  = Formatting.PascalCaseToCamelCase(PascalCaseName);
            FieldNumber    = field.FieldId;

            IsBlittable = store.BlittableMap.Contains(field.Identifier);

            if (field.Option != null)
            {
                CanBeEmpty = true;
                fieldType  = new OptionFieldType(field.Option.InnerType, store);
            }
            else if (field.List != null)
            {
                CanBeEmpty = true;
                fieldType  = new ListFieldType(field.List.InnerType, store);
            }
            else if (field.Map != null)
            {
                CanBeEmpty = true;
                fieldType  = new MapFieldType(field.Map.KeyType, field.Map.ValueType, store);
            }
            else
            {
                var singularType = field.Singular.Type;
                fieldType = new SingularFieldType(singularType, store);
            }
        }
Esempio n. 3
0
 // TODO: This can probably be reworked with the inner type concept.
 public ContainedType(Field.InnerType innerType, DetailsStore store)
 {
     if (innerType.Primitive != null)
     {
         category = ContainedTypeCategory.Primitive;
         Type     = CommonDetailsUtils.GetCapitalisedFqnTypename(innerType.Primitive);
         rawType  = innerType.Primitive;
     }
     else if (innerType.UserType != null)
     {
         category = ContainedTypeCategory.UserDefined;
         Type     = CommonDetailsUtils.GetCapitalisedFqnTypename(innerType.UserType.QualifiedName);
         rawType  = innerType.UserType.QualifiedName;
     }
     else if (innerType.EnumType != null)
     {
         category = ContainedTypeCategory.Enum;
         Type     = CommonDetailsUtils.GetCapitalisedFqnTypename(innerType.EnumType.QualifiedName);
         rawType  = innerType.EnumType.QualifiedName;
     }
     else
     {
         throw new ArgumentException("Malformed inner type.");
     }
 }
Esempio n. 4
0
        public UnityFieldDetails(FieldDefinition field, DetailsStore store)
        {
            PascalCaseName = Formatting.SnakeCaseToPascalCase(field.Name);
            CamelCaseName  = Formatting.PascalCaseToCamelCase(PascalCaseName);
            FieldNumber    = field.FieldId;

            IsBlittable = store.CheckBlittable(field);

            if (field.OptionType != null)
            {
                CanBeEmpty = true;
                fieldType  = new OptionFieldType(field.OptionType.InnerType, store);
            }
            else if (field.ListType != null)
            {
                CanBeEmpty = true;
                fieldType  = new ListFieldType(field.ListType.InnerType, store);
            }
            else if (field.MapType != null)
            {
                CanBeEmpty = true;
                fieldType  = new MapFieldType(field.MapType.KeyType, field.MapType.ValueType, store);
            }
            else
            {
                var singularType = field.SingularType.Type;
                fieldType = new SingularFieldType(singularType, store);
            }
        }
Esempio n. 5
0
        public int Run()
        {
            if (options.ShouldShowHelp)
            {
                ShowHelpMessage();
                return(0);
            }

            if (!ValidateOptions())
            {
                ShowHelpMessage();
                return(1);
            }

            var bundlePath          = GenerateBundle();
            var schemaBundle        = SchemaBundle.FromJson(File.ReadAllText(bundlePath));
            var store               = new DetailsStore(schemaBundle);
            var workerGenerationJob = new WorkerGenerationJob(options.NativeOutputDirectory, options, fileSystem);
            var singleJob           = new SingleGenerationJob(options.NativeOutputDirectory, store, fileSystem);

            var runner = new JobRunner(fileSystem);

            runner.Run(singleJob, workerGenerationJob);
            return(0);
        }
        public WorkerGenerationJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore) : base(baseOutputDir, fileSystem, detailsStore)
        {
            workerTypesToGenerate = ExtractWorkerTypes(CodeGeneratorOptions.Instance.WorkerJsonDirectory);

            OutputFiles.Add(Path.Combine(relativeEditorPath, workerFileName));
            OutputFiles.Add(Path.Combine(relativeEditorPath, workerListFileName));
            OutputFiles.Add(Path.Combine(relativeOutputPath, buildSystemFileName));
        }
Esempio n. 7
0
 public void PopulateFields(DetailsStore store)
 {
     if (raw.Data != null)
     {
         FieldDetails = store.Types[CommonDetailsUtils.CreateIdentifier(raw.Data.QualifiedName)].FieldDetails;
     }
     else
     {
         FieldDetails = raw.Fields
                        .Select(field => new UnityFieldDetails(field, store))
                        .ToList()
                        .AsReadOnly();
     }
 }
 public void PopulateFields(DetailsStore store)
 {
     if (!string.IsNullOrEmpty(raw.DataDefinition))
     {
         FieldDetails = store.Types[raw.DataDefinition].FieldDetails;
     }
     else
     {
         FieldDetails = raw.Fields
                        .Select(field => new UnityFieldDetails(field, store))
                        .ToList()
                        .AsReadOnly();
     }
 }
Esempio n. 9
0
        public void PopulateChildren(DetailsStore store)
        {
            var children = store.GetNestedTypes(Identifier);

            ChildTypes = store.Types
                         .Where(kv => children.Contains(kv.Key))
                         .Select(kv => kv.Value)
                         .ToList()
                         .AsReadOnly();

            ChildEnums = store.Enums
                         .Where(kv => children.Contains(kv.Key))
                         .Select(kv => kv.Value)
                         .ToList()
                         .AsReadOnly();
        }
        public int Run()
        {
            if (options.ShouldShowHelp)
            {
                ShowHelpMessage();
                return(0);
            }

            if (!ValidateOptions())
            {
                ShowHelpMessage();
                return(1);
            }

            var bundlePath   = GenerateBundle();
            var schemaBundle = SchemaBundle.LoadBundle(File.ReadAllText(bundlePath));
            var fileTree     = new FileTree(options.SchemaInputDirs);
            var store        = new DetailsStore(schemaBundle, options.SerializationOverrides, fileTree);

            var jobs = AppDomain.CurrentDomain
                       .GetAssemblies()
                       .SelectMany(assembly =>
            {
                try
                {
                    return(assembly.GetTypes());
                }
                catch (ReflectionTypeLoadException e)
                {
                    Console.Error.WriteLine($"Failed to load assembly {assembly.FullName} with error {e}");
                    return(Enumerable.Empty <Type>());
                }
            })
                       .Where(type => typeof(CodegenJob).IsAssignableFrom(type))
                       .Where(type => !type.IsAbstract)
                       .Where(type => !type.GetCustomAttributes(typeof(IgnoreCodegenJobAttribute)).Any())
                       .Select(type =>
                               (CodegenJob)Activator.CreateInstance(type, options.NativeOutputDirectory, fileSystem, store))
                       .ToArray();

            new JobRunner(fileSystem).Run(jobs);
            return(0);
        }
Esempio n. 11
0
        public UnityComponentDetails(ComponentDefinitionRaw componentDefinitionRaw, DetailsStore store)
        {
            ComponentName = componentDefinitionRaw.Identifier.Name;
            ComponentId   = componentDefinitionRaw.ComponentId;
            IsBlittable   = store.BlittableMap.Contains(componentDefinitionRaw.Identifier);

            CommandDetails = componentDefinitionRaw.Commands
                             .Select(command => new UnityCommandDetails(command))
                             .ToList()
                             .AsReadOnly();

            EventDetails = componentDefinitionRaw.Events
                           .Select(ev => new UnityEventDetails(ev))
                           .ToList()
                           .AsReadOnly();

            Identifier = componentDefinitionRaw.Identifier;
            raw        = componentDefinitionRaw;
        }
Esempio n. 12
0
        public WorkerGenerationJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore)
            : base(baseOutputDir, fileSystem, detailsStore)
        {
            const string jobName = nameof(WorkerGenerationJob);

            logger.Info($"Initialising {jobName}.");

            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.Info($"Finished initialising {jobName}.");
        }
Esempio n. 13
0
        public WorkerGenerationJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore, bool force)
            : base(baseOutputDir, fileSystem, detailsStore, force)
        {
            const string jobName = nameof(WorkerGenerationJob);

            Logger.Trace($"Initialising {jobName}.");

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

            Logger.Trace($"Adding job target {WorkerFileName}.");
            AddJobTarget(Path.Combine(relativeEditorPath, WorkerFileName),
                         () => UnityWorkerMenuGenerator.Generate(workerTypesToGenerate));

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

            Logger.Trace($"Adding job target for {WorkerListFileName}.");
            AddJobTarget(Path.Combine(relativeOutputPath, WorkerListFileName),
                         () => string.Join(Environment.NewLine, workerTypesToGenerate));

            Logger.Trace($"Finished initialising {jobName}.");
        }
Esempio n. 14
0
 public FieldTypeHandler(DetailsStore detailsStore)
 {
     this.detailsStore = detailsStore;
 }
Esempio n. 15
0
 public SingularFieldType(TypeReference innerType, DetailsStore store)
 {
     containedType = new ContainedType(innerType);
 }
Esempio n. 16
0
 public MapFieldType(TypeReference keyType, TypeReference valueType, DetailsStore store)
 {
     this.keyType   = new ContainedType(keyType);
     this.valueType = new ContainedType(valueType);
 }
Esempio n. 17
0
 public OptionFieldType(TypeReference innerType, DetailsStore store)
 {
     containedType = new ContainedType(innerType);
 }
Esempio n. 18
0
 public OptionFieldType(Field.InnerType innerType, DetailsStore store)
 {
     containedType = new ContainedType(innerType, store);
 }
Esempio n. 19
0
 public TestCodegenJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore, bool force)
     : base(baseOutputDir, fileSystem, detailsStore, force)
 {
     AddOutputFile(relativeOutputPath);
     AddOutputFile(relativeTemplateOutputPath);
 }
Esempio n. 20
0
        public int Run()
        {
            if (options.ShouldShowHelp)
            {
                ShowHelpMessage();
                return(0);
            }

            var optionErrors = options.GetValidationErrors().ToList();

            foreach (var optionError in optionErrors)
            {
                Console.WriteLine(optionError);
            }

            if (optionErrors.Any())
            {
                ShowHelpMessage();
                return(1);
            }

            logger.Info("Starting code generation.");

            logger.Info("Gathering schema information.");
            var bundlePath = GenerateBundle();

            logger.Info("Loading schema bundle from json.");
            var schemaBundle = SchemaBundle.LoadBundle(File.ReadAllText(bundlePath));

            logger.Info("Setting up schema file tree.");
            var fileTree = new FileTree(options.SchemaInputDirs);

            logger.Info("Initialising DetailsStore.");
            var store = new DetailsStore(schemaBundle, options.SerializationOverrides, fileTree);

            logger.Info("Setting up code generation jobs.");
            var jobs = AppDomain.CurrentDomain
                       .GetAssemblies()
                       .SelectMany(assembly =>
            {
                try
                {
                    return(assembly.GetTypes());
                }
                catch (ReflectionTypeLoadException e)
                {
                    logger.Error(e, $"Failed to load assembly {assembly.FullName}.");
                    return(Enumerable.Empty <Type>());
                }
            })
                       .Where(type => typeof(CodegenJob).IsAssignableFrom(type))
                       .Where(type => !type.IsAbstract)
                       .Where(type => !type.GetCustomAttributes(typeof(IgnoreCodegenJobAttribute)).Any())
                       .Select(type =>
            {
                logger.Info($"Creating instance of {type}.");
                return((CodegenJob)Activator.CreateInstance(type, options.NativeOutputDirectory, fileSystem, store, options.Force));
            })
                       .ToArray();

            logger.Info("Calling JobRunner.");
            new JobRunner(fileSystem).Run(jobs);

            logger.Info("Finished code generation.");
            return(0);
        }
Esempio n. 21
0
 public SingularFieldType(Field.InnerType innerType, DetailsStore store)
 {
     containedType = new ContainedType(innerType, store);
 }
Esempio n. 22
0
 public MapFieldType(Field.InnerType keyType, Field.InnerType valueType, DetailsStore store)
 {
     this.keyType   = new ContainedType(keyType, store);
     this.valueType = new ContainedType(valueType, store);
 }
 public TestCodegenJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore) : base(
         baseOutputDir, fileSystem, detailsStore)
 {
     OutputFiles.Add(relativeOutputPath);
     OutputFiles.Add(relativeTemplateOutputPath);
 }
Esempio n. 24
0
 public ComponentVisualElementGenerator(DetailsStore detailsStore)
 {
     typeGenerator = new FieldTypeHandler(detailsStore);
 }
        public SingleGenerationJob(string outputDir, DetailsStore store, IFileSystem fileSystem) : base(
                outputDir, fileSystem)
        {
            InputFiles  = store.SchemaFiles.ToList();
            OutputFiles = new List <string>();

            var allNestedTypes = store.Types
                                 .SelectMany(kv => store.GetNestedTypes(kv.Key))
                                 .ToHashSet();

            typesToGenerate = store.Types
                              .Where(kv => !allNestedTypes.Contains(kv.Key))
                              .Select(kv => new GenerationTarget <UnityTypeDetails>(kv.Value, kv.Value.Package))
                              .ToList();

            enumsToGenerate = store.Enums
                              .Where(kv => !allNestedTypes.Contains(kv.Key))
                              .Select(kv => new GenerationTarget <UnityEnumDetails>(kv.Value, kv.Value.Package))
                              .ToList();

            componentsToGenerate = store.Components
                                   .Select(kv => new GenerationTarget <UnityComponentDetails>(kv.Value, kv.Value.Package))
                                   .ToList();

            foreach (var typeTarget in typesToGenerate)
            {
                var fileName = Path.ChangeExtension(typeTarget.Content.CapitalisedName, FileExtension);
                OutputFiles.Add(Path.Combine(typeTarget.OutputPath, fileName));
            }

            foreach (var componentTarget in componentsToGenerate)
            {
                var relativeOutputPath = componentTarget.OutputPath;
                var componentName      = componentTarget.Content.ComponentName;

                OutputFiles.Add(Path.Combine(relativeOutputPath, Path.ChangeExtension(componentTarget.Content.ComponentName, FileExtension)));

                if (componentTarget.Content.CommandDetails.Count > 0)
                {
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandPayloads", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandComponents", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandSenderReceiver", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}ReactiveCommandComponents", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandDiffDeserializer", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandDiffStorage", FileExtension)));
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}CommandMetaDataStorage", FileExtension)));
                }

                if (componentTarget.Content.EventDetails.Count > 0)
                {
                    OutputFiles.Add(Path.Combine(relativeOutputPath,
                                                 Path.ChangeExtension($"{componentName}Events", FileExtension)));
                }

                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}UpdateSender", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ReactiveHandlers", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}EcsViewManager", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ComponentDiffStorage", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ComponentDiffDeserializer", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ReactiveComponents", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}Providers", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ComponentReaderWriter", FileExtension)));
                OutputFiles.Add(Path.Combine(relativeOutputPath,
                                             Path.ChangeExtension($"{componentName}ViewStorage", FileExtension)));
            }

            foreach (var enumTarget in enumsToGenerate)
            {
                var fileName = Path.ChangeExtension(enumTarget.Content.TypeName, FileExtension);
                OutputFiles.Add(Path.Combine(enumTarget.OutputPath, fileName));
            }
        }
 public TypeVisualElementGenerator(DetailsStore detailsStore)
 {
     fieldTypeHandler = new FieldTypeHandler(detailsStore);
 }
Esempio n. 27
0
        public ComponentVisualElementJob(CodegenJobOptions options, IFileSystem fileSystem, DetailsStore detailsStore) : base(options.AsEditor(), fileSystem, detailsStore)
        {
            const string jobName = nameof(ComponentVisualElementJob);

            Logger.Trace($"Initialising {jobName}.");

            Logger.Trace($"Adding job target for {DebugAsmdefFileName}");
            AddJobTarget(Path.Combine(relativeOutputPath, DebugAsmdefFileName), () => DebugAssemblyGenerator.Generate());

            var componentsToGenerate = detailsStore.Components.Values.ToList();
            var componentGenerator   = new ComponentVisualElementGenerator(detailsStore);

            AddGenerators(relativeOutputPath, componentsToGenerate, component => ($"{component.Name}Renderer.cs", componentGenerator.Generate));
            Logger.Trace($"Added job targets for {componentsToGenerate.Count} components");

            // Types
            Logger.Trace("Gathering nested types.");
            var allNestedTypes = detailsStore.Types
                                 .SelectMany(kv => detailsStore.GetNestedTypes(kv.Key))
                                 .ToHashSet();

            Logger.Trace("Gathering types details.");
            var typesToGenerate = detailsStore.Types
                                  .Where(kv => !allNestedTypes.Contains(kv.Key))
                                  .Select(kv => kv.Value)
                                  .ToList();

            var typeGenerator = new TypeVisualElementGenerator(detailsStore);

            AddGenerators(relativeOutputPath, typesToGenerate, type => ($"{type.Name}Renderer.cs", typeGenerator.Generate));
            Logger.Trace($"Added job targets for {typesToGenerate.Count} types");
        }
        public UnityComponentDetails(string package, ComponentDefinition componentDefinitionRaw, DetailsStore store)
        {
            Package       = package;
            ComponentName = componentDefinitionRaw.Name;
            ComponentId   = componentDefinitionRaw.ComponentId;
            IsBlittable   = store.BlittableSet.Contains(componentDefinitionRaw.QualifiedName);

            CommandDetails = componentDefinitionRaw.Commands
                             .Select(command => new UnityCommandDetails(command))
                             .ToList()
                             .AsReadOnly();

            EventDetails = componentDefinitionRaw.Events
                           .Select(ev => new UnityEventDetails(ev))
                           .ToList()
                           .AsReadOnly();

            raw = componentDefinitionRaw;
        }
Esempio n. 29
0
 public TestCodegenJob(string baseOutputDir, IFileSystem fileSystem, DetailsStore detailsStore, bool force)
     : base(baseOutputDir, fileSystem, detailsStore, force)
 {
     AddJobTarget(relativeOutputPath, () => TestContent);
     AddJobTarget(relativeTemplateOutputPath, () => ModularCodegenTestGenerator.Generate());
 }