]> git.tdb.fi Git - builder.git/commitdiff
Consolidate various target state variables into a single state
authorMikko Rasa <tdb@tdb.fi>
Tue, 1 May 2012 11:22:09 +0000 (14:22 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:50 +0000 (00:08 +0300)
source/filetarget.cpp
source/target.cpp
source/target.h
source/virtualtarget.cpp

index f04e3101281d4a8f9cb10791503591c3a7caf0cb..decb4bf793d68015066e1dede84f044e340ae836 100644 (file)
@@ -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<FileTarget *>(*i);
                        if(ft && ft->get_mtime()>mtime)
@@ -56,7 +56,7 @@ void FileTarget::check_rebuild()
        }
 
        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");
 }
 
index 65d801f91421a3544d6f077f9683f40032ce7d3f..7c6141df7403b1978ccd32f8fdfa6ce911c10f74 100644 (file)
@@ -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;
 }
index 2c14ea1ae3064ef394e0bcff951dafddf8360b61..04c3c09a3648876578e8b7e7794e64bb3e9b6bd5 100644 (file)
@@ -24,22 +24,27 @@ public:
        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() { }
@@ -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 && 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; }
index 5d388ded5e5393202a4b947f9560cbeb6aac012d..82abc90734056778c73cce68e2a39d6645d1cb1d 100644 (file)
@@ -13,7 +13,7 @@ VirtualTarget::VirtualTarget(Builder &b, const string &n):
 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");
 }