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"
15 FileTarget::FileTarget(Builder &b, const FS::Path &a):
16 Target(b, generate_name(b, 0, a)),
22 FileTarget::FileTarget(Builder &b, const SourcePackage &p, const FS::Path &a):
23 Target(b, generate_name(b, &p, a)),
29 void FileTarget::init(const SourcePackage *p)
34 builder.get_vfs().register_path(path, this);
39 void FileTarget::stat()
41 if(FS::Stat st = FS::lstat(path))
43 mtime = st.get_modify_time();
48 string FileTarget::generate_name(Builder &builder, const SourcePackage *pkg, const FS::Path &path)
50 if(pkg && FS::descendant_depth(path, pkg->get_source_directory())>=0)
52 FS::Path relpath = FS::relative(path, pkg->get_source_directory());
53 return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
55 else if(FS::descendant_depth(path, builder.get_prefix())>=0)
57 FS::Path relpath = FS::relative(path, builder.get_prefix());
58 return "<prefix>"+relpath.str().substr(1);
64 void FileTarget::touch()
68 signal_bubble_rebuild.emit();
71 void FileTarget::check_rebuild()
73 if(!tool || needs_rebuild())
77 mark_rebuild("Does not exist");
80 for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
82 FileTarget *ft = dynamic_cast<FileTarget *>(*i);
83 if(ft && ft->get_mtime()>mtime)
84 mark_rebuild((*i)->get_name()+" has changed");
85 else if((*i)->needs_rebuild())
86 mark_rebuild((*i)->get_name()+" needs rebuilding");
92 // Some side effects might not exist
93 for(Dependencies::iterator i=side_effects.begin(); (i!=side_effects.end() && !needs_rebuild()); ++i)
94 if((*i)->needs_rebuild())
95 mark_rebuild((*i)->get_name()+" needs rebuilding");
98 if(!needs_rebuild() && package)
100 if(package->get_config().get_mtime()>mtime)
101 mark_rebuild("Package options changed");
103 if(tool->get_executable())
105 string build_sig = create_build_signature();
106 if(package->get_cache().has_key(this, "build_sig"))
108 if(package->get_cache().get_value(this, "build_sig")!=build_sig)
109 mark_rebuild("Build signature changed");
115 string FileTarget::create_build_signature() const
120 const BuildInfo &binfo = (component ? component->get_build_info() : package->get_build_info());
121 return tool->create_build_signature(binfo);
124 void FileTarget::build(Task &task)
127 task.set_unlink(true);
130 void FileTarget::build_finished(bool success)
137 string build_sig = create_build_signature();
138 if(!build_sig.empty())
139 package->get_cache().set_value(this, "build_sig", build_sig);
143 Target::build_finished(success);
146 void FileTarget::clean()
151 mtime = Time::TimeStamp();