]> git.tdb.fi Git - builder.git/blobdiff - source/analyzer.cpp
Convert all list containers to vectors
[builder.git] / source / analyzer.cpp
index 7ea1fff8c58aa0d1dbcb2e25ffca4e93b1d68e3e..94f7782e2848632906b78360384ad1ed365295c8 100644 (file)
@@ -1,7 +1,9 @@
+#include <msp/core/algorithm.h>
 #include <msp/fs/utils.h>
 #include <msp/io/print.h>
 #include "analyzer.h"
 #include "builder.h"
+#include "buildgraph.h"
 #include "objectfile.h"
 #include "sourcefile.h"
 #include "sourcepackage.h"
@@ -23,12 +25,12 @@ void Analyzer::analyze()
        if(mode==RDEPS)
        {
                rdepends.clear();
-               const Builder::TargetMap &targets = builder.get_targets();
-               for(Builder::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+               for(const auto &kvp: builder.get_build_graph().get_targets())
                {
-                       const Target::Dependencies &depends = i->second->get_dependencies();
-                       for(Target::Dependencies::const_iterator j=depends.begin(); j!=depends.end(); ++j)
-                               rdepends[*j].insert(i->second);
+                       for(Target *d: kvp.second->get_dependencies())
+                               rdepends[d].insert(kvp.second);
+                       for(Target *d: kvp.second->get_transitive_dependencies())
+                               rdepends[d].insert(kvp.second);
                }
        }
 
@@ -42,15 +44,14 @@ void Analyzer::analyze()
        row.push_back("Rebuild");
        table.push_back(row);
        
-       Target &cmdline = *builder.get_target("cmdline");
+       Target &goals = builder.get_build_graph().get_goals();
        if(mode==RDEPS)
        {
-               const Target::Dependencies &deps = cmdline.get_dependencies();
-               for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-                       build_depend_table(**i, 0);
+               for(Target *d: goals.get_dependencies())
+                       build_depend_table(*d, 0);
        }
        else
-               build_depend_table(cmdline, 0);
+               build_depend_table(goals, 0);
 
        print_table();
 }
@@ -108,12 +109,16 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth)
                        depends.assign(rdeps.begin(), rdeps.end());
                }
                else
+               {
                        depends = tgt.get_dependencies();
+                       const Target::Dependencies &tdeps = tgt.get_transitive_dependencies();
+                       depends.insert(depends.end(), tdeps.begin(), tdeps.end());
+               }
 
-               depends.sort(full_paths ? target_order_full : target_order);
+               sort(depends, (full_paths ? target_order_full : target_order));
 
-               for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
-                       build_depend_table(**i, depth+1);
+               for(Target *d: depends)
+                       build_depend_table(*d, depth+1);
        }
 }
 
@@ -122,22 +127,22 @@ void Analyzer::print_table() const
        vector<string::size_type> col_width;
 
        // Determine column widths
-       for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
+       for(const vector<string> &r: table)
        {
-               if(col_width.size()<i->size())
-                       col_width.resize(i->size(), 0);
-               for(unsigned j=0; j<i->size(); ++j)
-                       col_width[j] = max(col_width[j], (*i)[j].size());
+               if(col_width.size()<r.size())
+                       col_width.resize(r.size(), 0);
+               for(unsigned j=0; j<r.size(); ++j)
+                       col_width[j] = max(col_width[j], r[j].size());
        }
 
-       for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
+       for(const vector<string> &r: table)
        {
                string line;
-               for(unsigned j=0; j<i->size(); ++j)
+               for(unsigned j=0; j<r.size(); ++j)
                {
                        if(j>0)
                                line += "  ";
-                       line += lexical_cast((*i)[j], Fmt("%-s").width(col_width[j]));
+                       line += lexical_cast<string>(r[j], Fmt("%-s").width(col_width[j]));
                }
                IO::print("%s\n", line);
        }