]> git.tdb.fi Git - builder.git/commitdiff
Add a helper class for tool customization
authorMikko Rasa <tdb@tdb.fi>
Sat, 24 Dec 2022 21:34:14 +0000 (23:34 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 24 Dec 2022 21:34:14 +0000 (23:34 +0200)
source/customizedtool.cpp [new file with mode: 0644]
source/customizedtool.h [new file with mode: 0644]

diff --git a/source/customizedtool.cpp b/source/customizedtool.cpp
new file mode 100644 (file)
index 0000000..0a3f3a5
--- /dev/null
@@ -0,0 +1,59 @@
+#include "builder.h"
+#include "customizedtool.h"
+#include "target.h"
+
+using namespace std;
+using namespace Msp;
+
+CustomizedTool::CustomizedTool(Builder &b, const std::string &t, const Architecture &a):
+       CustomizedTool(b.get_toolchain().get_tool(t), a)
+{ }
+
+CustomizedTool::CustomizedTool(Tool &t, const Architecture &a):
+       Tool(t.get_builder(), &a, t.get_tag()),
+       parent(t)
+{
+       input_suffixes = parent.get_input_suffixes();
+       aux_suffixes = parent.get_auxiliary_suffixes();
+       processing_unit = parent.get_processing_unit();
+
+       set_run([this](const Target &t){ return parent.run(t); });
+}
+
+Target *CustomizedTool::create_source(const Component &c, const FS::Path &p) const
+{
+       return parent.create_source(c, p);
+}
+
+Target *CustomizedTool::create_source(const FS::Path &p) const
+{
+       return parent.create_source(p);
+}
+
+Target *CustomizedTool::create_target(const vector<Target *> &s, const string &a)
+{
+       Target *target = parent.create_target(s, a);
+       target->set_tool(*this);
+       return target;
+}
+
+Target *CustomizedTool::create_install(Target &t) const
+{
+       return parent.create_install(t);
+}
+
+string CustomizedTool::create_build_signature(const BuildInfo &bi) const
+{
+       string sig = Tool::create_build_signature(bi);
+       string parent_sig = parent.create_build_signature(bi);
+       string::size_type comma = parent_sig.find(',');
+       if(comma==string::npos)
+               return sig;
+       else
+               return sig+parent_sig.substr(comma);
+}
+
+void CustomizedTool::do_prepare(ToolData &tool) const
+{
+       parent.prepare(&static_cast<Tool &>(tool));
+}
diff --git a/source/customizedtool.h b/source/customizedtool.h
new file mode 100644 (file)
index 0000000..55c4c6a
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef CUSTOMIZEDTOOL_H_
+#define CUSTOMIZEDTOOL_H_
+
+#include "tool.h"
+
+class CustomizedTool: public Tool
+{
+protected:
+       Tool &parent;
+
+       CustomizedTool(Builder &, const std::string &, const Architecture &);
+       CustomizedTool(Tool &, const Architecture &);
+
+public:
+       const Tool *get_base_tool() const override { return &parent; }
+       Target *create_source(const Component &, const Msp::FS::Path &) const override;
+       Target *create_source(const Msp::FS::Path &) const override;
+       Target *create_target(const std::vector<Target *> &, const std::string & = std::string()) override;
+       Target *create_install(Target &) const override;
+       std::string create_build_signature(const BuildInfo &) const override;
+protected:
+       void do_prepare(ToolData &) const override;
+};
+
+#endif