mark_rebuild("Does not exist");
else
{
- for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
+ for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
{
FileTarget *ft = dynamic_cast<FileTarget *>(*i);
if(ft && ft->get_mtime()>mtime)
}
const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
- if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
+ if(!needs_rebuild() && spkg && spkg->get_config().get_mtime()>mtime)
mark_rebuild("Package options changed");
}
package(p),
name(n),
tool(0),
- building(false),
- rebuild(false),
- deps_ready(false),
- preparing(false),
- prepared(false)
+ 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;
+ bool self_ok = state!=BUILDING;
for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
{
Target *tgt = (*i)->get_buildable_target();
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;
+ 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;
}
Task *Target::build()
{
if(!tool)
{
- rebuild = false;
+ state = UPTODATE;
return 0;
}
Task *task = tool->run(*this);
task->signal_finished.connect(sigc::mem_fun(this, &Target::build_finished));
- building = true;
+ state = BUILDING;
return task;
}
void Target::mark_rebuild(const std::string &reason)
{
- rebuild = true;
+ state = REBUILD;
rebuild_reason = reason;
}
void Target::build_finished(bool /*success*/)
{
- building = false;
- rebuild = false;
+ state = UPTODATE;
}
typedef std::list<Target *> Dependencies;
protected:
+ enum State
+ {
+ INIT,
+ PREPARING,
+ REBUILD,
+ BUILDING,
+ UPTODATE
+ };
+
Builder &builder;
const Package *package;
std::string name;
const Tool *tool;
- bool building;
- bool rebuild;
+ State state;
std::string rebuild_reason;
std::string install_location;
Dependencies depends;
bool deps_ready;
- bool preparing;
- bool prepared;
-
Target(Builder &, const Package *, const std::string &);
public:
virtual ~Target() { }
const Tool *get_tool() const { return tool; }
bool is_buildable() const { return tool!=0; }
- bool needs_rebuild() const { return rebuild; }
+ bool needs_rebuild() const { return state>PREPARING && state<UPTODATE; }
const std::string &get_rebuild_reason() const { return rebuild_reason; }
bool is_installable() const { return !install_location.empty(); }
const std::string &get_install_location() const { return install_location; }
void VirtualTarget::check_rebuild()
{
// Virtual targets are only rebuilt if their dependencies need rebuilding.
- for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
+ for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
if((*i)->needs_rebuild())
mark_rebuild((*i)->get_name()+" needs rebuilding");
}