]> git.tdb.fi Git - builder.git/blobdiff - source/tool.h
Refactor the use of external tasks in tools
[builder.git] / source / tool.h
index ca19c6f17b522cda1565371c60cbc0e97304f3df..b756563242ba4099152f0ce125bd93a6504d9ffb 100644 (file)
@@ -6,7 +6,10 @@
 #include <vector>
 #include <msp/fs/path.h>
 #include "buildinfo.h"
+#include "externaltask.h"
 #include "internaltask.h"
+#include "sourcepackage.h"
+#include "target.h"
 #include "virtualfilesystem.h"
 
 class Architecture;
@@ -14,13 +17,21 @@ class Builder;
 class BuildInfo;
 class Component;
 class FileTarget;
-class Target;
+
+class ToolData
+{
+public:
+       VirtualFileSystem::SearchPath system_path;
+       BuildInfo build_info;
+       Msp::Variant extra_data;
+       std::vector<std::string> problems;
+};
 
 /**
 Base class for tools.  Tools are used to turn targets into other targets.
 Examples include compilers and linkers.
 */
-class Tool
+class Tool: protected ToolData
 {
 public:
        enum ProcessingUnit
@@ -39,16 +50,12 @@ protected:
        std::vector<std::string> input_suffixes;
        std::vector<std::string> aux_suffixes;
        ProcessingUnit processing_unit = ONE_FILE;
-       VirtualFileSystem::SearchPath system_path;
-       BuildInfo build_info;
        std::function<Task *(const Target &)> run_func;
        bool prepared = false;
-       std::vector<std::string> problems;
 
        Tool(Builder &b, const std::string &t): Tool(b, 0, t) { }
-       Tool(Builder &b, const Architecture &a, const std::string &t): Tool(b, &a, t) { }
-private:
        Tool(Builder &b, const Architecture *a, const std::string &t): builder(b), architecture(a), tag(t) { }
+
 public:
        virtual ~Tool() { }
 
@@ -60,11 +67,13 @@ public:
        tool is architecture-agnostic. */
        const Architecture *get_architecture() const { return architecture; }
 
+       virtual const Tool *get_base_tool() const { return this; }
+
 protected:
        void set_run(std::function<Task *(const Target &)>);
 
        template<typename T>
-       void set_run(Task *(*)(const T &));
+       void set_run_external(ExternalTask::Arguments (*)(const T &, Msp::FS::Path &));
 
        template<typename T>
        void set_run_internal(bool (*)(const T &));
@@ -102,6 +111,8 @@ public:
        the chain. */
        const BuildInfo &get_build_info() const { return build_info; }
 
+       const Msp::Variant &get_extra_data() const { return extra_data; }
+
        /// Creates a source file appropriate for this tool.
        virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
 
@@ -125,9 +136,10 @@ public:
        virtual std::string create_build_signature(const BuildInfo &) const;
 
        void prepare();
+       void prepare(Tool &) const;
 
 protected:
-       virtual void do_prepare() { }
+       virtual void do_prepare(ToolData &) const { }
 
 public:
        const std::vector<std::string> &get_problems() const { return problems; }
@@ -139,9 +151,13 @@ public:
 
 
 template<typename T>
-void Tool::set_run(Task *(*f)(const T &))
+void Tool::set_run_external(ExternalTask::Arguments (*f)(const T &, Msp::FS::Path &))
 {
-       set_run([f](const Target &t){ return f(dynamic_cast<const T &>(t)); });
+       set_run([f](const Target &t){
+               Msp::FS::Path work_dir = t.get_package()->get_source_directory();
+               ExternalTask::Arguments args = f(dynamic_cast<const T &>(t), work_dir);
+               return new ExternalTask(args, work_dir);
+       });
 }
 
 template<typename T>