1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
4 #include <msp/time/utils.h>
6 #include "filetarget.h"
7 #include "sourcepackage.h"
12 FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a):
13 Target(b, generate_name(p, a)),
19 builder.get_vfs().register_path(path, this);
21 if(FS::Stat st = FS::lstat(path))
23 mtime = st.get_modify_time();
28 void FileTarget::touch()
31 signal_bubble_rebuild.emit();
34 void FileTarget::check_rebuild()
40 mark_rebuild("Does not exist");
43 for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
45 FileTarget *ft = dynamic_cast<FileTarget *>(*i);
46 if(ft && ft->get_mtime()>mtime)
47 mark_rebuild((*i)->get_name()+" has changed");
48 else if((*i)->needs_rebuild())
49 mark_rebuild((*i)->get_name()+" needs rebuilding");
53 const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
54 if(!needs_rebuild() && spkg && spkg->get_config().get_mtime()>mtime)
55 mark_rebuild("Package options changed");
58 string FileTarget::generate_name(const Package *pkg, const FS::Path &pth)
60 if(const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(pkg))
62 if(FS::descendant_depth(pth, spkg->get_source())>=0)
64 FS::Path relpath = FS::relative(pth, spkg->get_source());
65 return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
67 else if(FS::descendant_depth(pth, pkg->get_builder().get_prefix())>=0)
69 FS::Path relpath = FS::relative(pth, pkg->get_builder().get_prefix());
70 return "<prefix>"+relpath.str().substr(1);