+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <iomanip>
#include <iostream>
#include <sstream>
#include <msp/path/path.h>
+#include <msp/path/utils.h>
#include "analyzer.h"
#include "builder.h"
#include "install.h"
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;
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)
+ if(mode!=REBUILD && mode!=ALLDEPS)
{
+ // Skip trivial targets
if(dynamic_cast<ObjectFile *>(&tgt))
return build_depend_table(*tgt.get_depends().front(), depth);
else if(dynamic_cast<Install *>(&tgt))
return build_depend_table(*tgt.get_depends().front(), depth);
}
- else if(!tgt.get_rebuild())
+ 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;
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();
if(!max_depth || depth<max_depth-1)
{
- const list<Target *> &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<Target *>::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<unsigned> col_width;
+ // Determine column widths
for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
{
if(col_width.size()<i->size())