int CompilationGraph::Build (const sys::Path& TempDir, const LanguageMap& LangMap) { InputLanguagesSet InLangs; bool WasSomeActionGenerated = !InputFilenames.empty(); // Traverse initial parts of the toolchains and fill in InLangs. if (int ret = BuildInitial(InLangs, TempDir, LangMap)) return ret; std::vector<const Node*> JTV; if (int ret = TopologicalSortFilterJoinNodes(JTV)) return ret; // For all join nodes in topological order: for (std::vector<const Node*>::iterator B = JTV.begin(), E = JTV.end(); B != E; ++B) { const Node* CurNode = *B; JoinTool* JT = &static_cast<JoinTool&>(*CurNode->ToolPtr.getPtr()); // Are there any files in the join list? if (JT->JoinListEmpty() && !(JT->WorksOnEmpty() && InputFilenames.empty())) continue; WasSomeActionGenerated = true; Action CurAction; if (int ret = JT->GenerateAction(CurAction, CurNode->HasChildren(), TempDir, InLangs, LangMap)) { return ret; } if (int ret = CurAction.Execute()) return ret; if (CurAction.StopCompilation()) return 0; const Edge* Edg = ChooseEdge(CurNode->OutEdges, InLangs, CurNode->Name()); if (Edg == 0) return 1; const Node* NextNode = getNode(Edg->ToolName()); if (NextNode == 0) return 1; if (int ret = PassThroughGraph(sys::Path(CurAction.OutFile()), NextNode, InLangs, TempDir, LangMap)) { return ret; } } if (!WasSomeActionGenerated) { PrintError("no input files"); return 1; } return 0; }
int CompilationGraph::Build (const sys::Path& TempDir) { InputLanguagesSet InLangs; // Traverse initial parts of the toolchains and fill in InLangs. BuildInitial(InLangs, TempDir); std::vector<const Node*> JTV; TopologicalSortFilterJoinNodes(JTV); // For all join nodes in topological order: for (std::vector<const Node*>::iterator B = JTV.begin(), E = JTV.end(); B != E; ++B) { sys::Path Out; const Node* CurNode = *B; JoinTool* JT = &dynamic_cast<JoinTool&>(*CurNode->ToolPtr.getPtr()); bool IsLast = false; // Are there any files in the join list? if (JT->JoinListEmpty()) continue; // Is this the last tool in the toolchain? // NOTE: we can process several toolchains in parallel. if (!CurNode->HasChildren() || JT->IsLast()) { if (OutputFilename.empty()) { Out.set("a"); Out.appendSuffix(JT->OutputSuffix()); } else Out.set(OutputFilename); IsLast = true; } else { Out = MakeTempFile(TempDir, "tmp", JT->OutputSuffix()); } if (JT->GenerateAction(Out).Execute() != 0) throw std::runtime_error("Tool returned error code!"); if (!IsLast) { const Node* NextNode = &getNode(ChooseEdge(CurNode->OutEdges, InLangs, CurNode->Name())->ToolName()); PassThroughGraph(Out, NextNode, InLangs, TempDir); } } return 0; }