From c194bac9d508999c046a1f56c80b9419f77a8590 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 9 May 2013 10:12:52 +0300 Subject: [PATCH] Improvements for handling side effects Propagate rebuild from side effects to the primary target. This can happen if the side effect does not exist for whatever reason. As an additional safeguard, redirect any build attempts on side effects to the primary target. --- source/filetarget.cpp | 10 ++++------ source/target.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/source/filetarget.cpp b/source/filetarget.cpp index b42580a..6ce5cfd 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -70,7 +70,7 @@ void FileTarget::touch() void FileTarget::check_rebuild() { - if(!tool) + if(!tool || needs_rebuild()) return; if(!mtime) @@ -89,12 +89,10 @@ void FileTarget::check_rebuild() if(!needs_rebuild()) { + // Some side effects might not exist for(Dependencies::iterator i=side_effects.begin(); (i!=side_effects.end() && !needs_rebuild()); ++i) - { - FileTarget *ft = dynamic_cast(*i); - if(ft && !ft->get_mtime()) - mark_rebuild((*i)->get_name()+" does not exist"); - } + if((*i)->needs_rebuild()) + mark_rebuild((*i)->get_name()+" needs rebuilding"); } if(!needs_rebuild() && package) diff --git a/source/target.cpp b/source/target.cpp index 7f031ec..f5b93a0 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -39,6 +39,9 @@ void Target::add_side_effect(Target &se) if(tool) se.set_tool(*tool); se.primary_target = this; + /* Side effects are checked for rebuild after the primary target. Recheck + the primary if a side effect is marked for rebuild. */ + se.signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild)); } Target *Target::get_buildable_target() @@ -139,6 +142,9 @@ void Target::prepare() Task *Target::build() { + if(primary_target) + return primary_target->build(); + Task *task = tool->run(*this); task->signal_finished.connect(sigc::mem_fun(this, &Target::build_finished)); state = BUILDING; -- 2.45.2