Ejemplo n.º 1
0
        /// <summary>
        /// Build all the tasks for this node
        /// </summary>
        /// <param name="Job">Information about the current job</param>
        /// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include. Should be set to contain the node inputs on entry.</param>
        /// <returns>Whether the task succeeded or not. Exiting with an exception will be caught and treated as a failure.</returns>
        public bool Build(JobContext Job, Dictionary <string, HashSet <FileReference> > TagNameToFileSet)
        {
            // Run each of the tasks in order
            HashSet <FileReference> BuildProducts = TagNameToFileSet[DefaultOutput.TagName];

            for (int Idx = 0; Idx < Tasks.Count; Idx++)
            {
                ITaskExecutor Executor = Tasks[Idx].GetExecutor();
                if (Executor == null)
                {
                    // Execute this task directly
                    try
                    {
                        Tasks[Idx].Execute(Job, BuildProducts, TagNameToFileSet);
                    }
                    catch (Exception Ex)
                    {
                        ExceptionUtils.AddContext(Ex, "while executing task {0}", Tasks[Idx].GetTraceString());
                        if (Tasks[Idx].SourceLocation != null)
                        {
                            ExceptionUtils.AddContext(Ex, "at {0}({1})", GetReadablePathForDiagnostics(Tasks[Idx].SourceLocation.Item1), Tasks[Idx].SourceLocation.Item2);
                        }
                        throw;
                    }
                }
                else
                {
                    // The task has a custom executor, which may be able to execute several tasks simultaneously. Try to add the following tasks.
                    int FirstIdx = Idx;
                    while (Idx + 1 < Tasks.Count && Executor.Add(Tasks[Idx + 1]))
                    {
                        Idx++;
                    }
                    try
                    {
                        Executor.Execute(Job, BuildProducts, TagNameToFileSet);
                    }
                    catch (Exception Ex)
                    {
                        for (int TaskIdx = FirstIdx; TaskIdx <= Idx; TaskIdx++)
                        {
                            ExceptionUtils.AddContext(Ex, "while executing {0}", Tasks[TaskIdx].GetTraceString());
                        }
                        if (Tasks[FirstIdx].SourceLocation != null)
                        {
                            ExceptionUtils.AddContext(Ex, "at {0}({1})", GetReadablePathForDiagnostics(Tasks[FirstIdx].SourceLocation.Item1), Tasks[FirstIdx].SourceLocation.Item2);
                        }
                        throw;
                    }
                }
            }

            // Remove anything that doesn't exist, since these files weren't explicitly tagged
            BuildProducts.RemoveWhere(x => !FileReference.Exists(x));
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Build all the tasks for this node
        /// </summary>
        /// <param name="Job">Information about the current job</param>
        /// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include. Should be set to contain the node inputs on entry.</param>
        /// <returns>Whether the task succeeded or not. Exiting with an exception will be caught and treated as a failure.</returns>
        public bool Build(JobContext Job, Dictionary <string, HashSet <FileReference> > TagNameToFileSet)
        {
            // Run each of the tasks in order
            HashSet <FileReference> BuildProducts = TagNameToFileSet[DefaultOutput.TagName];

            for (int Idx = 0; Idx < Tasks.Count; Idx++)
            {
                ITaskExecutor Executor = Tasks[Idx].GetExecutor();
                if (Executor == null)
                {
                    // Execute this task directly
                    if (!Tasks[Idx].Execute(Job, BuildProducts, TagNameToFileSet))
                    {
                        CommandUtils.Log("Failed to execute task.");
                        return(false);
                    }
                }
                else
                {
                    // The task has a custom executor, which may be able to execute several tasks simultaneously. Try to add the following tasks.
                    while (Idx + 1 < Tasks.Count && Executor.Add(Tasks[Idx + 1]))
                    {
                        Idx++;
                    }
                    if (!Executor.Execute(Job, BuildProducts, TagNameToFileSet))
                    {
                        CommandUtils.Log("Failed to execute task.");
                        return(false);
                    }
                }
            }

            // Remove anything that doesn't exist, since these files weren't explicitly tagged
            BuildProducts.RemoveWhere(x => !FileReference.Exists(x));
            return(true);
        }