X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fanalyzer.cpp;h=f694edb96198494aadcceeb258950417bb708c90;hb=4d0d003b022943d8a0e39ba19078bab8d32d8857;hp=7dceac720eb7e4f5d969b3d3c381776adfd0bdca;hpb=b0eb979b0dc79269cb3bb5bb2e67ef4e80689cfe;p=builder.git diff --git a/source/analyzer.cpp b/source/analyzer.cpp index 7dceac7..f694edb 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -1,7 +1,15 @@ +/* $Id$ + +This file is part of builder +Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + #include #include #include #include +#include #include "analyzer.h" #include "builder.h" #include "install.h" @@ -14,10 +22,14 @@ using namespace Msp; Analyzer::Analyzer(Builder &b): builder(b), + mode(DEPS), max_depth(0), full_paths(false) { } +/** +Performs the analysis and prints out the resulting dependency tree. +*/ void Analyzer::analyze() { TableRow row; @@ -32,16 +44,25 @@ void Analyzer::analyze() print_table(); } +/** +Adds rows to the table for the given target and it' dependencies. + +@param tgt Target to be processed +@param depth Recursion level of the target (top level is 0) +*/ void Analyzer::build_depend_table(Target &tgt, unsigned depth) { if(mode!=REBUILD && mode!=ALLDEPS) { + // 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); } 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; @@ -50,7 +71,7 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) if(full_paths) fn=tgt.get_name(); else - fn=Path::Path(tgt.get_name())[-1]; + fn=basename(tgt.get_name()); row.push_back(string(depth*2, ' ')+fn); const Package *pkg=tgt.get_package(); @@ -73,17 +94,22 @@ 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); } } +/** +Prints out the table that resulted from the analysis. +*/ void Analyzer::print_table() const { vector col_width; + // Determine column widths for(Table::const_iterator i=table.begin(); i!=table.end(); ++i) { if(col_width.size()size())