1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
3 #include <msp/strings/format.h>
5 #include "filetarget.h"
6 #include "sourcepackage.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);
64 dep.signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild));
67 void Target::prepare()
73 builder.problem((package ? package->get_name() : string()), "Dependency cycle detected at "+name);
81 if(FileTarget *tool_exe = tool->get_executable())
82 add_depend(*tool_exe);
85 for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
92 for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
93 (*i)->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild));
100 // This special case is needed for VirtualTargets
105 // XXX Minor breach of OO here
106 if(FileTarget *ft = dynamic_cast<FileTarget *>(this))
107 if(!builder.get_dry_run() && FS::exists(ft->get_path()))
108 FS::unlink(ft->get_path());
110 Task *task = tool->run(*this);
111 task->signal_finished.connect(sigc::mem_fun(this, &Target::build_finished));
117 void Target::mark_rebuild(const string &reason)
120 throw invalid_argument("No reason given for rebuilding "+name);
123 rebuild_reason = reason;
125 builder.get_logger().log("rebuild", format("Rebuilding %s: %s", name, reason));
127 signal_bubble_rebuild.emit();
130 void Target::build_finished(bool /*success*/)