X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffiletarget.cpp;h=6626db8ded177b79ed8ecd1f0b8bd5a81f3bf456;hb=2f1e3b296bb8a2c4fcb73d7339cf7d0d6f9d1459;hp=ed3e66b7c3711577a6a5e620086eec18e506f063;hpb=66d1078c04849ec17a7343d0494d6ed087e04318;p=builder.git diff --git a/source/filetarget.cpp b/source/filetarget.cpp index ed3e66b..6626db8 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -1,23 +1,75 @@ -/* $Id$ - -This file is part of builder -Copyright © 2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include -#include "file.h" +#include +#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())), - path(a) + Target(b, generate_name(p, a)), + path(a), + size(0) +{ + package = p; + + builder.get_vfs().register_path(path, this); + + if(FS::Stat st = FS::lstat(path)) + { + mtime = st.get_modify_time(); + size = st.get_size(); + } +} + +void FileTarget::touch() +{ + mtime = Time::now(); + signal_bubble_rebuild.emit(); +} + +void FileTarget::check_rebuild() +{ + if(!tool) + return; + + if(!mtime) + mark_rebuild("Does not exist"); + else + { + for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i) + { + FileTarget *ft = dynamic_cast(*i); + if(ft && ft->get_mtime()>mtime) + mark_rebuild((*i)->get_name()+" has changed"); + else if((*i)->needs_rebuild()) + mark_rebuild((*i)->get_name()+" needs rebuilding"); + } + } + + const SourcePackage *spkg = dynamic_cast(package); + if(!needs_rebuild() && spkg && spkg->get_config().get_mtime()>mtime) + mark_rebuild("Package options changed"); +} + +string FileTarget::generate_name(const Package *pkg, const FS::Path &pth) { - struct stat st; - if(!FS::stat(path, st)) - mtime=Time::TimeStamp::from_unixtime(st.st_mtime); + if(const SourcePackage *spkg = dynamic_cast(pkg)) + { + if(FS::descendant_depth(pth, spkg->get_source())>=0) + { + FS::Path relpath = FS::relative(pth, spkg->get_source()); + return format("<%s>%s", pkg->get_name(), relpath.str().substr(1)); + } + else if(FS::descendant_depth(pth, pkg->get_builder().get_prefix())>=0) + { + FS::Path relpath = FS::relative(pth, pkg->get_builder().get_prefix()); + return ""+relpath.str().substr(1); + } + } + + return pth.str(); }