X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanalyzer.cpp;h=75c08849b39c61fdb222bbdcae8ab981bedfb770;hb=20994a6f4802f2dbcf01888d0e1996edf554ade5;hp=f8af44ff9a6295497102bd80989ef3f64c24c096;hpb=04c316da6d5d90e43cba262f54d90ca231f703bf;p=builder.git diff --git a/source/analyzer.cpp b/source/analyzer.cpp index f8af44f..75c0884 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -27,6 +27,18 @@ 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; @@ -36,19 +48,27 @@ void Analyzer::analyze() row.push_back("Rebuild"); table.push_back(row); - build_depend_table(*builder.get_target("cmdline"), 0); + const 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) +void Analyzer::build_depend_table(const Target &tgt, unsigned depth) { - if(mode!=REBUILD && mode!=ALLDEPS) + if(mode==DEPS) { // Skip trivial targets - if(ObjectFile *obj = dynamic_cast(&tgt)) + if(const ObjectFile *obj = dynamic_cast(&tgt)) return build_depend_table(obj->get_source(), depth); - else if(Install *inst = dynamic_cast(&tgt)) + else if(const Install *inst = dynamic_cast(&tgt)) return build_depend_table(inst->get_source(), depth); } else if(mode==REBUILD && !tgt.get_rebuild()) @@ -58,12 +78,13 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) 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(); if(pkg) @@ -85,9 +106,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); } @@ -119,5 +148,22 @@ void Analyzer::print_table() const } } -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(); +}