From: Mikko Rasa Date: Thu, 5 Jan 2023 09:56:38 +0000 (+0200) Subject: Report which targets participate in a dependency cycle X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d2c4cd0f5657f26150759fb8ab19dd448646eb06;p=builder.git Report which targets participate in a dependency cycle --- diff --git a/source/lib/target.cpp b/source/lib/target.cpp index d1aaf73..558b3b2 100644 --- a/source/lib/target.cpp +++ b/source/lib/target.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "builder.h" #include "filetarget.h" #include "sourcepackage.h" @@ -11,6 +12,8 @@ using namespace std; using namespace Msp; +vector Target::prepare_stack; + Target::Target(Builder &b, const string &n): builder(b), name(n) @@ -118,12 +121,26 @@ void Target::prepare() return; if(state==PREPARING) { - builder.get_logger().log("problems", "Dependency cycle detected at %s", name); - problems.push_back("Dependency cycle detected"); + auto i = find(prepare_stack, this); + if(i!=prepare_stack.end()) + { + string cycle; + for(; i!=prepare_stack.end(); ++i) + append(cycle, " -> ", (*i)->name); + append(cycle, " -> ", name); + builder.get_logger().log("problems", "Dependency cycle detected: %s", cycle); + problems.push_back(format("Dependency cycle detected: %s", cycle)); + } + else + { + builder.get_logger().log("problems", "Dependency cycle detected at %s", name); + problems.push_back("Dependency cycle detected"); + } state = BROKEN; return; } + PushPrepare _push(this); state = PREPARING; /* Prepare existing dependencies early, because their information may be needed to find other dependencies. */ diff --git a/source/lib/target.h b/source/lib/target.h index 0ba38f8..1ae268c 100644 --- a/source/lib/target.h +++ b/source/lib/target.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "libbuilder_api.h" @@ -41,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 signal_bubble_rebuild; sigc::signal signal_modified; @@ -61,6 +68,8 @@ protected: Dependencies side_effects; Target *primary_target = 0; + static std::vector prepare_stack; + Target(Builder &, const std::string &); public: virtual ~Target() { }