]> git.tdb.fi Git - builder.git/blob - source/target.h
Make install_location a path
[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 <sigc++/signal.h>
9 #include <msp/time/timestamp.h>
10
11 class Builder;
12 class Component;
13 class SourcePackage;
14 class Task;
15 class Tool;
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         enum State
28         {
29                 INIT,
30                 PREPARING,
31                 REBUILD,
32                 BUILDING,
33                 UPTODATE
34         };
35
36 public:
37         sigc::signal<void> signal_bubble_rebuild;
38
39 protected:
40         Builder &builder;
41         const SourcePackage *package;
42         const Component *component;
43         std::string name;
44
45         const Tool *tool;
46         State state;
47         std::string rebuild_reason;
48         Msp::FS::Path install_location;
49
50         Dependencies depends;
51
52         Target(Builder &, const std::string &);
53 public:
54         virtual ~Target() { }
55
56         virtual const char *get_type() const = 0;
57         const std::string &get_name() const { return name; }
58         const SourcePackage *get_package() const { return package; }
59         const Component *get_component() const { return component; }
60
61         /** Tries to locate a target that will help getting this target built.  If
62         all dependencies are up-to-date, returns this target.  If there are no
63         targets ready to be built (maybe because they are being built right now),
64         returns 0. */
65         virtual Target *get_buildable_target();
66
67         /** If this target is a proxy for another (such as Install), return that
68         target.  Otherwise, return the target itself.
69
70         Implementors should call the function recursively to find the final target. */
71         virtual Target *get_real_target() { return this; }
72
73         void set_tool(const Tool &);
74         const Tool *get_tool() const { return tool; }
75
76         /** Indicates if it's possible to build this target. */
77         bool is_buildable() const { return tool!=0; }
78
79         /** Indicates if this target needs rebuilding.  Only makes sense after the
80         target has been prepared. */
81         bool needs_rebuild() const { return state>PREPARING && state<UPTODATE; }
82
83         /** Returns the reason for rebuilding this target.  Only makes sense after
84         the target has been prepared. */
85         const std::string &get_rebuild_reason() const { return rebuild_reason; }
86
87         /** Forces rebuild of the target. */
88         void force_rebuild();
89
90         bool is_installable() const { return !install_location.empty(); }
91         const Msp::FS::Path &get_install_location() const { return install_location; }
92         void add_depend(Target *);
93         const Dependencies &get_depends() const { return depends; }
94
95         /** Finds dependencies for the target. */
96         virtual void find_depends() { }
97
98         /** Prepares the target by finding dependencies, recursively preparing them
99         and then checking whether rebuilding is needed. */
100         virtual void prepare();
101
102         /** Starts building the target.  Returns the Action used for building. */
103         Task *build();
104 protected:
105         void mark_rebuild(const std::string &);
106
107         /** Checks if the target needs to be rebuilt and why. */
108         virtual void check_rebuild() = 0;
109
110         /** Handler for Task::signal_finished. */
111         virtual void build_finished(bool);
112 };
113
114 #endif