X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanalyzer.cpp;h=984af61be7167b9ad06e47abdd4838e3e4bbb521;hb=87ea54db19306434bac3e765c9bd3464fd53f390;hp=3481ec823309523fce9f78e171c3ff9df7374382;hpb=242c55b17e6608b29a77ca17a5b677e202a3ca90;p=builder.git diff --git a/source/analyzer.cpp b/source/analyzer.cpp index 3481ec8..984af61 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -5,15 +5,14 @@ Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include -#include -#include #include +#include #include "analyzer.h" #include "builder.h" #include "install.h" #include "objectfile.h" #include "package.h" +#include "sourcefile.h" #include "target.h" using namespace std; @@ -28,6 +27,20 @@ Analyzer::Analyzer(Builder &b): 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) + { + const TargetList &depends = i->second->get_depends(); + for(TargetList::const_iterator j=depends.begin(); j!=depends.end(); ++j) + rdepends[*j].insert(i->second); + } + } + + table.clear(); + TableRow row; row.push_back("Name"); row.push_back("Package"); @@ -35,36 +48,46 @@ void Analyzer::analyze() row.push_back("Rebuild"); table.push_back(row); - build_depend_table(*builder.get_target("cmdline"), 0); + Target &cmdline = *builder.get_target("cmdline"); + 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); + } + else + build_depend_table(cmdline, 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(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); + 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.get_rebuild() && !real->get_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 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=FS::basename(tgt.get_name()); - 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 @@ -84,9 +107,17 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) if(!max_depth || depth &rdeps = rdepends[&tgt]; + depends.assign(rdeps.begin(), rdeps.end()); + } + else + depends = tgt.get_depends(); + + 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); } @@ -94,7 +125,7 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) void Analyzer::print_table() const { - vector col_width; + vector col_width; // Determine column widths for(Table::const_iterator i=table.begin(); i!=table.end(); ++i) @@ -102,22 +133,38 @@ void Analyzer::print_table() const 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()); + col_width[j] = max(col_width[j], (*i)[j].size()); } for(Table::const_iterator i=table.begin(); i!=table.end(); ++i) { - ostringstream ss; - ss<size(); ++j) { if(j>0) - ss<<" "; - ss<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(); +}