Example #1
0
        Type CompileGraph(CodeGenMode mode, out CompilationResult results)
        {
            results = default;
            RoslynEcsTranslator translator = (RoslynEcsTranslator)GraphModel.CreateTranslator();

            translator.AllowNoJobsFallback = false;

            // because of the hack in the translator constructor, override right after
            ((EcsStencil)Stencil).UseJobSystem = mode == CodeGenMode.Jobs || mode == CodeGenMode.JobsTracing;

            var compilationOptions = CompilationOptions.LiveEditing;

            if (mode == CodeGenMode.JobsTracing || mode == CodeGenMode.NoJobsTracing)
            {
                compilationOptions |= CompilationOptions.Tracing;
            }
            results = GraphModel.Compile(AssemblyType.Memory, translator,
                                         compilationOptions);

            var results2 = results;

            Assert.That(results?.status, Is.EqualTo(CompilationStatus.Succeeded),
                        () => $"Compilation failed, errors: {String.Join("\n", results2?.errors)}\r\n{FormatCode(results2)}");
            return(EcsStencil.LiveCompileGraph(GraphModel, results, includeVscriptingAssemblies: true));
        }
        Type CompileGraph(CodeGenMode mode)
        {
            RoslynEcsTranslator translator = (RoslynEcsTranslator)GraphModel.CreateTranslator();

            translator.AllowNoJobsFallback = false;

            // because of the hack in the translator constructor, override right after
            ((EcsStencil)Stencil).UseJobSystem = mode == CodeGenMode.Jobs;

            CompilationResult results = GraphModel.Compile(AssemblyType.Memory, translator,
                                                           CompilationOptions.LiveEditing);

            if (results?.sourceCode != null && results.sourceCode.Length != 0)
            {
                LogAssert.Expect(LogType.Log, new Regex("using.*"));
                Debug.Log(results.sourceCode[(int)SourceCodePhases.Initial]);
            }

            Assert.That(results?.status, Is.EqualTo(CompilationStatus.Succeeded),
                        () => $"Compilation failed, errors: {String.Join("\n", results?.errors)}");

            return(EcsStencil.LiveCompileGraph(GraphModel, results, includeVscriptingAssemblies: true));
        }