]> git.tdb.fi Git - builder.git/blobdiff - source/externaltask.cpp
Move the bpk files into a subdirectory and install them
[builder.git] / source / externaltask.cpp
index 0da81e519cc05eba437855e02da99d81722302d1..643831e993b9b7e8a8d4c2b65f11245c612bba18 100644 (file)
@@ -50,6 +50,8 @@ void ExternalTask::start()
        if(stdout_dest==CAPTURE || stderr_dest==CAPTURE)
                capture_pipe = new IO::Pipe;
 
+       prepare();
+
        if((pid = fork()))
        {
                if(pid==-1)
@@ -91,12 +93,21 @@ void ExternalTask::start()
 }
 
 Task::Status ExternalTask::check()
+{
+       return do_wait(false);
+}
+
+Task::Status ExternalTask::wait()
+{
+       return do_wait(true);
+}
+
+Task::Status ExternalTask::do_wait(bool block)
 {
        if(pid>0)
        {
-               // XXX This is sub-optimal, should have support for a blocking wait
                int status;
-               if(waitpid(pid, &status, WNOHANG)==pid)
+               if(waitpid(pid, &status, (block ? 0 : WNOHANG))==pid)
                {
                        if(WIFEXITED(status))
                                exit_code = WEXITSTATUS(status);
@@ -138,3 +149,14 @@ void ExternalTask::set_stderr(Destination d)
 {
        stderr_dest = d;
 }
+
+string ExternalTask::run_and_capture_output(const Arguments &argv, const FS::Path &wd)
+{
+       ExternalTask task(argv, wd);
+       task.set_stdout(CAPTURE);
+       task.set_stderr(IGNORE);
+       task.start();
+       if(task.wait()!=SUCCESS)
+               throw runtime_error(format("%s failed", argv.front()));
+       return task.get_output();
+}