]> git.tdb.fi Git - builder.git/blob - source/target.h
Rename Target::get_rebuild to needs_rebuild
[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 Builder;
11 class Package;
12 class Task;
13 class Tool;
14
15 class Target;
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 public:
24         typedef std::list<Target *> Dependencies;
25
26 protected:
27         Builder &builder;
28         const Package *package;
29         std::string name;
30
31         const Tool *tool;
32         bool building;
33         bool rebuild;
34         std::string rebuild_reason;
35         std::string install_location;
36
37         Dependencies depends;
38         bool deps_ready;
39
40         bool preparing;
41         bool prepared;
42
43         Target(Builder &, const Package *, const std::string &);
44 public:
45         virtual ~Target() { }
46
47         virtual const char *get_type() const = 0;
48         const std::string &get_name() const { return name; }
49         const Package *get_package() const { return package; }
50
51         /**
52         Tries to locate a target that will help getting this target built.  If all
53         dependencies are up-to-date, returns this target.  If there are no targets
54         ready to be built (maybe because they are being built right now), returns 0.
55         */
56         virtual Target *get_buildable_target();
57
58         /**
59         If this target is a proxy for another (such as Install or Symlink), return
60         that target.  Otherwise, return the target itself.
61
62         Implementors should call the function recursively to find the final target.
63         */
64         virtual Target *get_real_target() { return this; }
65
66         void set_tool(const Tool &);
67         const Tool *get_tool() const { return tool; }
68
69         bool is_buildable() const { return tool!=0; }
70         bool needs_rebuild() const { return rebuild; }
71         const std::string &get_rebuild_reason() const { return rebuild_reason; }
72         bool is_installable() const { return !install_location.empty(); }
73         const std::string &get_install_location() const { return install_location; }
74         void add_depend(Target *);
75         const Dependencies &get_depends() const { return depends; }
76         bool get_depends_ready() const { return deps_ready; }
77
78         /**
79         Finds dependencies for the target.  When all dependencies have been found,
80         the function should set deps_ready to true.
81         */
82         virtual void find_depends() { deps_ready = true; }
83
84         /**
85         Prepares the target by recursively preparing dependencies, then checking
86         whether rebuilding is needed.  A flag is used to prevent unnecessary
87         executions.
88         */
89         virtual void prepare();
90
91         /**
92         Starts building the target.  Returns the Action used for building.
93         */
94         Task *build();
95 protected:
96         void mark_rebuild(const std::string &);
97
98         /**
99         Checks if the target needs to be rebuilt and why.
100         */
101         virtual void check_rebuild() = 0;
102
103         /**
104         Handler for the build_finished signal of Task.
105         */
106         virtual void build_finished(bool);
107 };
108
109 #endif