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()
39 if(builder.get_build_all())
40 mark_rebuild("Rebuilding everything");
42 mark_rebuild("Does not exist");
45 for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
47 FileTarget *ft = dynamic_cast<FileTarget *>(*i);
48 if(ft && ft->get_mtime()>mtime)
49 mark_rebuild((*i)->get_name()+" has changed");
50 else if((*i)->needs_rebuild())
51 mark_rebuild((*i)->get_name()+" needs rebuilding");
55 const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
56 if(!needs_rebuild() && spkg && spkg->get_config().get_mtime()>mtime)
57 mark_rebuild("Package options changed");
60 string FileTarget::generate_name(const Package *pkg, const FS::Path &pth)
62 if(const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(pkg))
64 if(FS::descendant_depth(pth, spkg->get_source())>=0)
66 FS::Path relpath = FS::relative(pth, spkg->get_source());
67 return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
69 else if(FS::descendant_depth(pth, pkg->get_builder().get_prefix())>=0)
71 FS::Path relpath = FS::relative(pth, pkg->get_builder().get_prefix());
72 return "<prefix>"+relpath.str().substr(1);