3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/fs/utils.h>
9 #include <msp/io/print.h>
13 #include "objectfile.h"
15 #include "sourcefile.h"
21 Analyzer::Analyzer(Builder &b):
28 void Analyzer::analyze()
33 row.push_back("Name");
34 row.push_back("Package");
35 row.push_back("Type");
36 row.push_back("Rebuild");
39 build_depend_table(*builder.get_target("cmdline"), 0);
44 void Analyzer::build_depend_table(Target &tgt, unsigned depth)
46 if(mode!=REBUILD && mode!=ALLDEPS)
48 // Skip trivial targets
49 if(ObjectFile *obj = dynamic_cast<ObjectFile *>(&tgt))
50 return build_depend_table(obj->get_source(), depth);
51 else if(Install *inst = dynamic_cast<Install *>(&tgt))
52 return build_depend_table(inst->get_source(), depth);
54 else if(mode==REBUILD && !tgt.get_rebuild())
55 /* All targets that depend on to-be-built targets will be rebuilt
56 themselves, so we cn stop here. */
65 fn = FS::basename(tgt.get_name());
66 row.push_back(string(depth*2, ' ')+fn);
68 const Package *pkg = tgt.get_package();
70 row.push_back(pkg->get_name());
74 row.push_back(tgt.get_type());
78 if(tgt.get_rebuild_reason().empty())
79 row.push_back("Yes (no reason)");
81 row.push_back(tgt.get_rebuild_reason());
86 if(!max_depth || depth<max_depth-1)
88 const TargetList &depends = tgt.get_depends();
89 //XXX If we want to sort the targets, we need to take the value of full_paths into account
90 //depends.sort(target_order);
91 for(TargetList::const_iterator i=depends.begin(); i!=depends.end(); ++i)
92 build_depend_table(**i, depth+1);
96 void Analyzer::print_table() const
98 vector<string::size_type> col_width;
100 // Determine column widths
101 for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
103 if(col_width.size()<i->size())
104 col_width.resize(i->size(), 0);
105 for(unsigned j=0; j<i->size(); ++j)
106 col_width[j] = max(col_width[j], (*i)[j].size());
109 for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
112 for(unsigned j=0; j<i->size(); ++j)
116 line += lexical_cast((*i)[j], Fmt("%-s").width(col_width[j]));
118 IO::print("%s\n", line);
122 bool Analyzer::target_order(Target *t1, Target *t2)
123 { return t1->get_name()<t2->get_name(); }