Example #1
0
 private void QueuePendingAssemblies()
 {
     if (this.pendingAssemblies.Count != 0)
     {
         List <ScriptAssembly> list = null;
         foreach (ScriptAssembly current in this.pendingAssemblies)
         {
             bool             flag = true;
             ScriptAssembly[] scriptAssemblyReferences = current.ScriptAssemblyReferences;
             for (int i = 0; i < scriptAssemblyReferences.Length; i++)
             {
                 ScriptAssembly key = scriptAssemblyReferences[i];
                 if (!this.processedAssemblies.ContainsKey(key))
                 {
                     flag = false;
                     break;
                 }
             }
             if (flag)
             {
                 if (list == null)
                 {
                     list = new List <ScriptAssembly>();
                 }
                 list.Add(current);
             }
         }
         if (list != null)
         {
             bool buildingForEditor = (this.options & EditorScriptCompilationOptions.BuildingForEditor) == EditorScriptCompilationOptions.BuildingForEditor;
             foreach (ScriptAssembly current2 in list)
             {
                 this.pendingAssemblies.Remove(current2);
                 MonoIsland         island             = current2.ToMonoIsland(this.options, this.buildOutputDirectory);
                 ScriptCompilerBase scriptCompilerBase = ScriptCompilers.CreateCompilerInstance(island, buildingForEditor, island._target, current2.RunUpdater);
                 this.compilerTasks.Add(current2, scriptCompilerBase);
                 scriptCompilerBase.BeginCompiling();
                 if (this.OnCompilationStarted != null)
                 {
                     this.OnCompilationStarted(current2, this.compilePhase);
                 }
                 if (this.compilerTasks.Count == this.maxConcurrentCompilers)
                 {
                     break;
                 }
             }
             this.compilePhase++;
         }
     }
 }
        void QueuePendingAssemblies()
        {
            if (pendingAssemblies.Count == 0)
            {
                return;
            }

            List <ScriptAssembly> assemblyCompileQueue    = null;
            List <ScriptAssembly> removePendingAssemblies = null;

            // Find assemblies that have all their references already compiled.
            foreach (var pendingAssembly in pendingAssemblies)
            {
                bool compileAssembly = true;

                foreach (var reference in pendingAssembly.ScriptAssemblyReferences)
                {
                    CompilerMessage[] messages;

                    if (!processedAssemblies.TryGetValue(reference, out messages))
                    {
                        // If a reference is not compiling and not pending
                        // also remove this assembly from pending.
                        if (!compilerTasks.ContainsKey(reference) && !pendingAssemblies.Contains(reference))
                        {
                            if (removePendingAssemblies == null)
                            {
                                removePendingAssemblies = new List <ScriptAssembly>();
                            }

                            removePendingAssemblies.Add(pendingAssembly);
                        }

                        compileAssembly = false;
                        break;
                    }

                    // If reference has compile errors, do not compile the pending assembly.
                    bool compileErrors = messages.Any(m => m.type == CompilerMessageType.Error);

                    if (compileErrors)
                    {
                        if (removePendingAssemblies == null)
                        {
                            removePendingAssemblies = new List <ScriptAssembly>();
                        }

                        removePendingAssemblies.Add(pendingAssembly);

                        compileAssembly = false;
                        break;
                    }
                }

                if (compileAssembly)
                {
                    if (assemblyCompileQueue == null)
                    {
                        assemblyCompileQueue = new List <ScriptAssembly>();
                    }

                    assemblyCompileQueue.Add(pendingAssembly);
                }
            }

            if (removePendingAssemblies != null)
            {
                foreach (var assembly in removePendingAssemblies)
                {
                    pendingAssemblies.Remove(assembly);
                }

                // All pending assemblies were removed and no assemblies
                // were queued for compilation.
                if (assemblyCompileQueue == null)
                {
                    return;
                }
            }

            // No assemblies to compile, need to wait for more references to finish compiling.
            if (assemblyCompileQueue == null)
            {
                if (compilerTasks.Count() == 0)
                {
                    throw new Exception("No pending assemblies queued for compilation and no compilers running. Compilation will never finish.");
                }
                return;
            }

            // Begin compiling any queued assemblies
            foreach (var assembly in assemblyCompileQueue)
            {
                pendingAssemblies.Remove(assembly);

                if (assembly.CallOnBeforeCompilationStarted && OnBeforeCompilationStarted != null)
                {
                    OnBeforeCompilationStarted(assembly, compilePhase);
                }

                var compiler = ScriptCompilers.CreateCompilerInstance(assembly, options, buildOutputDirectory);

                compilerTasks.Add(assembly, compiler);

                // Start compiler process
                compiler.BeginCompiling();

                if (OnCompilationStarted != null)
                {
                    OnCompilationStarted(assembly, compilePhase);
                }

                if (compilerTasks.Count == maxConcurrentCompilers)
                {
                    break;
                }
            }

            compilePhase++;
        }