Esempio n. 1
0
        /// <summary>
        /// Compiles the list of files given
        /// </summary>
        public bool CompileFiles(List <FileToCompile> filesToCompile)
        {
            if (filesToCompile == null || filesToCompile.Count == 0)
            {
                EndOfCompilation();
                return(true);
            }

            // init
            StartingTime     = DateTime.Now;
            NbFilesToCompile = filesToCompile.Count;

            // now we do a list of those files, sorted from the biggest (in size) to the smallest file
            filesToCompile.Sort((file1, file2) => file2.Size.CompareTo(file1.Size));

            // we want to dispatch all those files in a fair way among the Prowin processes we will create...
            var numberOfProcesses = MonoProcess ? 1 : Math.Max(NumberOfProcessesPerCore, 1) * Environment.ProcessorCount;

            // ensure that each process will at least take in 10 files, starting a new process for 1 file to compile isn't efficient!
            numberOfProcesses = Math.Min(numberOfProcesses, NbFilesToCompile / 10);

            var fileLists      = new List <List <FileToCompile> >();
            var currentProcess = 0;

            foreach (var file in filesToCompile)
            {
                // create a new process when needed
                if (currentProcess >= fileLists.Count)
                {
                    fileLists.Add(new List <FileToCompile>());
                }

                // assign the file to the current process
                fileLists[currentProcess].Add(file);

                // we will assign the next file to the next process...
                currentProcess++;
                if (currentProcess == numberOfProcesses)
                {
                    currentProcess = 0;
                }
            }

            _processesRunning = fileLists.Count;

            // init the compilation on each process
            _processes.Clear();
            for (int i = 0; i < fileLists.Count; i++)
            {
                var exec = new ProExecutionCompile(ProEnv)
                {
                    Files = fileLists[i],
                    NeedDatabaseConnection = true,
                    NoBatch        = true,
                    IsTestMode     = IsTestMode,
                    IsAnalysisMode = IsAnalysisMode
                };
                exec.OnExecutionOk     += OnExecutionOk;
                exec.OnExecutionFailed += OnExecutionFailed;
                exec.OnCompilationOk   += OnExecCompilationOk;

                if (RFilesOnly)
                {
                    exec.CompileWithDebugList = false;
                    exec.CompileWithXref      = false;
                    exec.CompileWithListing   = false;
                }

                _processes.Add(exec);
            }

            // launch the compile process
            return(_processes.All(exec => exec.Start()));
        }