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;
51 Target(Builder &, const std::string &);
55 virtual const char *get_type() const = 0;
56 const std::string &get_name() const { return name; }
57 const SourcePackage *get_package() const { return package; }
58 const Component *get_component() const { return component; }
60 /** Adds a dependency for the target. Order is preseved and is important
61 for some target types. It is an error to create dependency cycles, although
62 this won't be detected until the targets are prepared. */
63 void add_depend(Target &);
66 /** Finds dependencies for the target. Called during preparation. If the
67 target needs to recursively inspect its dependencies, it should prepare its
68 direct dependencies first. */
69 virtual void find_depends() { }
72 /// Returns the dependencies of the target, in the order they were added.
73 const Dependencies &get_depends() const { return depends; }
75 /** Tries to locate a target that will help getting this target built. If
76 all dependencies are up-to-date, returns this target. If there are no
77 targets ready to be built (maybe because they are being built right now),
79 virtual Target *get_buildable_target();
81 /** If this target is a proxy for another (such as InstalledFile), return
82 that target. Otherwise, return the target itself. Implementors should call
83 the function recursively to find the final target. */
84 virtual Target *get_real_target() { return this; }
86 void set_tool(const Tool &);
88 /** Returns the tool used to build the target. To actually build it, call
89 the build() function. */
90 const Tool *get_tool() const { return tool; }
92 /** Indicates if it's possible to build this target. */
93 bool is_buildable() const { return tool!=0; }
95 /** Indicates if this target needs rebuilding. Only makes sense after the
96 target has been prepared. */
97 bool needs_rebuild() const { return state>PREPARING && state<UPTODATE; }
99 /** Returns the reason for rebuilding this target. Only makes sense after
100 the target has been prepared. */
101 const std::string &get_rebuild_reason() const { return rebuild_reason; }
103 /** Forces rebuild of the target. */
104 void force_rebuild();
107 /** Marks the target to be rebuilt and specified a reason for it. */
108 void mark_rebuild(const std::string &);
110 /** Checks if the target needs to be rebuilt and why. */
111 virtual void check_rebuild() = 0;
114 /** Prepares the target by finding dependencies, recursively preparing them
115 and then checking whether rebuilding is needed. */
116 virtual void prepare();
118 /** Invokes the associated Tool to build the target and returns the
119 resulting Task. The task must be started by the caller. */
120 virtual Task *build();
123 /** Handler for Task::signal_finished. */
124 virtual void build_finished(bool);