if(stdout_dest==CAPTURE || stderr_dest==CAPTURE)
capture_pipe = new IO::Pipe;
+ prepare();
+
if((pid = fork()))
{
if(pid==-1)
#include "builder.h"
#include "filetarget.h"
#include "sourcepackage.h"
+#include "task.h"
#include "tool.h"
using namespace std;
Task *FileTarget::build()
{
- if(tool && !builder.get_dry_run() && mtime)
- FS::unlink(path);
-
- return Target::build();
+ Task *task = Target::build();
+ task->set_file(path);
+ task->set_unlink(true);
+ return task;
}
void FileTarget::build_finished(bool success)
if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
argv.push_back(relative(obj->get_path(), work_dir).str());
- if(!builder.get_dry_run())
- {
- FS::mkpath(FS::dirname(lib.get_path()), 0755);
- if(FS::exists(lib.get_path()))
- FS::unlink(lib.get_path());
- }
-
return new ExternalTask(argv, work_dir);
}
argv.push_back(relative(obj_path, work_dir).str());
argv.push_back(relative(src_path, work_dir).str());
- if(!builder.get_dry_run())
- FS::mkpath(FS::dirname(obj_path), 0755);
-
return new ExternalTask(argv, work_dir);
}
if(static_link_ok)
argv.push_back("-static");
- if(!builder.get_dry_run())
- FS::mkpath(FS::dirname(bin.get_path()), 0755);
-
return new ExternalTask(argv, work_dir);
}
void InternalTask::start()
{
+ prepare();
worker->launch();
}
--- /dev/null
+#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
+#include "task.h"
+
+using namespace Msp;
+
+Task::Task():
+ unlink(false)
+{ }
+
+void Task::set_file(const FS::Path &f)
+{
+ file = f;
+}
+
+void Task::set_unlink(bool u)
+{
+ unlink = u;
+}
+
+void Task::prepare()
+{
+ if(!file.empty())
+ {
+ if(FS::exists(file))
+ {
+ // If the file exists, the directory it's in must exist too
+ FS::unlink(file);
+ }
+ else
+ {
+ FS::Path dir = FS::dirname(file);
+ if(!FS::exists(dir))
+ FS::mkpath(dir, 0755);
+ }
+ }
+}
#include <string>
#include <sigc++/signal.h>
+#include <msp/fs/path.h>
/**
Tasks are used to manage other programs and worker threads involved in the
sigc::signal<void, bool> signal_finished;
+ Msp::FS::Path file;
+ bool unlink;
+
protected:
- Task() { }
+ Task();
public:
virtual ~Task() { }
+ /** Associate the task with a file. */
+ void set_file(const Msp::FS::Path &);
+
+ /** If set to true, the associated file is removed before the task is
+ started. */
+ void set_unlink(bool = true);
+
/** Returns the command being executed for this task. Only makes sense if
an external command is involved. */
virtual std::string get_command() const = 0;
/// Starts the task.
virtual void start() = 0;
+protected:
+ /** Ensures that the output directory exists and removes the file if
+ necessary. */
+ void prepare();
+
+public:
/// Checks the status of the task and immediately returns.
virtual Status check() = 0;