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)
virtual std::string create_build_signature() const;
-public:
- virtual Task *build();
+ virtual void build(Task &);
-protected:
virtual void build_finished(bool);
public:
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;
}
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);
#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)
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);
}
sigc::signal<void, bool> signal_finished;
- Msp::FS::Path file;
+ std::list<Msp::FS::Path> files;
bool unlink;
protected:
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);
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: