1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
4 #include <msp/strings/utils.h>
5 #include <msp/time/utils.h>
7 #include "filetarget.h"
8 #include "sourcepackage.h"
14 FileTarget::FileTarget(Builder &b, const FS::Path &a):
15 Target(b, generate_name(b, 0, a)),
21 FileTarget::FileTarget(Builder &b, const SourcePackage &p, const FS::Path &a):
22 Target(b, generate_name(b, &p, a)),
28 void FileTarget::init(const SourcePackage *p)
33 builder.get_vfs().register_path(path, this);
38 void FileTarget::stat()
40 if(FS::Stat st = FS::lstat(path))
42 mtime = st.get_modify_time();
47 string FileTarget::generate_name(Builder &builder, const SourcePackage *pkg, const FS::Path &path)
49 if(pkg && FS::descendant_depth(path, pkg->get_source_directory())>=0)
51 FS::Path relpath = FS::relative(path, pkg->get_source_directory());
52 return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
54 else if(FS::descendant_depth(path, builder.get_prefix())>=0)
56 FS::Path relpath = FS::relative(path, builder.get_prefix());
57 return "<prefix>"+relpath.str().substr(1);
63 void FileTarget::touch()
66 signal_bubble_rebuild.emit();
69 void FileTarget::check_rebuild()
75 mark_rebuild("Does not exist");
78 for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
80 FileTarget *ft = dynamic_cast<FileTarget *>(*i);
81 if(ft && ft->get_mtime()>mtime)
82 mark_rebuild((*i)->get_name()+" has changed");
83 else if((*i)->needs_rebuild())
84 mark_rebuild((*i)->get_name()+" needs rebuilding");
88 if(!needs_rebuild() && package)
90 if(package->get_config().get_mtime()>mtime)
91 mark_rebuild("Package options changed");
93 string build_sig = create_build_signature();
94 if(package->get_cache().has_key(this, "build_sig"))
96 if(package->get_cache().get_value(this, "build_sig")!=build_sig)
97 mark_rebuild("Build signature changed");
102 string FileTarget::create_build_signature() const
107 const BuildInfo &binfo = (component ? component->get_build_info() : package->get_build_info());
108 return tool->create_build_signature(binfo);
111 Task *FileTarget::build()
113 if(tool && !builder.get_dry_run() && mtime)
116 return Target::build();
119 void FileTarget::build_finished(bool success)
126 string build_sig = create_build_signature();
127 if(!build_sig.empty())
128 package->get_cache().set_value(this, "build_sig", build_sig);
132 Target::build_finished(success);