]> git.tdb.fi Git - builder.git/blobdiff - source/lib/target.h
Refactor transitive dependencies to work on all targets
[builder.git] / source / lib / target.h
index 6ef6457a0f5fe73d70ddc31d7f66b561e878b63b..c6c8baa89d6e5046001afbf4ffb8c3c628316e99 100644 (file)
@@ -6,7 +6,9 @@
 #include <string>
 #include <vector>
 #include <sigc++/signal.h>
+#include <msp/core/noncopyable.h>
 #include <msp/time/timestamp.h>
+#include "libbuilder_api.h"
 
 class Builder;
 class BuildInfo;
@@ -24,7 +26,7 @@ normal and transitive.  Normal dependencies will need to be built before the
 target itself, and will cause the target to be rebuilt if modified.  Transitive
 dependencies can be used by other targets further down the chain.
 */
-class Target
+class LIBBUILDER_API Target
 {
 public:
        using Dependencies = std::vector<Target *>;
@@ -40,6 +42,12 @@ protected:
                BROKEN
        };
 
+       struct PushPrepare: Msp::NonCopyable
+       {
+               PushPrepare(Target *t) { prepare_stack.push_back(t); }
+               ~PushPrepare() { prepare_stack.pop_back(); }
+       };
+
 public:
        sigc::signal<void> signal_bubble_rebuild;
        sigc::signal<void> signal_modified;
@@ -59,6 +67,9 @@ protected:
        Dependencies trans_depends;
        Dependencies side_effects;
        Target *primary_target = 0;
+       bool rescan_trans_deps = false;
+
+       static std::vector<Target *> prepare_stack;
 
        Target(Builder &, const std::string &);
 public:
@@ -86,6 +97,13 @@ protected:
        direct dependencies first. */
        virtual void find_dependencies() { }
 
+private:
+       bool find_transitive_dependencies();
+       void find_transitive_dependencies(Target &, std::vector<Target *> &) const;
+
+protected:
+       virtual Target *resolve_transitive_dependency(Target &, Target &dep) const { return &dep; }
+
 public:
        /// Returns the dependencies of the target, in the order they were added.
        const Dependencies &get_dependencies() const { return depends; }