3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
11 #include <msp/fs/utils.h>
15 #include "objectfile.h"
22 Analyzer::Analyzer(Builder &b):
29 void Analyzer::analyze()
32 row.push_back("Name");
33 row.push_back("Package");
34 row.push_back("Type");
35 row.push_back("Rebuild");
38 build_depend_table(*builder.get_target("cmdline"), 0);
43 void Analyzer::build_depend_table(Target &tgt, unsigned depth)
45 if(mode!=REBUILD && mode!=ALLDEPS)
47 // Skip trivial targets
48 if(dynamic_cast<ObjectFile *>(&tgt))
49 return build_depend_table(*tgt.get_depends().front(), depth);
50 else if(dynamic_cast<Install *>(&tgt))
51 return build_depend_table(*tgt.get_depends().front(), depth);
53 else if(mode==REBUILD && !tgt.get_rebuild())
54 /* All targets that depend on to-be-built targets will be rebuilt
55 themselves, so we cn stop here. */
64 fn=FS::basename(tgt.get_name());
65 row.push_back(string(depth*2, ' ')+fn);
67 const Package *pkg=tgt.get_package();
69 row.push_back(pkg->get_name());
73 row.push_back(tgt.get_type());
77 if(tgt.get_rebuild_reason().empty())
78 row.push_back("Yes (no reason)");
80 row.push_back(tgt.get_rebuild_reason());
85 if(!max_depth || depth<max_depth-1)
87 const TargetList &depends=tgt.get_depends();
88 //XXX If we want to sort the targets, we need to take the value of full_paths into account
89 //depends.sort(target_order);
90 for(TargetList::const_iterator i=depends.begin(); i!=depends.end(); ++i)
91 build_depend_table(**i, depth+1);
95 void Analyzer::print_table() const
97 vector<unsigned> col_width;
99 // Determine column widths
100 for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
102 if(col_width.size()<i->size())
103 col_width.resize(i->size(), 0);
104 for(unsigned j=0; j<i->size(); ++j)
105 col_width[j]=max(col_width[j], (*i)[j].size());
108 for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
112 for(unsigned j=0; j<i->size(); ++j)
116 ss<<setw(col_width[j])<<(*i)[j];
118 cout<<ss.str()<<'\n';
122 bool Analyzer::target_order(Target *t1, Target *t2)
123 { return t1->get_name()<t2->get_name(); }