X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanalyzer.cpp;h=f8af44ff9a6295497102bd80989ef3f64c24c096;hb=04c316da6d5d90e43cba262f54d90ca231f703bf;hp=7dceac720eb7e4f5d969b3d3c381776adfd0bdca;hpb=b0eb979b0dc79269cb3bb5bb2e67ef4e80689cfe;p=builder.git diff --git a/source/analyzer.cpp b/source/analyzer.cpp index 7dceac7..f8af44f 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -1,12 +1,18 @@ -#include -#include -#include -#include +/* $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 "objectfile.h" #include "package.h" +#include "sourcefile.h" #include "target.h" using namespace std; @@ -14,12 +20,15 @@ using namespace Msp; Analyzer::Analyzer(Builder &b): builder(b), + mode(DEPS), max_depth(0), full_paths(false) { } void Analyzer::analyze() { + table.clear(); + TableRow row; row.push_back("Name"); row.push_back("Package"); @@ -36,24 +45,27 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) { if(mode!=REBUILD && mode!=ALLDEPS) { - 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(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()) + /* All targets that depend on to-be-built targets will be rebuilt + themselves, so we cn stop here. */ return; TableRow row; string fn; if(full_paths) - fn=tgt.get_name(); + fn = tgt.get_name(); else - fn=Path::Path(tgt.get_name())[-1]; + fn = FS::basename(tgt.get_name()); row.push_back(string(depth*2, ' ')+fn); - const Package *pkg=tgt.get_package(); + const Package *pkg = tgt.get_package(); if(pkg) row.push_back(pkg->get_name()); else @@ -73,36 +85,37 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) if(!max_depth || depth &depends=tgt.get_depends(); + const TargetList &depends = tgt.get_depends(); + //XXX If we want to sort the targets, we need to take the value of full_paths into account //depends.sort(target_order); - for(list::const_iterator i=depends.begin(); i!=depends.end(); ++i) + for(TargetList::const_iterator i=depends.begin(); i!=depends.end(); ++i) build_depend_table(**i, depth+1); } } 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) { 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<