1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
5 #include "filetarget.h"
14 Target::Target(Builder &b, const string &n):
22 builder.add_target(this);
25 Target *Target::get_buildable_target()
30 bool self_ok = state!=BUILDING;
31 for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
33 Target *tgt = (*i)->get_buildable_target();
36 else if((*i)->needs_rebuild())
46 void Target::set_tool(const Tool &t)
51 void Target::force_rebuild()
54 throw logic_error("Target::force_rebuild");
55 mark_rebuild("Forced rebuild");
58 void Target::add_depend(Target *dep)
61 throw invalid_argument("Target::add_depend");
62 depends.push_back(dep);
63 dep->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild));
66 void Target::prepare()
72 builder.problem((package ? package->get_name() : string()), "Dependency cycle detected at "+name);
80 if(FileTarget *tool_exe = tool->get_executable())
84 for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
100 // XXX Minor breach of OO here
101 if(FileTarget *ft = dynamic_cast<FileTarget *>(this))
102 if(!builder.get_dry_run() && FS::exists(ft->get_path()))
103 FS::unlink(ft->get_path());
105 Task *task = tool->run(*this);
106 task->signal_finished.connect(sigc::mem_fun(this, &Target::build_finished));
112 void Target::mark_rebuild(const std::string &reason)
115 throw invalid_argument("No reason given for rebuilding "+name);
118 rebuild_reason = reason;
119 signal_bubble_rebuild.emit();
121 builder.get_logger().log("rebuild", format("Rebuilding %s: %s", name, reason));
124 void Target::build_finished(bool /*success*/)