4 #include <msp/path/path.h>
8 #include "objectfile.h"
15 Analyzer::Analyzer(Builder &b):
23 Performs the analysis and prints out the resulting dependency tree.
25 void Analyzer::analyze()
28 row.push_back("Name");
29 row.push_back("Package");
30 row.push_back("Type");
31 row.push_back("Rebuild");
34 build_depend_table(*builder.get_target("cmdline"), 0);
40 Adds rows to the table for the given target and it' dependencies.
42 @param tgt Target to be processed
43 @param depth Recursion level of the target (top level is 0)
45 void Analyzer::build_depend_table(Target &tgt, unsigned depth)
47 if(mode!=REBUILD && mode!=ALLDEPS)
49 // Skip trivial targets
50 if(dynamic_cast<ObjectFile *>(&tgt))
51 return build_depend_table(*tgt.get_depends().front(), depth);
52 else if(dynamic_cast<Install *>(&tgt))
53 return build_depend_table(*tgt.get_depends().front(), depth);
55 else if(mode==REBUILD && !tgt.get_rebuild())
56 /* All targets that depend on to-be-built targets will be rebuilt
57 themselves, so we cn stop here. */
66 fn=Path::Path(tgt.get_name())[-1];
67 row.push_back(string(depth*2, ' ')+fn);
69 const Package *pkg=tgt.get_package();
71 row.push_back(pkg->get_name());
75 row.push_back(tgt.get_type());
79 if(tgt.get_rebuild_reason().empty())
80 row.push_back("Yes (no reason)");
82 row.push_back(tgt.get_rebuild_reason());
87 if(!max_depth || depth<max_depth-1)
89 const TargetList &depends=tgt.get_depends();
90 //XXX If we want to sort the targets, we need to take the value of full_paths into account
91 //depends.sort(target_order);
92 for(TargetList::const_iterator i=depends.begin(); i!=depends.end(); ++i)
93 build_depend_table(**i, depth+1);
98 Prints out the table that resulted from the analysis.
100 void Analyzer::print_table() const
102 vector<unsigned> col_width;
104 // Determine column widths
105 for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
107 if(col_width.size()<i->size())
108 col_width.resize(i->size(), 0);
109 for(unsigned j=0; j<i->size(); ++j)
110 col_width[j]=max(col_width[j], (*i)[j].size());
113 for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
117 for(unsigned j=0; j<i->size(); ++j)
121 ss<<setw(col_width[j])<<(*i)[j];
123 cout<<ss.str()<<'\n';
127 bool Analyzer::target_order(Target *t1, Target *t2)
128 { return t1->get_name()<t2->get_name(); }