X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanalyzer.cpp;h=4cebafad175ae6d7cc3a1a2459ffbba4c4d1709e;hb=7c2db9e2b91da953701be233336c5bfa1f3c4af0;hp=21ed52cec64b2cf463a62a1d9823870ea5917283;hpb=1a46151c99a406123c4ddfc797a7841baf3e4cc2;p=builder.git diff --git a/source/analyzer.cpp b/source/analyzer.cpp index 21ed52c..4cebafa 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -1,110 +1,168 @@ -#include -#include -#include -#include +#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; Analyzer::Analyzer(Builder &b): builder(b), + mode(DEPS), max_depth(0), full_paths(false) { } void Analyzer::analyze() { + if(mode==RDEPS) + { + rdepends.clear(); + for(const auto &kvp: builder.get_build_graph().get_targets()) + { + 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); + } + } + + table.clear(); + TableRow row; row.push_back("Name"); row.push_back("Package"); row.push_back("Type"); + row.push_back("Tool"); row.push_back("Rebuild"); table.push_back(row); - build_depend_table(*builder.get_target("cmdline"), 0); + Target &goals = builder.get_build_graph().get_goals(); + if(mode==RDEPS) + { + for(Target *d: goals.get_dependencies()) + build_depend_table(*d, 0); + } + else + build_depend_table(goals, 0); print_table(); } void Analyzer::build_depend_table(Target &tgt, unsigned depth) { - if(mode!=REBUILD && mode!=ALLDEPS) + Target *real = tgt.get_real_target(); + if(mode==DEPS) { - if(dynamic_cast(&tgt)) - return build_depend_table(*tgt.get_depends().front(), depth); - else if(dynamic_cast(&tgt)) - return build_depend_table(*tgt.get_depends().front(), depth); + // 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(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 can stop here. */ return; TableRow row; - string fn; - if(full_paths) - fn=tgt.get_name(); + string name; + const FileTarget *ft = dynamic_cast(&tgt); + if(full_paths && ft) + name = ft->get_path().str(); else - fn=Path::Path(tgt.get_name())[-1]; - row.push_back(string(depth*2, ' ')+fn); + name = tgt.get_name(); + row.push_back(string(depth*2, ' ')+name); - const Package *pkg=tgt.get_package(); + const Package *pkg = tgt.get_package(); if(pkg) row.push_back(pkg->get_name()); else 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_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(Target *d: depends) + build_depend_table(*d, depth+1); } } void Analyzer::print_table() const { - vector col_width; + vector col_width; - for(Table::const_iterator i=table.begin(); i!=table.end(); ++i) + // Determine column widths + 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) { - ostringstream ss; - ss<size(); ++j) + string line; + for(unsigned j=0; j0) - ss<<" "; - ss<(r[j], Fmt("%-s").width(col_width[j])); } - cout<get_name()get_name(); } +bool Analyzer::target_order(const Target *t1, const Target *t2) +{ + return t1->get_name()get_name(); +} + +bool Analyzer::target_order_full(const Target *t1, const Target *t2) +{ + const FileTarget *ft1 = dynamic_cast(t1); + const FileTarget *ft2 = dynamic_cast(t2); + if(!ft1) + { + if(ft2) + return true; + return target_order(t1, t2); + } + else if(!ft2) + return false; + return ft1->get_path().str()get_path().str(); +}