X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffiletarget.cpp;h=7ba81b28cf5a626340c3a9de707b23846c9688d1;hb=af2dac0d09df4782060dd131f2a761e8a46a8d55;hp=08b0f3115e984e25d30b73f6d2e21d5a5543236c;hpb=a40db37e1e681d397d4bfc6c893e15945c533b72;p=builder.git diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 08b0f31..7ba81b2 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -1,27 +1,62 @@ /* $Id$ This file is part of builder -Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ #include #include -#include "file.h" +#include +#include "builder.h" +#include "filetarget.h" +#include "sourcepackage.h" using namespace std; using namespace Msp; FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a): - // XXX Builder depends on target name being its path for locating file targets - Target(b, p, /*FS::basename*/(a.str())), + Target(b, p, FS::basename(a.str())), path(a), size(0) { + builder.add_target(this); + struct stat st; - if(!FS::stat(path, st)) + if(!FS::lstat(path, st)) { - mtime=Time::TimeStamp::from_unixtime(st.st_mtime); - size=st.st_size; + mtime = Time::TimeStamp::from_unixtime(st.st_mtime); + size = st.st_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 + { + for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i) + { + FileTarget *ft = dynamic_cast(*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"); + } + } + + const SourcePackage *spkg = dynamic_cast(package); + if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime) + mark_rebuild("Package options changed"); +}