]> git.tdb.fi Git - builder.git/commitdiff
Remove all files in a side effect group when starting a task
authorMikko Rasa <tdb@tdb.fi>
Thu, 9 May 2013 07:24:17 +0000 (10:24 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 9 May 2013 07:24:17 +0000 (10:24 +0300)
source/filetarget.cpp
source/filetarget.h
source/target.cpp
source/target.h
source/task.cpp
source/task.h

index 6ce5cfdb3bcee336d5b601608c23c8b50b8e2edf..862ddbe5836197c500ae99cf05f324c419bacbe5 100644 (file)
@@ -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)
index da6b9a883d6625b9e20d87bc9880822b23aea846..64567fd255755a6f87fde6d3915ecf4318b695d3 100644 (file)
@@ -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:
index f5b93a0b3ad74b51aeab675e763f82b14bd85f9f..dd75e9a4a98b4d18206a8e7cf7c1512746557902 100644 (file)
@@ -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;
 }
 
index 7c1d9a74b7ea90bc2ec881254da2cda61861f39b..6b9cc90a0842de77c845982a1f6462d7c107caf6 100644 (file)
@@ -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);
 
index f6fa7b283e6c9b69b6c50cb9ad2d7d3707ac621f..75b725ede8657cc760efaa07d0bb92456b51975e 100644 (file)
@@ -3,15 +3,16 @@
 #include <msp/fs/utils.h>
 #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<FS::Path>::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);
                }
index 0732453bfd460b0f0fe8ae881899c6d33581d89a..183deee40e5c8d0b6b3b60455a2e3f14e933fdb5 100644 (file)
@@ -22,7 +22,7 @@ public:
 
        sigc::signal<void, bool> signal_finished;
 
-       Msp::FS::Path file;
+       std::list<Msp::FS::Path> 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: