X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftarget.cpp;h=7c6141df7403b1978ccd32f8fdfa6ce911c10f74;hb=40177b0cfc0d4e67f971941f632e4f1f7e7c3f88;hp=bfb78672afb08e4e787236452b831b060a78632e;hpb=0458300fda4f345f865a7f3ee4fc0f2020a91983;p=builder.git diff --git a/source/target.cpp b/source/target.cpp index bfb7867..7c6141d 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -1,17 +1,11 @@ -/* $Id$ - -This file is part of builder -Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include -#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,26 +14,25 @@ Target::Target(Builder &b, const Package *p, const string &n): builder(b), package(p), name(n), - buildable(false), - building(false), - rebuild(false), - deps_ready(false), - preparing(false), - prepared(false) -{ } + tool(0), + state(INIT), + deps_ready(false) +{ + builder.add_target(this); +} Target *Target::get_buildable_target() { - if(!rebuild) + if(!needs_rebuild()) return 0; - bool self_ok = !building; - for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i) + bool self_ok = state!=BUILDING; + for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i) { Target *tgt = (*i)->get_buildable_target(); if(tgt) return tgt; - else if((*i)->get_rebuild()) + else if((*i)->needs_rebuild()) self_ok = false; } @@ -49,6 +42,11 @@ 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) @@ -58,28 +56,28 @@ void Target::add_depend(Target *dep) void Target::prepare() { - if(prepared) + if(state>PREPARING) return; - if(preparing) + if(state==PREPARING) { builder.problem((package ? package->get_name() : string()), "Dependency cycle detected at "+name); return; } - preparing = true; - for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i) + state = PREPARING; + for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i) (*i)->prepare(); check_rebuild(); - preparing = false; - prepared = true; + if(state==PREPARING) + state = UPTODATE; } -Action *Target::build() +Task *Target::build() { - if(!buildable) + if(!tool) { - rebuild = false; + state = UPTODATE; return 0; } @@ -88,25 +86,20 @@ Action *Target::build() 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)); + state = BUILDING; - return action; + return task; } void Target::mark_rebuild(const std::string &reason) { - rebuild = true; + state = REBUILD; rebuild_reason = reason; } -void Target::build_done() +void Target::build_finished(bool /*success*/) { - building = false; - rebuild = false; + state = UPTODATE; }