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.
24 typedef std::list<Target *> Dependencies;
37 sigc::signal<void> signal_bubble_rebuild;
41 const SourcePackage *package;
42 const Component *component;
47 std::string rebuild_reason;
50 Dependencies side_effects;
51 Target *primary_target;
53 Target(Builder &, const std::string &);
57 virtual const char *get_type() const = 0;
58 const std::string &get_name() const { return name; }
59 const SourcePackage *get_package() const { return package; }
60 const Component *get_component() const { return component; }
62 /** Adds a dependency for the target. Order is preseved and is important
63 for some target types. It is an error to create dependency cycles, although
64 this won't be detected until the targets are prepared. */
65 void add_dependency(Target &);
67 /** Adds a side effect for the target. Side effects are not built on their
68 own, but together with their primary target. */
69 void add_side_effect(Target &);
72 /** Finds dependencies for the target. Called during preparation. If the
73 target needs to recursively inspect its dependencies, it should prepare its
74 direct dependencies first. */
75 virtual void find_dependencies() { }
78 /// Returns the dependencies of the target, in the order they were added.
79 const Dependencies &get_dependencies() const { return depends; }
81 /// Returns the side effects of the target.
82 const Dependencies &get_side_effects() const { return side_effects; }
84 /// Returns the primary target associated with a side effect target.
85 Target *get_primary_target() const { return primary_target; }
87 /** Tries to locate a target that will help getting this target built. If
88 all dependencies are up-to-date, returns this target. If there are no
89 targets ready to be built (maybe because they are being built right now),
91 virtual Target *get_buildable_target();
93 /** If this target is a proxy for another (such as InstalledFile), return
94 that target. Otherwise, return the target itself. Implementors should call
95 the function recursively to find the final target. */
96 virtual Target *get_real_target() { return this; }
98 void set_tool(const Tool &);
100 /** Returns the tool used to build the target. To actually build it, call
101 the build() function. */
102 const Tool *get_tool() const { return tool; }
104 /** Indicates if it's possible to build this target. */
105 bool is_buildable() const { return tool!=0; }
107 /** Indicates if this target needs rebuilding. Only makes sense after the
108 target has been prepared. */
109 bool needs_rebuild() const { return state>PREPARING && state<UPTODATE; }
111 /** Returns the reason for rebuilding this target. Only makes sense after
112 the target has been prepared. */
113 const std::string &get_rebuild_reason() const { return rebuild_reason; }
115 /** Forces rebuild of the target. */
116 void force_rebuild();
119 /** Marks the target to be rebuilt and specified a reason for it. */
120 void mark_rebuild(const std::string &);
122 /** Checks if the target needs to be rebuilt and why. */
123 virtual void check_rebuild() = 0;
126 /** Prepares the target by finding dependencies, recursively preparing them
127 and then checking whether rebuilding is needed. */
130 /** Invokes the associated Tool to build the target and returns the
131 resulting Task. The task must be started by the caller. */
132 virtual Task *build();
135 /** Handler for Task::signal_finished. */
136 virtual void build_finished(bool);
138 virtual void modified() { }
141 /** Removes any results of building the target. */
142 virtual void clean() { }