4 #include <msp/path/path.h>
8 #include "objectfile.h"
15 Analyzer::Analyzer(Builder &b):
21 void Analyzer::analyze()
24 row.push_back("Name");
25 row.push_back("Package");
26 row.push_back("Type");
27 row.push_back("Rebuild");
30 build_depend_table(*builder.get_target("cmdline"), 0);
35 void Analyzer::build_depend_table(Target &tgt, unsigned depth)
37 if(mode!=REBUILD && mode!=ALLDEPS)
39 if(dynamic_cast<ObjectFile *>(&tgt))
40 return build_depend_table(*tgt.get_depends().front(), depth);
41 else if(dynamic_cast<Install *>(&tgt))
42 return build_depend_table(*tgt.get_depends().front(), depth);
44 else if(mode==REBUILD && !tgt.get_rebuild())
53 fn=Path::Path(tgt.get_name())[-1];
54 row.push_back(string(depth*2, ' ')+fn);
56 const Package *pkg=tgt.get_package();
58 row.push_back(pkg->get_name());
62 row.push_back(tgt.get_type());
66 if(tgt.get_rebuild_reason().empty())
67 row.push_back("Yes (no reason)");
69 row.push_back(tgt.get_rebuild_reason());
74 if(!max_depth || depth<max_depth-1)
76 const list<Target *> &depends=tgt.get_depends();
77 //depends.sort(target_order);
78 for(list<Target *>::const_iterator i=depends.begin(); i!=depends.end(); ++i)
79 build_depend_table(**i, depth+1);
83 void Analyzer::print_table() const
85 vector<unsigned> col_width;
87 for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
89 if(col_width.size()<i->size())
90 col_width.resize(i->size(), 0);
91 for(unsigned j=0; j<i->size(); ++j)
92 col_width[j]=max(col_width[j], (*i)[j].size());
95 for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
99 for(unsigned j=0; j<i->size(); ++j)
103 ss<<setw(col_width[j])<<(*i)[j];
105 cout<<ss.str()<<'\n';
109 bool Analyzer::target_order(Target *t1, Target *t2)
110 { return t1->get_name()<t2->get_name(); }