]> git.tdb.fi Git - builder.git/blob - source/target.h
Move the TargetMap typedef inside Builder
[builder.git] / source / target.h
1 #ifndef TARGET_H_
2 #define TARGET_H_
3
4 #include <list>
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <msp/time/timestamp.h>
9
10 class Action;
11 class Builder;
12 class Package;
13
14 class Target;
15 typedef std::list<Target *> TargetList;
16
17 /**
18 Targets make up the build graph.  This class is a base for all target types and
19 handles many common tasks.  See also FileTarget and VirtualTarget.
20 */
21 class Target
22 {
23 protected:
24         Builder &builder;
25         const Package *package;
26         std::string name;
27
28         bool buildable;
29         bool building;
30         bool rebuild;
31         std::string rebuild_reason;
32
33         TargetList depends;
34         bool deps_ready;
35
36         bool preparing;
37         bool prepared;
38
39         Target(Builder &, const Package *, const std::string &);
40 public:
41         virtual ~Target() { }
42
43         virtual const char *get_type() const = 0;
44         const std::string &get_name() const { return name; }
45         const Package *get_package() const { return package; }
46
47         /**
48         Tries to locate a target that will help getting this target built.  If all
49         dependencies are up-to-date, returns this target.  If there are no targets
50         ready to be built (maybe because they are being built right now), returns 0.
51         */
52         virtual Target *get_buildable_target();
53
54         /**
55         If this target is a proxy for another (such as Install or Symlink), return
56         that target.  Otherwise, return the target itself.
57
58         Implementors should call the function recursively to find the final target.
59         */
60         virtual Target *get_real_target() { return this; }
61
62         bool is_buildable() const { return buildable; }
63         bool get_rebuild() const { return rebuild; }
64         const std::string &get_rebuild_reason() const { return rebuild_reason; }
65         void add_depend(Target *);
66         const TargetList &get_depends() const { return depends; }
67         bool get_depends_ready() const { return deps_ready; }
68
69         /**
70         Finds dependencies for the target.  When all dependencies have been found,
71         the function should set deps_ready to true.
72         */
73         virtual void find_depends() { deps_ready = true; }
74
75         /**
76         Prepares the target by recursively preparing dependencies, then checking
77         whether rebuilding is needed.  A flag is used to prevent unnecessary
78         executions.
79         */
80         virtual void prepare();
81
82         /**
83         Starts building the target.  Returns the Action used for building.
84         */
85         Action *build();
86 protected:
87         void mark_rebuild(const std::string &);
88
89         /**
90         Checks if the target needs to be rebuilt and why.
91         */
92         virtual void check_rebuild() = 0;
93
94         /**
95         Creates and returns an Action suitable for building this target.
96         */
97         virtual Action *create_action() =0;
98
99         /**
100         Handler for the build_done signal of Action.
101         */
102         virtual void build_done();
103 };
104
105 #endif