From 25900e0f84f72de6208f30529f9bcaae11570f8f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 1 May 2012 14:22:09 +0300 Subject: [PATCH] Consolidate various target state variables into a single state --- source/filetarget.cpp | 4 ++-- source/target.cpp | 30 +++++++++++++----------------- source/target.h | 17 +++++++++++------ source/virtualtarget.cpp | 2 +- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/source/filetarget.cpp b/source/filetarget.cpp index f04e310..decb4bf 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -39,7 +39,7 @@ void FileTarget::check_rebuild() 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(*i); if(ft && ft->get_mtime()>mtime) @@ -56,7 +56,7 @@ void FileTarget::check_rebuild() } const SourcePackage *spkg = dynamic_cast(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"); } diff --git a/source/target.cpp b/source/target.cpp index 65d801f..7c6141d 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -15,21 +15,18 @@ Target::Target(Builder &b, const Package *p, const string &n): 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(); @@ -59,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; + 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; } @@ -91,19 +88,18 @@ Task *Target::build() 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; } diff --git a/source/target.h b/source/target.h index 2c14ea1..04c3c09 100644 --- a/source/target.h +++ b/source/target.h @@ -24,22 +24,27 @@ public: typedef std::list 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() { } @@ -67,7 +72,7 @@ public: 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 && stateneeds_rebuild()) mark_rebuild((*i)->get_name()+" needs rebuilding"); } -- 2.43.0