1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
4 #include "filetarget.h"
13 Target::Target(Builder &b, const string &n):
21 builder.add_target(this);
24 Target *Target::get_buildable_target()
29 bool self_ok = state!=BUILDING;
30 for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
32 Target *tgt = (*i)->get_buildable_target();
35 else if((*i)->needs_rebuild())
45 void Target::set_tool(const Tool &t)
50 void Target::force_rebuild()
53 throw logic_error("Target::force_rebuild");
54 mark_rebuild("Forced rebuild");
57 void Target::add_depend(Target *dep)
60 throw invalid_argument("Target::add_depend");
61 depends.push_back(dep);
62 dep->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild));
65 void Target::prepare()
71 builder.problem((package ? package->get_name() : string()), "Dependency cycle detected at "+name);
78 for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
94 // XXX Minor breach of OO here
95 if(FileTarget *ft = dynamic_cast<FileTarget *>(this))
96 if(!builder.get_dry_run() && FS::exists(ft->get_path()))
97 FS::unlink(ft->get_path());
99 Task *task = tool->run(*this);
100 task->signal_finished.connect(sigc::mem_fun(this, &Target::build_finished));
106 void Target::mark_rebuild(const std::string &reason)
109 throw invalid_argument("No reason given for rebuilding "+name);
112 rebuild_reason = reason;
113 signal_bubble_rebuild.emit();
116 void Target::build_finished(bool /*success*/)