]> git.tdb.fi Git - builder.git/blobdiff - source/analyzer.cpp
Account for install directories when forming displaced dependency paths
[builder.git] / source / analyzer.cpp
index 984af61be7167b9ad06e47abdd4838e3e4bbb521..2c9cf058d7a565d3849acca028e150d878f4e85c 100644 (file)
@@ -1,19 +1,13 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <msp/fs/utils.h>
 #include <msp/io/print.h>
 #include "analyzer.h"
 #include "builder.h"
-#include "install.h"
+#include "buildgraph.h"
 #include "objectfile.h"
-#include "package.h"
 #include "sourcefile.h"
+#include "sourcepackage.h"
 #include "target.h"
+#include "tool.h"
 
 using namespace std;
 using namespace Msp;
@@ -30,11 +24,14 @@ void Analyzer::analyze()
        if(mode==RDEPS)
        {
                rdepends.clear();
-               const TargetMap &targets = builder.get_targets();
-               for(TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+               const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
+               for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
                {
-                       const TargetList &depends = i->second->get_depends();
-                       for(TargetList::const_iterator j=depends.begin(); j!=depends.end(); ++j)
+                       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);
+                       const Target::Dependencies &tdepends = i->second->get_transitive_dependencies();
+                       for(Target::Dependencies::const_iterator j=tdepends.begin(); j!=tdepends.end(); ++j)
                                rdepends[*j].insert(i->second);
                }
        }
@@ -45,18 +42,19 @@ void Analyzer::analyze()
        row.push_back("Name");
        row.push_back("Package");
        row.push_back("Type");
+       row.push_back("Tool");
        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 TargetList &deps = cmdline.get_depends();
-               for(TargetList::const_iterator i=deps.begin(); i!=deps.end(); ++i)
+               const Target::Dependencies &deps = goals.get_dependencies();
+               for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
                        build_depend_table(**i, 0);
        }
        else
-               build_depend_table(cmdline, 0);
+               build_depend_table(goals, 0);
 
        print_table();
 }
@@ -72,7 +70,7 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth)
                if(const ObjectFile *obj = dynamic_cast<const ObjectFile *>(&tgt))
                        return build_depend_table(obj->get_source(), depth);
        }
-       else if(mode==REBUILD && !tgt.get_rebuild() && !real->get_rebuild())
+       else if(mode==REBUILD && !tgt.needs_rebuild())
                /* All targets that depend on to-be-built targets will be rebuilt
                themselves, so we can stop here. */
                return;
@@ -94,31 +92,35 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth)
                row.push_back("");
        
        row.push_back(tgt.get_type());
-       
-       if(tgt.get_rebuild())
-       {
-               if(tgt.get_rebuild_reason().empty())
-                       row.push_back("Yes (no reason)");
-               else
-                       row.push_back(tgt.get_rebuild_reason());
-       }
+       const Tool *tool = tgt.get_tool();
+       if(tool)
+               row.push_back(tool->get_tag());
+       else
+               row.push_back("");
+
+       if(tgt.needs_rebuild())
+               row.push_back(tgt.get_rebuild_reason());
 
        table.push_back(row);
 
        if(!max_depth || depth<max_depth-1)
        {
-               TargetList depends;
+               Target::Dependencies depends;
                if(mode==RDEPS)
                {
                        const set<Target *> &rdeps = rdepends[&tgt];
                        depends.assign(rdeps.begin(), rdeps.end());
                }
                else
-                       depends = tgt.get_depends();
+               {
+                       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);
 
-               for(TargetList::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+               for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
                        build_depend_table(**i, depth+1);
        }
 }
@@ -143,7 +145,7 @@ void Analyzer::print_table() const
                {
                        if(j>0)
                                line += "  ";
-                       line += lexical_cast((*i)[j], Fmt("%-s").width(col_width[j]));
+                       line += lexical_cast<string>((*i)[j], Fmt("%-s").width(col_width[j]));
                }
                IO::print("%s\n", line);
        }