]> git.tdb.fi Git - builder.git/blobdiff - source/target.cpp
Always prepare cmdline to avoid some dependency hassle
[builder.git] / source / target.cpp
index b24013aaf55eabb094c72ef912480a956c6a9ae8..2005d25cfc55817792d47289a2c1c2dabb58ce9d 100644 (file)
@@ -10,6 +10,7 @@ Distributed under the LGPL
 #include <msp/time/utils.h>
 #include "action.h"
 #include "builder.h"
+#include "filetarget.h"
 #include "package.h"
 #include "sourcepackage.h"
 #include "target.h"
@@ -25,14 +26,10 @@ Target::Target(Builder &b, const Package *p, const string &n):
        building(false),
        rebuild(false),
        deps_ready(false),
-       prepared(false),
-       counted(false)
+       preparing(false),
+       prepared(false)
 {
        builder.add_target(this);
-
-       struct stat st;
-       if(!FS::stat(name, st))
-               mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
 }
 
 Target *Target::get_buildable_target()
@@ -68,13 +65,19 @@ void Target::prepare()
 {
        if(prepared)
                return;
+       if(preparing)
+       {
+               builder.problem((package ? package->get_name() : string()), "Dependency cycle detected at "+name);
+               return;
+       }
 
-       prepared=true;
+       preparing=true;
        for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
                (*i)->prepare();
 
        check_rebuild();
-
+       preparing=false;
+       prepared=true;
 }
 
 Action *Target::build()
@@ -85,8 +88,9 @@ Action *Target::build()
                return 0;
        }
 
-       if(!builder.get_dry_run() && FS::exists(name))
-               FS::unlink(name);
+       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)
@@ -99,18 +103,6 @@ Action *Target::build()
        return action;
 }
 
-unsigned Target::count_rebuild()
-{
-       if(counted)
-               return 0;
-
-       counted=true;
-       unsigned count=rebuild;
-       for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i)
-               count+=(*i)->count_rebuild();
-       return count;
-}
-
 void Target::touch()
 {
        mtime=Time::now();