Beispiel #1
0
        void main(string[] cmdline_args)
        {
            string[] all_args = fetchConfigArgs().Concat(cmdline_args).ToArray();
            logNubuildInvocation(all_args);
            try
            {
                parseArgs(all_args);
            }
            catch (UserError err)
            {
                usage(err.Message);
            }

            BuildEngine.theEngine.ItemCache = GetItemCache();
            BuildEngine.theEngine.Repository = new Repository(BuildEngine.theEngine.ItemCache);
            if (this.useCloudExecution)
            {
                if (!this.useCloudCache)
                {
                    usage("Cloud Execution requires Cloud Cache!");
                }

                BuildEngine.theEngine.CloudReportQueueName = Path.GetRandomFileName().Substring(0, 8);
                BuildEngine.theEngine.CloudExecutionQueue = new CloudExecutionQueue(BuildEngine.theEngine.CloudReportQueueName);
                Logger.WriteLine("Using cloud report queue name: " + BuildEngine.theEngine.CloudReportQueueName);
            }

            Scheduler scheduler = new Scheduler(jobParallelism);

            scheduler.addTargetVerbs(verbs);

            ////try
            ////{
            scheduler.parallelSchedule();
            ////}
            ////catch (Exception ex)
            ////{
            ////    scheduler.dbgDisplayCounts();
            ////    throw;
            ////}

            IEnumerable<BuildObject> targets = scheduler.getTargets();

            BuildObject outputTarget = null;
            if (targets.Count() > 0)
            {
                outputTarget = targets.First();
            }
            else
            {
                Logger.WriteLine("No targets requested.");
            }

            if (targets.Count() > 1)
            {
                // TODO need a better story for relaying failure results. Right now
                // they get stuck in the results cache, but don't appear where we
                // can find them. Emit to a log, or to files in nuobj?
                Logger.WriteLine("Multiple targets build. First result follows.");
            }

            if (outputTarget != null)
            {
                Disposition d = scheduler.getObjectDisposition(outputTarget);
                if (d is Fresh)
                {
                    ASCIIPresentater ascii = new ASCIIPresentater();
                    IVerb verb = scheduler.getParent(outputTarget);
                    verb.getPresentation().format(ascii);
                    Logger.Write(ascii.ToString());

                    if (this.html_output != null)
                    {
                        HTMLPresentater html = new HTMLPresentater();
                        verb.getPresentation().format(html);

                        try
                        {
                            using (StreamWriter sw = new StreamWriter(this.html_output))
                            {
                                sw.Write(html.ToString());
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.WriteLine("Failed to write html output to file: " + html_output);
                            Logger.WriteLine("Exception was: " + e);
                        }
                    }
                }
                else
                {
                    Logger.WriteLine("Build failed.");
                    foreach (string msg in d.getMessages())
                    {
                        Logger.Write(msg);
                    }
                }
            }
            else if (targets.Count() == 0)
            {
                Logger.WriteLine("No targets requested.");
            }
            else
            {
                Logger.WriteLine("Multiple targets built. Look for results in nuobj/.");
            }

            // -
            // We have to explicitly ask the BackgroundWorker thread to exit
            // as it will prevent the process from exiting until it does.
            // -
            this.backgroundWorker.StopWork();

            // -
            // Report what the background worker accomplished during this run.
            // -
            this.backgroundWorker.WaitForCompletion();
            Logger.WriteLine(string.Format("Background Worker completed {0} work items out of {1} queued.",
                this.backgroundWorker.GetWorkItemsPerformed,
                this.backgroundWorker.GetWorkItemsQueued));
            if (this.backgroundWorker.GetWorkItemsFailed != 0)
            {
                Logger.WriteLine(string.Format(
                    "{0} work item procedures failed (threw an exception).",
                    this.backgroundWorker.GetWorkItemsFailed));
            }
        }
Beispiel #2
0
        void main(string[] cmdline_args)
        {
            string[] all_args = fetchConfigArgs().Concat(cmdline_args).ToArray();
            logNubuildInvocation(all_args);
            try
            {
                parseArgs(all_args);
            }
            catch (UserError err)
            {
                usage(err.Message);
            }

            BuildEngine.theEngine.ItemCache  = GetItemCache();
            BuildEngine.theEngine.Repository = new Repository(BuildEngine.theEngine.ItemCache);
            if (this.useCloudExecution)
            {
                if (!this.useCloudCache)
                {
                    usage("Cloud Execution requires Cloud Cache!");
                }

                BuildEngine.theEngine.CloudReportQueueName = Path.GetRandomFileName().Substring(0, 8);
                // BuildEngine.theEngine.CloudExecutionQueue = new CloudExecutionQueue(BuildEngine.theEngine.CloudReportQueueName);
                Logger.WriteLine("Using cloud report queue name: " + BuildEngine.theEngine.CloudReportQueueName);
            }

            Scheduler scheduler = new Scheduler(jobParallelism);

            scheduler.addTargetVerbs(verbs);

            ////try
            ////{
            scheduler.parallelSchedule();
            ////}
            ////catch (Exception ex)
            ////{
            ////    scheduler.dbgDisplayCounts();
            ////    throw;
            ////}

            IEnumerable <BuildObject> targets = scheduler.getTargets();

            BuildObject outputTarget = null;

            if (targets.Count() > 0)
            {
                outputTarget = targets.First();
            }
            else
            {
                Logger.WriteLine("No targets requested.");
            }

            if (targets.Count() > 1)
            {
                // TODO need a better story for relaying failure results. Right now
                // they get stuck in the results cache, but don't appear where we
                // can find them. Emit to a log, or to files in nuobj?
                Logger.WriteLine("Multiple targets build. First result follows.");
            }

            if (outputTarget != null)
            {
                Disposition d = scheduler.getObjectDisposition(outputTarget);
                if (d is Fresh)
                {
                    ASCIIPresentater ascii = new ASCIIPresentater();
                    IVerb            verb  = scheduler.getParent(outputTarget);
                    verb.getPresentation().format(ascii);
                    Logger.Write(ascii.ToString());

                    if (this.html_output != null)
                    {
                        HTMLPresentater html = new HTMLPresentater();
                        verb.getPresentation().format(html);

                        try
                        {
                            using (StreamWriter sw = new StreamWriter(this.html_output))
                            {
                                sw.Write(html.ToString());
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.WriteLine("Failed to write html output to file: " + html_output);
                            Logger.WriteLine("Exception was: " + e);
                        }
                    }
                }
                else
                {
                    Logger.WriteLine("Build failed.");
                    foreach (string msg in d.getMessages())
                    {
                        Logger.Write(msg);
                    }
                }
            }
            else if (targets.Count() == 0)
            {
                Logger.WriteLine("No targets requested.");
            }
            else
            {
                Logger.WriteLine("Multiple targets built. Look for results in nuobj/.");
            }

            // -
            // We have to explicitly ask the BackgroundWorker thread to exit
            // as it will prevent the process from exiting until it does.
            // -
            this.backgroundWorker.StopWork();

            // -
            // Report what the background worker accomplished during this run.
            // -
            this.backgroundWorker.WaitForCompletion();
            Logger.WriteLine(string.Format("Background Worker completed {0} work items out of {1} queued.",
                                           this.backgroundWorker.GetWorkItemsPerformed,
                                           this.backgroundWorker.GetWorkItemsQueued));
            if (this.backgroundWorker.GetWorkItemsFailed != 0)
            {
                Logger.WriteLine(string.Format(
                                     "{0} work item procedures failed (threw an exception).",
                                     this.backgroundWorker.GetWorkItemsFailed));
            }
        }