]> git.tdb.fi Git - builder.git/blob - source/buildgraph.h
Remove most container typedefs and refactor others
[builder.git] / source / buildgraph.h
1 #ifndef BUILDGRAPH_H_
2 #define BUILDGRAPH_H_
3
4 #include <map>
5 #include <string>
6
7 class Builder;
8 class Target;
9
10 /**
11 Manages a graph of targets.
12 */
13 class BuildGraph
14 {
15 private:
16         Builder &builder;
17         std::map<std::string, Target *> targets;
18         Target *goals;
19
20 public:
21         BuildGraph(Builder &);
22         ~BuildGraph();
23
24         /** Looks up a target by name.  Returns 0 if no such target exists. */
25         Target *get_target(const std::string &) const;
26
27         const std::map<std::string, Target *> &get_targets() const { return targets; }
28
29         /** Adds a target.  It can later be retrieved by name.  Called from Target
30         constructor. */
31         void add_target(Target *);
32
33         /** Adds a target that is a primary build goal.  Such targets will be added
34         as dependencies of the "world" virtual target.  If the target belongs to a
35         default component of the main package, it's also added to the "default"
36         virtual target. */
37         void add_primary_target(Target &);
38
39         /** Adds a target that will be installed.  A new InstalledFile target is
40         created and added as a dependency to the "install" virtual target. */
41         void add_installed_target(Target &);
42
43         /** Adds a target as a toplevel goal.  These are stored as dependencies of
44         the "goals" virtual target. */
45         void add_goal(Target &);
46
47         Target &get_goals() const { return *goals; }
48
49         /** Prepares all toplevel goals for building.  If no goals are defined, the
50         "default" target is added as a goal. */
51         void prepare();
52
53         /** Marks all buildable targets to be rebuilt.  The graph must be prepared
54         first. */
55         void force_full_rebuild();
56
57         /** Returns the number of targets that are going to be rebuilt.  The graph
58         must be prepared first. */
59         unsigned count_rebuild_targets() const;
60
61         /** Returns a target that can be built and is needed for building the goal
62         targets.  Null */
63         Target *get_buildable_target() const;
64 };
65
66 #endif