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;
38 sigc::signal<void> signal_bubble_rebuild;
42 const SourcePackage *package;
43 const Component *component;
48 std::string rebuild_reason;
49 std::list<std::string> problems;
52 Dependencies side_effects;
53 Target *primary_target;
55 Target(Builder &, const std::string &);
59 virtual const char *get_type() const = 0;
60 const std::string &get_name() const { return name; }
61 const SourcePackage *get_package() const { return package; }
62 const Component *get_component() const { return component; }
64 /** Adds a dependency for the target. Order is preseved and is important
65 for some target types. It is an error to create dependency cycles, although
66 this won't be detected until the targets are prepared. */
67 void add_dependency(Target &);
69 /** Adds a side effect for the target. Side effects are not built on their
70 own, but together with their primary target. */
71 void add_side_effect(Target &);
74 /** Finds dependencies for the target. Called during preparation. If the
75 target needs to recursively inspect its dependencies, it should prepare its
76 direct dependencies first. */
77 virtual void find_dependencies() { }
80 /// Returns the dependencies of the target, in the order they were added.
81 const Dependencies &get_dependencies() const { return depends; }
83 /// Returns the side effects of the target.
84 const Dependencies &get_side_effects() const { return side_effects; }
86 /// Returns the primary target associated with a side effect target.
87 Target *get_primary_target() const { return primary_target; }
89 /** Tries to locate a target that will help getting this target built. If
90 all dependencies are up-to-date, returns this target. If there are no
91 targets ready to be built (maybe because they are being built right now),
93 virtual Target *get_buildable_target();
95 /** If this target is a proxy for another (such as InstalledFile), return
96 that target. Otherwise, return the target itself. Implementors should call
97 the function recursively to find the final target. */
98 virtual Target *get_real_target() { return this; }
100 void set_tool(Tool &);
102 /** Returns the tool used to build the target. To actually build it, call
103 the build() function. */
104 const Tool *get_tool() const { return tool; }
106 /** Indicates if it's possible to build this target. */
107 bool is_buildable() const { return tool!=0; }
109 /** Indicates if this target needs rebuilding. Only makes sense after the
110 target has been prepared. */
111 bool needs_rebuild() const { return state>PREPARING && state<UPTODATE; }
113 /** Returns the reason for rebuilding this target. Only makes sense after
114 the target has been prepared. */
115 const std::string &get_rebuild_reason() const { return rebuild_reason; }
117 /** Forces rebuild of the target. */
118 void force_rebuild();
121 /** Marks the target to be rebuilt and specified a reason for it. */
122 void mark_rebuild(const std::string &);
124 /** Checks if the target needs to be rebuilt and why. */
125 virtual void check_rebuild() = 0;
128 bool is_broken() const { return state==BROKEN; }
130 const std::list<std::string> &get_problems() const { return problems; }
132 /** Prepares the target by finding dependencies, recursively preparing them
133 and then checking whether rebuilding is needed. */
136 /** Invokes the associated Tool to build the target and returns the
137 resulting Task. The task must be started by the caller. */
138 virtual Task *build();
141 /** Targets can override this to do additional setup on the Task. This is
142 also called on side effects, which normally do not get built by themselves. */
143 virtual void build(Task &) { }
145 /** Handler for Task::signal_finished. */
146 virtual void build_finished(bool);
148 virtual void modified() { }
151 /** Removes any results of building the target. */
152 virtual void clean() { }