]> git.tdb.fi Git - builder.git/blobdiff - source/filetarget.cpp
Replace per-file copyright notices with a single file
[builder.git] / source / filetarget.cpp
index 8f35cfc9ed3b54f776f30159ab7e909fb5ed4843..d6dcd1681c4d589cdb7976279e7acfdc032dd46c 100644 (file)
@@ -1,14 +1,9 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
+#include <msp/time/utils.h>
 #include "builder.h"
 #include "filetarget.h"
+#include "sourcepackage.h"
 
 using namespace std;
 using namespace Msp;
@@ -20,10 +15,46 @@ FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a):
 {
        builder.add_target(this);
 
-       struct stat st;
-       if(!FS::stat(path, st))
+       if(FS::Stat st = FS::lstat(path))
+       {
+               mtime = st.get_modify_time();
+               size = st.get_size();
+       }
+}
+
+void FileTarget::touch()
+{
+       mtime = Time::now();
+}
+
+void FileTarget::check_rebuild()
+{
+       if(!buildable)
+               return;
+
+       if(builder.get_build_all())
+               mark_rebuild("Rebuilding everything");
+       else if(!mtime)
+               mark_rebuild("Does not exist");
+       else
        {
-               mtime = Time::TimeStamp::from_unixtime(st.st_mtime);
-               size = st.st_size;
+               for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
+               {
+                       FileTarget *ft = dynamic_cast<FileTarget *>(*i);
+                       if(ft && ft->get_mtime()>mtime)
+                               mark_rebuild((*i)->get_name()+" has changed");
+                       else if((*i)->get_rebuild())
+                               mark_rebuild((*i)->get_name()+" needs rebuilding");
+                       else
+                       {
+                               Target *real = ft->get_real_target();
+                               if(real->get_rebuild())
+                                       mark_rebuild(real->get_name()+" needs rebuilding");
+                       }
+               }
        }
+
+       const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
+       if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
+               mark_rebuild("Package options changed");
 }