From d2c4cd0f5657f26150759fb8ab19dd448646eb06 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 5 Jan 2023 11:56:38 +0200 Subject: [PATCH] Report which targets participate in a dependency cycle --- source/lib/target.cpp | 21 +++++++++++++++++++-- source/lib/target.h | 9 +++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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() { } -- 2.45.2