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(const auto &kvp: targets)
26 Target *BuildGraph::get_target(const string &n) const
28 auto i = targets.find(n);
34 void BuildGraph::add_target(Target *t)
36 targets.insert({ 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_staged_target(Target &t)
60 builder.get_toolchain().get_tool("CP").create_target(t, "//");
63 void BuildGraph::add_goal(Target &t)
65 goals->add_dependency(t);
68 void BuildGraph::prepare()
70 if(goals->get_dependencies().empty())
71 add_goal(*get_target("default"));
75 void BuildGraph::force_full_rebuild()
77 for(const auto &kvp: targets)
78 if(kvp.second->is_buildable() && !kvp.second->needs_rebuild())
79 kvp.second->force_rebuild();
82 unsigned BuildGraph::count_rebuild_targets() const
85 for(const auto &kvp: targets)
86 if(kvp.second->is_buildable() && kvp.second->needs_rebuild())
91 Target *BuildGraph::get_buildable_target() const
93 return goals->get_buildable_target();