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