2 #include "buildgraph.h"
4 #include "sourcepackage.h"
6 #include "virtualtarget.h"
10 BuildGraph::BuildGraph(Builder &b):
12 goals(new VirtualTarget(builder, "goals"))
14 Target *world = new VirtualTarget(builder, "world");
15 world->add_dependency(*new VirtualTarget(builder, "default"));
16 world->add_dependency(*new VirtualTarget(builder, "install"));
17 world->add_dependency(*new VirtualTarget(builder, "archives"));
20 BuildGraph::~BuildGraph()
22 for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
26 Target *BuildGraph::get_target(const string &n) const
28 TargetMap::const_iterator i = targets.find(n);
34 void BuildGraph::add_target(Target *t)
36 targets.insert(TargetMap::value_type(t->get_name(), t));
39 void BuildGraph::add_primary_target(Target &t)
41 get_target("world")->add_dependency(t);
43 Package *main_pkg = &builder.get_package_manager().get_main_package();
44 if(t.get_package()==main_pkg && t.get_component() && t.get_component()->is_default())
45 get_target("default")->add_dependency(t);
48 void BuildGraph::add_installed_target(Target &t)
51 if(const Tool *tool = t.get_tool())
52 inst_tgt = tool->create_install(t);
54 inst_tgt = builder.get_toolchain().get_tool("CP").create_target(t);
55 get_target("install")->add_dependency(*inst_tgt);
58 void BuildGraph::add_goal(Target &t)
60 goals->add_dependency(t);
63 void BuildGraph::prepare()
65 if(goals->get_dependencies().empty())
66 add_goal(*get_target("default"));
70 void BuildGraph::force_full_rebuild()
72 for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
73 if(i->second->is_buildable() && !i->second->needs_rebuild())
74 i->second->force_rebuild();
77 unsigned BuildGraph::count_rebuild_targets() const
80 for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
81 if(i->second->is_buildable() && i->second->needs_rebuild())
86 Target *BuildGraph::get_buildable_target() const
88 return goals->get_buildable_target();