]> git.tdb.fi Git - builder.git/blobdiff - source/target.cpp
Make BuildInfo able to handle chained dependencies
[builder.git] / source / target.cpp
index 0760f531d8a91af342d6e4cc13c3e20bc0eab2f8..6653c11fb0b90e0e3e916a63b7a74548c259daab 100644 (file)
@@ -1,17 +1,11 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
-#include "action.h"
 #include "builder.h"
 #include "filetarget.h"
 #include "package.h"
 #include "target.h"
+#include "task.h"
+#include "tool.h"
 
 using namespace std;
 using namespace Msp;
@@ -20,13 +14,16 @@ Target::Target(Builder &b, const Package *p, const string &n):
        builder(b),
        package(p),
        name(n),
+       tool(0),
        buildable(false),
        building(false),
        rebuild(false),
        deps_ready(false),
        preparing(false),
        prepared(false)
-{ }
+{
+       builder.add_target(this);
+}
 
 Target *Target::get_buildable_target()
 {
@@ -34,7 +31,7 @@ Target *Target::get_buildable_target()
                return 0;
 
        bool self_ok = !building;
-       for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
        {
                Target *tgt = (*i)->get_buildable_target();
                if(tgt)
@@ -49,10 +46,15 @@ Target *Target::get_buildable_target()
        return 0;
 }
 
+void Target::set_tool(const Tool &t)
+{
+       tool = &t;
+}
+
 void Target::add_depend(Target *dep)
 {
        if(dep==this)
-               throw InvalidParameterValue("A target can't depend on itself");
+               throw invalid_argument("Target::add_depend");
        depends.push_back(dep);
 }
 
@@ -67,7 +69,7 @@ void Target::prepare()
        }
 
        preparing = true;
-       for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
                (*i)->prepare();
 
        check_rebuild();
@@ -75,28 +77,26 @@ void Target::prepare()
        prepared = true;
 }
 
-Action *Target::build()
+Task *Target::build()
 {
        if(!buildable)
        {
                rebuild = false;
                return 0;
        }
+       if(!tool)
+               throw logic_error("buildable && !tool");
 
        // XXX Minor breach of OO here
        if(FileTarget *ft = dynamic_cast<FileTarget *>(this))
                if(!builder.get_dry_run() && FS::exists(ft->get_path()))
                        FS::unlink(ft->get_path());
 
-       Action *action = create_action();
-       if(action)
-       {
-               action->signal_done.connect(sigc::mem_fun(this, &Target::build_done));
-
-               building = true;
-       }
+       Task *task = tool->run(*this);
+       task->signal_finished.connect(sigc::mem_fun(this, &Target::build_finished));
+       building = true;
 
-       return action;
+       return task;
 }
 
 void Target::mark_rebuild(const std::string &reason)
@@ -105,7 +105,7 @@ void Target::mark_rebuild(const std::string &reason)
        rebuild_reason = reason;
 }
 
-void Target::build_done()
+void Target::build_finished(bool /*success*/)
 {
        building = false;
        rebuild = false;