]> git.tdb.fi Git - builder.git/commitdiff
Move some more functionality into BuildGraph
authorMikko Rasa <tdb@tdb.fi>
Sun, 7 Apr 2013 19:55:03 +0000 (22:55 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 7 Apr 2013 19:55:03 +0000 (22:55 +0300)
Readme.txt
source/analyzer.cpp
source/builder.cpp
source/buildgraph.cpp
source/buildgraph.h

index db18ed7359bb3a640c28172a7163cb776b339ef9..9ae07f62c1ce4e191950218a550c617675ef3e11 100644 (file)
@@ -236,9 +236,9 @@ install
 tarballs
   Depends on source tarballs of all packages.
 
-cmdline
-  This target is an internal representation of the command line.  Trying to
-  add it to the command line will cause Builder to abort.
+goals
+  Depends on all targets on the command line.  Trying to add this target to the
+  command line will cause Builder to abort due to a circular dependency.
 
 -------------------------------------------------------------------------------
 
index 39cc7e183974ff6e2894289386127bd5c902bebc..d15a7477984886db2e4c22262869f019275f9454 100644 (file)
@@ -43,15 +43,15 @@ void Analyzer::analyze()
        row.push_back("Rebuild");
        table.push_back(row);
        
-       Target &cmdline = *builder.get_build_graph().get_target("cmdline");
+       Target &goals = builder.get_build_graph().get_goals();
        if(mode==RDEPS)
        {
-               const Target::Dependencies &deps = cmdline.get_dependencies();
+               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();
 }
index 8b900a4987af9230c4f8d860a004bcb49379825a..c599e269408adb38d4b38c75808d19ef71dc83a6 100644 (file)
@@ -150,9 +150,6 @@ Builder::Builder(int argc, char **argv):
                        cmdline_targets.push_back(*i);
        }
 
-       if(cmdline_targets.empty())
-               cmdline_targets.push_back("default");
-
        if(!work_dir.empty())
                FS::chdir(work_dir);
 
@@ -351,8 +348,7 @@ bool Builder::prepare_build()
 {
        package_manager.get_main_package().prepare();
 
-       // Make the cmdline target depend on all targets mentioned on the command line
-       Target *cmdline = new VirtualTarget(*this, "cmdline");
+       // Add targets from command line as goals
        for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i)
        {
                Target *tgt = build_graph.get_target(*i);
@@ -366,10 +362,10 @@ bool Builder::prepare_build()
                        return false;
                }
 
-               cmdline->add_dependency(*tgt);
+               build_graph.add_goal(*tgt);
        }
 
-       cmdline->prepare();
+       build_graph.prepare();
 
        // Apply what-ifs
        for(NameList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
@@ -384,11 +380,7 @@ bool Builder::prepare_build()
        }
 
        if(build_all)
-       {
-               for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
-                       if(i->second->is_buildable() && !i->second->needs_rebuild())
-                               i->second->force_rebuild();
-       }
+               build_graph.force_full_rebuild();
 
        if(!dry_run)
        {
@@ -402,13 +394,7 @@ bool Builder::prepare_build()
 
 int Builder::do_build()
 {
-       Target *cmdline = build_graph.get_target("cmdline");
-
-       unsigned total = 0;
-       const BuildGraph::TargetMap &targets = build_graph.get_targets();
-       for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->is_buildable() && i->second->needs_rebuild())
-                       ++total;
+       unsigned total = build_graph.count_rebuild_targets();
 
        if(!total)
        {
@@ -429,7 +415,7 @@ int Builder::do_build()
        {
                if(tasks.size()<jobs && !fail && !starved)
                {
-                       Target *tgt = cmdline->get_buildable_target();
+                       Target *tgt = build_graph.get_buildable_target();
                        if(tgt)
                        {
                                if(tgt->get_tool())
index 8c0ff1272507a7336bfaee32461f4b83e5eaace7..94b5ed6ffd2dcfe578249dc2739a39c2a0014191 100644 (file)
@@ -8,7 +8,8 @@
 using namespace std;
 
 BuildGraph::BuildGraph(Builder &b):
-       builder(b)
+       builder(b),
+       goals(new VirtualTarget(builder, "goals"))
 {
        Target *world = new VirtualTarget(builder, "world");
        world->add_dependency(*new VirtualTarget(builder, "default"));
@@ -53,3 +54,36 @@ void BuildGraph::add_installed_target(Target &t)
                inst_tgt = builder.get_toolchain().get_tool("CP").create_target(t);
        get_target("install")->add_dependency(*inst_tgt);
 }
+
+void BuildGraph::add_goal(Target &t)
+{
+       goals->add_dependency(t);
+}
+
+void BuildGraph::prepare()
+{
+       if(goals->get_dependencies().empty())
+               add_goal(*get_target("default"));
+       goals->prepare();
+}
+
+void BuildGraph::force_full_rebuild()
+{
+       for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
+               if(i->second->is_buildable() && !i->second->needs_rebuild())
+                       i->second->force_rebuild();
+}
+
+unsigned BuildGraph::count_rebuild_targets() const
+{
+       unsigned count = 0;
+       for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+               if(i->second->is_buildable() && i->second->needs_rebuild())
+                       ++count;
+       return count;
+}
+
+Target *BuildGraph::get_buildable_target() const
+{
+       return goals->get_buildable_target();
+}
index 54409c0c061c648c8bb2c5e9c44f9ba6f201425d..e702b51eb765328da30773c4c4c40943235d6835 100644 (file)
@@ -17,6 +17,7 @@ public:
 private:
        Builder &builder;
        TargetMap targets;
+       Target *goals;
 
 public:
        BuildGraph(Builder &);
@@ -40,6 +41,28 @@ public:
        /** Adds a target that will be installed.  A new InstalledFile target is
        created and added as a dependency to the "install" virtual target. */
        void add_installed_target(Target &);
+
+       /** Adds a target as a toplevel goal.  These are stored as dependencies of
+       the "goals" virtual target. */
+       void add_goal(Target &);
+
+       Target &get_goals() const { return *goals; }
+
+       /** Prepares all toplevel goals for building.  If no goals are defined, the
+       "default" target is added as a goal. */
+       void prepare();
+
+       /** Marks all buildable targets to be rebuilt.  The graph must be prepared
+       first. */
+       void force_full_rebuild();
+
+       /** Returns the number of targets that are going to be rebuilt.  The graph
+       must be prepared first. */
+       unsigned count_rebuild_targets() const;
+
+       /** Returns a target that can be built and is needed for building the goal
+       targets.  Null */
+       Target *get_buildable_target() const;
 };
 
 #endif