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