]> git.tdb.fi Git - builder.git/blob - source/lib/buildgraph.cpp
Install headers of non-installed components in a staging directory
[builder.git] / source / lib / buildgraph.cpp
1 #include "builder.h"
2 #include "buildgraph.h"
3 #include "component.h"
4 #include "sourcepackage.h"
5 #include "tool.h"
6 #include "virtualtarget.h"
7
8 using namespace std;
9
10 BuildGraph::BuildGraph(Builder &b):
11         builder(b),
12         goals(new VirtualTarget(builder, "goals"))
13 {
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"));
18 }
19
20 BuildGraph::~BuildGraph()
21 {
22         for(const auto &kvp: targets)
23                 delete kvp.second;
24 }
25
26 Target *BuildGraph::get_target(const string &n) const
27 {
28         auto i = targets.find(n);
29         if(i!=targets.end())
30                 return i->second;
31         return 0;
32 }
33
34 void BuildGraph::add_target(Target *t)
35 {
36         targets.insert({ t->get_name(), t });
37 }
38
39 void BuildGraph::add_primary_target(Target &t)
40 {
41         get_target("world")->add_dependency(t);
42
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);
46 }
47
48 void BuildGraph::add_installed_target(Target &t)
49 {
50         Target *inst_tgt = 0;
51         if(const Tool *tool = t.get_tool())
52                 inst_tgt = tool->create_install(t);
53         if(!inst_tgt)
54                 inst_tgt = builder.get_toolchain().get_tool("CP").create_target(t);
55         get_target("install")->add_dependency(*inst_tgt);
56 }
57
58 void BuildGraph::add_staged_target(Target &t)
59 {
60         builder.get_toolchain().get_tool("CP").create_target(t, "//");
61 }
62
63 void BuildGraph::add_goal(Target &t)
64 {
65         goals->add_dependency(t);
66 }
67
68 void BuildGraph::prepare()
69 {
70         if(goals->get_dependencies().empty())
71                 add_goal(*get_target("default"));
72         goals->prepare();
73 }
74
75 void BuildGraph::force_full_rebuild()
76 {
77         for(const auto &kvp: targets)
78                 if(kvp.second->is_buildable() && !kvp.second->needs_rebuild())
79                         kvp.second->force_rebuild();
80 }
81
82 unsigned BuildGraph::count_rebuild_targets() const
83 {
84         unsigned count = 0;
85         for(const auto &kvp: targets)
86                 if(kvp.second->is_buildable() && kvp.second->needs_rebuild())
87                         ++count;
88         return count;
89 }
90
91 Target *BuildGraph::get_buildable_target() const
92 {
93         return goals->get_buildable_target();
94 }