]> git.tdb.fi Git - builder.git/blobdiff - source/analyzer.cpp
Miscellaneous minor code cleanups
[builder.git] / source / analyzer.cpp
index 7dceac720eb7e4f5d969b3d3c381776adfd0bdca..37c8911c4bcb3e8562837eaae5634c8d9e961bcd 100644 (file)
@@ -1,12 +1,18 @@
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <msp/path/path.h>
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include <msp/fs/utils.h>
+#include <msp/io/print.h>
 #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,12 +45,15 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth)
 {
        if(mode!=REBUILD && mode!=ALLDEPS)
        {
-               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);
+               // Skip trivial targets
+               if(ObjectFile *obj=dynamic_cast<ObjectFile *>(&tgt))
+                       return build_depend_table(obj->get_source(), depth);
+               else if(Install *inst=dynamic_cast<Install *>(&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;
@@ -50,7 +62,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=FS::basename(tgt.get_name());
        row.push_back(string(depth*2, ' ')+fn);
 
        const Package *pkg=tgt.get_package();
@@ -73,9 +85,10 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth)
 
        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);
        }
 }
@@ -84,6 +97,7 @@ 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())
@@ -94,15 +108,14 @@ void Analyzer::print_table() const
 
        for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
        {
-               ostringstream ss;
-               ss<<left;
+               string line;
                for(unsigned j=0; j<i->size(); ++j)
                {
                        if(j>0)
-                               ss<<"  ";
-                       ss<<setw(col_width[j])<<(*i)[j];
+                               line+="  ";
+                       line+=lexical_cast((*i)[j], Fmt("%-s").width(col_width[j]));
                }
-               cout<<ss.str()<<'\n';
+               IO::print("%s\n", line);
        }
 }