]> git.tdb.fi Git - builder.git/commitdiff
Give tasks the ability to return the relevant shell command
authorMikko Rasa <tdb@tdb.fi>
Thu, 10 May 2012 21:20:33 +0000 (00:20 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:52 +0000 (00:08 +0300)
source/externaltask.cpp
source/externaltask.h
source/internaltask.h
source/task.h

index 672762b91bb2b35ede371ade85820d3090175205..f24774e83a5cc8009aae92d2d172a41c2893c039 100644 (file)
@@ -8,11 +8,32 @@
 using namespace std;
 using namespace Msp;
 
-ExternalTask::ExternalTask(const vector<string> &argv, const FS::Path &work_dir):
+ExternalTask::ExternalTask(const vector<string> &a, const FS::Path &wd):
+       argv(a),
+       work_dir(wd),
        pid(-1),
        exit_code(-1)
 { }
 
+string ExternalTask::get_command() const
+{
+       string cmd;
+       for(vector<string>::const_iterator i=argv.begin(); i!=argv.end(); ++i)
+       {
+               if(i!=argv.begin())
+                       cmd += ' ';
+
+               for(string::const_iterator j=i->begin(); j!=i->end(); ++j)
+               {
+                       if(*j=='"' || *j=='\'' || *j==' ' || *j=='\\' || *j=='&')
+                               cmd += '\\';
+                       cmd += *j;
+               }
+       }
+
+       return cmd;
+}
+
 void ExternalTask::start()
 {
        if((pid = fork()))
index 3028e74ddb998ae1db611a05285c3f2d7d635be5..0bd108e9a3cac68e46ca80e6f43ac434b752a70c 100644 (file)
@@ -9,12 +9,15 @@
 class ExternalTask: public Task
 {
 private:
+       std::vector<std::string> argv;
+       Msp::FS::Path work_dir;
        int pid;
        int exit_code;
 
 public:
        ExternalTask(const std::vector<std::string> &, const Msp::FS::Path &);
 
+       virtual std::string get_command() const;
        virtual void start();
        virtual Status check();
 };
index 9e52247a258f3429095d73db17a04dd1535c560d..83023d3ad33c63e0826cb4e3359a9cedd3413c66 100644 (file)
@@ -27,6 +27,7 @@ public:
        InternalTask(Worker *);
        ~InternalTask();
 
+       virtual std::string get_command() const { return "<internal>"; }
        virtual void start();
        virtual Status check();
 };
index 03d212bc74af1ac1b7eaaaaabfe8f7ec0e64aa72..531316be71d1ee98a46d3f86bcd55a8b8b796b39 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef TASK_H_
 #define TASK_H_
 
+#include <string>
 #include <sigc++/signal.h>
 
 class Task
@@ -20,6 +21,7 @@ protected:
 public:
        virtual ~Task() { }
 
+       virtual std::string get_command() const = 0;
        virtual void start() = 0;
        virtual Status check() = 0;
 };