X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanalyzer.cpp;h=2c9cf058d7a565d3849acca028e150d878f4e85c;hb=bc85cc286c8a3f1055f1979a7ff8697cf1b61912;hp=563143f11c56d2c0b5a72b7f5e4fc58327d23f72;hpb=75bdcf13fbd285e2006337ec606ca28fa4ddae9e;p=builder.git diff --git a/source/analyzer.cpp b/source/analyzer.cpp index 563143f..2c9cf05 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; @@ -27,39 +21,64 @@ Analyzer::Analyzer(Builder &b): void Analyzer::analyze() { + if(mode==RDEPS) + { + rdepends.clear(); + const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets(); + for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) + { + const Target::Dependencies &depends = i->second->get_dependencies(); + for(Target::Dependencies::const_iterator j=depends.begin(); j!=depends.end(); ++j) + rdepends[*j].insert(i->second); + const Target::Dependencies &tdepends = i->second->get_transitive_dependencies(); + for(Target::Dependencies::const_iterator j=tdepends.begin(); j!=tdepends.end(); ++j) + rdepends[*j].insert(i->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) + { + const Target::Dependencies &deps = goals.get_dependencies(); + for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) + build_depend_table(**i, 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) { // Skip trivial targets - if(ObjectFile *obj = dynamic_cast(&tgt)) + 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(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; string name; - FileTarget *ft = dynamic_cast(&tgt); + const FileTarget *ft = dynamic_cast(&tgt); if(full_paths && ft) name = ft->get_path().str(); else @@ -73,23 +92,35 @@ void Analyzer::build_depend_table(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_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::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) build_depend_table(**i, depth+1); } } @@ -114,11 +145,28 @@ void Analyzer::print_table() const { if(j>0) line += " "; - line += lexical_cast((*i)[j], Fmt("%-s").width(col_width[j])); + line += lexical_cast((*i)[j], Fmt("%-s").width(col_width[j])); } IO::print("%s\n", line); } } -bool Analyzer::target_order(Target *t1, Target *t2) -{ return t1->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(); +}