8 #include <sigc++/signal.h>
9 #include <msp/time/timestamp.h>
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.
21 Targets can depend on other targets. There are two kinds of dependencies:
22 normal and transitive. Normal dependencies will need to be built before the
23 target itself, and will cause the target to be rebuilt if modified. Transitive
24 dependencies can be used by other targets further down the chain.
29 typedef std::list<Target *> Dependencies;
43 sigc::signal<void> signal_bubble_rebuild;
47 const SourcePackage *package;
48 const Component *component;
53 std::string rebuild_reason;
54 std::list<std::string> problems;
57 Dependencies trans_depends;
58 Dependencies side_effects;
59 Target *primary_target;
61 Target(Builder &, const std::string &);
65 virtual const char *get_type() const = 0;
66 const std::string &get_name() const { return name; }
67 const SourcePackage *get_package() const { return package; }
68 const Component *get_component() const { return component; }
70 /** Adds a dependency for the target. Order is preseved and is important
71 for some target types. It is an error to create dependency cycles, although
72 this won't be detected until the targets are prepared. */
73 void add_dependency(Target &);
75 void add_transitive_dependency(Target &);
77 /** Adds a side effect for the target. Side effects are not built on their
78 own, but together with their primary target. */
79 void add_side_effect(Target &);
82 /** Finds dependencies for the target. Called during preparation. If the
83 target needs to recursively inspect its dependencies, it should prepare its
84 direct dependencies first. */
85 virtual void find_dependencies() { }
88 /// Returns the dependencies of the target, in the order they were added.
89 const Dependencies &get_dependencies() const { return depends; }
91 const Dependencies &get_transitive_dependencies() const { return trans_depends; }
93 /// Returns the side effects of the target.
94 const Dependencies &get_side_effects() const { return side_effects; }
96 /// Returns the primary target associated with a side effect target.
97 Target *get_primary_target() const { return primary_target; }
99 /** Tries to locate a target that will help getting this target built. If
100 all dependencies are up-to-date, returns this target. If there are no
101 targets ready to be built (maybe because they are being built right now),
103 virtual Target *get_buildable_target();
105 /** If this target is a proxy for another (such as InstalledFile), return
106 that target. Otherwise, return the target itself. Implementors should call
107 the function recursively to find the final target. */
108 virtual Target *get_real_target() { return this; }
110 void set_tool(Tool &);
112 /** Returns the tool used to build the target. To actually build it, call
113 the build() function. */
114 const Tool *get_tool() const { return tool; }
116 /** Indicates if it's possible to build this target. */
117 bool is_buildable() const { return tool!=0; }
119 /** Indicates if this target needs rebuilding. Only makes sense after the
120 target has been prepared. */
121 bool needs_rebuild() const { return state>PREPARING && state<UPTODATE; }
123 /** Returns the reason for rebuilding this target. Only makes sense after
124 the target has been prepared. */
125 const std::string &get_rebuild_reason() const { return rebuild_reason; }
127 /** Forces rebuild of the target. */
128 void force_rebuild();
131 /** Marks the target to be rebuilt and specified a reason for it. */
132 void mark_rebuild(const std::string &);
134 /** Checks if the target needs to be rebuilt and why. */
135 virtual void check_rebuild() = 0;
138 bool is_broken() const { return state==BROKEN; }
140 const std::list<std::string> &get_problems() const { return problems; }
142 /** Prepares the target by finding dependencies, recursively preparing them
143 and then checking whether rebuilding is needed. */
146 /** Invokes the associated Tool to build the target and returns the
147 resulting Task. The task must be started by the caller. */
148 virtual Task *build();
151 /** Targets can override this to do additional setup on the Task. This is
152 also called on side effects, which normally do not get built by themselves. */
153 virtual void build(Task &) { }
155 /** Handler for Task::signal_finished. */
156 virtual void build_finished(bool);
158 virtual void modified() { }
161 /** Removes any results of building the target. */
162 virtual void clean() { }