X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanalyzer.cpp;h=4cebafad175ae6d7cc3a1a2459ffbba4c4d1709e;hb=7c2db9e2b91da953701be233336c5bfa1f3c4af0;hp=75c08849b39c61fdb222bbdcae8ab981bedfb770;hpb=e7fe6a0e161cbba80ef924f53792eded80cbb3a1;p=builder.git diff --git a/source/analyzer.cpp b/source/analyzer.cpp index 75c0884..4cebafa 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -1,19 +1,13 @@ -/* $Id$ - -This file is part of builder -Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include #include "analyzer.h" #include "builder.h" -#include "install.h" +#include "buildgraph.h" #include "objectfile.h" -#include "package.h" #include "sourcefile.h" +#include "sourcepackage.h" #include "target.h" +#include "tool.h" using namespace std; using namespace Msp; @@ -30,12 +24,12 @@ void Analyzer::analyze() if(mode==RDEPS) { rdepends.clear(); - const TargetMap &targets = builder.get_targets(); - for(TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) + for(const auto &kvp: builder.get_build_graph().get_targets()) { - const TargetList &depends = i->second->get_depends(); - for(TargetList::const_iterator j=depends.begin(); j!=depends.end(); ++j) - rdepends[*j].insert(i->second); + for(Target *d: kvp.second->get_dependencies()) + rdepends[d].insert(kvp.second); + for(Target *d: kvp.second->get_transitive_dependencies()) + rdepends[d].insert(kvp.second); } } @@ -45,35 +39,36 @@ void Analyzer::analyze() row.push_back("Name"); row.push_back("Package"); row.push_back("Type"); + row.push_back("Tool"); row.push_back("Rebuild"); table.push_back(row); - const Target &cmdline = *builder.get_target("cmdline"); + Target &goals = builder.get_build_graph().get_goals(); if(mode==RDEPS) { - const TargetList &deps = cmdline.get_depends(); - for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i) - build_depend_table(**i, 0); + for(Target *d: goals.get_dependencies()) + build_depend_table(*d, 0); } else - build_depend_table(cmdline, 0); + build_depend_table(goals, 0); print_table(); } -void Analyzer::build_depend_table(const Target &tgt, unsigned depth) +void Analyzer::build_depend_table(Target &tgt, unsigned depth) { + Target *real = tgt.get_real_target(); if(mode==DEPS) { // Skip trivial targets + if(real!=&tgt) + return build_depend_table(*real, depth); if(const ObjectFile *obj = dynamic_cast(&tgt)) return build_depend_table(obj->get_source(), depth); - else if(const Install *inst = dynamic_cast(&tgt)) - return build_depend_table(inst->get_source(), depth); } - else if(mode==REBUILD && !tgt.get_rebuild()) + else if(mode==REBUILD && !tgt.needs_rebuild()) /* All targets that depend on to-be-built targets will be rebuilt - themselves, so we cn stop here. */ + themselves, so we can stop here. */ return; TableRow row; @@ -93,32 +88,36 @@ void Analyzer::build_depend_table(const Target &tgt, unsigned depth) row.push_back(""); row.push_back(tgt.get_type()); - - if(tgt.get_rebuild()) - { - if(tgt.get_rebuild_reason().empty()) - row.push_back("Yes (no reason)"); - else - row.push_back(tgt.get_rebuild_reason()); - } + const Tool *tool = tgt.get_tool(); + if(tool) + row.push_back(tool->get_tag()); + else + row.push_back(""); + + if(tgt.needs_rebuild()) + row.push_back(tgt.get_rebuild_reason()); table.push_back(row); if(!max_depth || depth &rdeps = rdepends[&tgt]; depends.assign(rdeps.begin(), rdeps.end()); } else - depends = tgt.get_depends(); + { + depends = tgt.get_dependencies(); + const Target::Dependencies &tdeps = tgt.get_transitive_dependencies(); + depends.insert(depends.end(), tdeps.begin(), tdeps.end()); + } depends.sort(full_paths ? target_order_full : target_order); - for(TargetList::const_iterator i=depends.begin(); i!=depends.end(); ++i) - build_depend_table(**i, depth+1); + for(Target *d: depends) + build_depend_table(*d, depth+1); } } @@ -127,22 +126,22 @@ void Analyzer::print_table() const vector col_width; // Determine column widths - for(Table::const_iterator i=table.begin(); i!=table.end(); ++i) + for(const vector &r: table) { - if(col_width.size()size()) - col_width.resize(i->size(), 0); - for(unsigned j=0; jsize(); ++j) - col_width[j] = max(col_width[j], (*i)[j].size()); + if(col_width.size() &r: table) { string line; - for(unsigned j=0; jsize(); ++j) + for(unsigned j=0; j0) line += " "; - line += lexical_cast((*i)[j], Fmt("%-s").width(col_width[j])); + line += lexical_cast(r[j], Fmt("%-s").width(col_width[j])); } IO::print("%s\n", line); }