From: Mikko Rasa Date: Thu, 9 May 2013 07:24:17 +0000 (+0300) Subject: Remove all files in a side effect group when starting a task X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=24981eb7ef702aa97b2ab90399ccd3fc23ce9ccf;p=builder.git Remove all files in a side effect group when starting a task --- diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 6ce5cfd..862ddbe 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -121,12 +121,10 @@ string FileTarget::create_build_signature() const return tool->create_build_signature(binfo); } -Task *FileTarget::build() +void FileTarget::build(Task &task) { - Task *task = Target::build(); - task->set_file(path); - task->set_unlink(true); - return task; + task.add_file(path); + task.set_unlink(true); } void FileTarget::build_finished(bool success) diff --git a/source/filetarget.h b/source/filetarget.h index da6b9a8..64567fd 100644 --- a/source/filetarget.h +++ b/source/filetarget.h @@ -41,10 +41,8 @@ protected: virtual std::string create_build_signature() const; -public: - virtual Task *build(); + virtual void build(Task &); -protected: virtual void build_finished(bool); public: diff --git a/source/target.cpp b/source/target.cpp index f5b93a0..dd75e9a 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -149,6 +149,10 @@ Task *Target::build() task->signal_finished.connect(sigc::mem_fun(this, &Target::build_finished)); state = BUILDING; + build(*task); + for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i) + (*i)->build(*task); + return task; } diff --git a/source/target.h b/source/target.h index 7c1d9a7..6b9cc90 100644 --- a/source/target.h +++ b/source/target.h @@ -138,6 +138,10 @@ public: virtual Task *build(); protected: + /** Targets can override this to do additional setup on the Task. This is + also called on side effects, which normally do not get built by themselves. */ + virtual void build(Task &) { } + /** Handler for Task::signal_finished. */ virtual void build_finished(bool); diff --git a/source/task.cpp b/source/task.cpp index f6fa7b2..75b725e 100644 --- a/source/task.cpp +++ b/source/task.cpp @@ -3,15 +3,16 @@ #include #include "task.h" +using namespace std; using namespace Msp; Task::Task(): unlink(false) { } -void Task::set_file(const FS::Path &f) +void Task::add_file(const FS::Path &f) { - file = f; + files.push_back(f); } void Task::set_unlink(bool u) @@ -21,16 +22,16 @@ void Task::set_unlink(bool u) void Task::prepare() { - if(!file.empty()) + for(list::const_iterator i=files.begin(); i!=files.end(); ++i) { - if(FS::exists(file)) + if(FS::exists(*i)) { // If the file exists, the directory it's in must exist too - FS::unlink(file); + FS::unlink(*i); } else { - FS::Path dir = FS::dirname(file); + FS::Path dir = FS::dirname(*i); if(!FS::exists(dir)) FS::mkpath(dir, 0755); } diff --git a/source/task.h b/source/task.h index 0732453..183deee 100644 --- a/source/task.h +++ b/source/task.h @@ -22,7 +22,7 @@ public: sigc::signal signal_finished; - Msp::FS::Path file; + std::list files; bool unlink; protected: @@ -31,9 +31,9 @@ public: virtual ~Task() { } /** Associate the task with a file. */ - void set_file(const Msp::FS::Path &); + void add_file(const Msp::FS::Path &); - /** If set to true, the associated file is removed before the task is + /** If set to true, the associated files are removed before the task is started. */ void set_unlink(bool = true); @@ -45,8 +45,7 @@ public: virtual void start() = 0; protected: - /** Ensures that the output directory exists and removes the file if - necessary. */ + /// Ensures that the output directory exists and removes files if necessary. void prepare(); public: