From 44197e3e19f2e7cd6b76ab4e96f089b83c5e2e93 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 24 Dec 2022 23:34:14 +0200 Subject: [PATCH] Add a helper class for tool customization --- source/customizedtool.cpp | 59 +++++++++++++++++++++++++++++++++++++++ source/customizedtool.h | 25 +++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 source/customizedtool.cpp create mode 100644 source/customizedtool.h diff --git a/source/customizedtool.cpp b/source/customizedtool.cpp new file mode 100644 index 0000000..0a3f3a5 --- /dev/null +++ b/source/customizedtool.cpp @@ -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 &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)); +} diff --git a/source/customizedtool.h b/source/customizedtool.h new file mode 100644 index 0000000..55c4c6a --- /dev/null +++ b/source/customizedtool.h @@ -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 &, 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 -- 2.45.2