From: Mikko Rasa Date: Mon, 26 Dec 2022 12:07:51 +0000 (+0200) Subject: Fix logic issues with Tool::prepare X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=15cf75a5ac62454d90b8b2987b1940710056f4d0;p=builder.git Fix logic issues with Tool::prepare CustomizedTool's do_prepare will call the parent tool's prepare with itself as argument, so the prepared flag shouldn't be checked in this case. The command and executable checks are also better to do in the outer call to avoid doing them twice, since they don't depend on the base tool's logic. --- diff --git a/source/customizedtool.cpp b/source/customizedtool.cpp index 681d87e..9171996 100644 --- a/source/customizedtool.cpp +++ b/source/customizedtool.cpp @@ -55,5 +55,5 @@ string CustomizedTool::create_build_signature(const BuildInfo &bi) const void CustomizedTool::do_prepare(ToolData &tool) const { - parent.prepare(&static_cast(tool)); + parent.prepare(static_cast(tool)); } diff --git a/source/tool.cpp b/source/tool.cpp index d7b27ff..82349e1 100644 --- a/source/tool.cpp +++ b/source/tool.cpp @@ -37,27 +37,31 @@ Target *Tool::create_target(Target &source, const string &arg) return create_target(sources, arg); } -void Tool::prepare(Tool *tool) +void Tool::prepare() { - if(!tool) - tool = this; - else if(tool->get_base_tool()!=this) - throw invalid_argument("Tool::prepare"); - - if(tool->prepared) + if(prepared) return; - tool->prepared = true; - if(!tool->command.empty()) - tool->executable = builder.get_vfs().find_binary(tool->command); - do_prepare(*tool); + prepared = true; + + if(!command.empty()) + executable = builder.get_vfs().find_binary(command); + prepare(*this); if(!command.empty() && !executable) { - builder.get_logger().log("problems", "Can't find executable %s for %s", tool->command, tool->tag); - tool->problems.push_back(format("Can't find executable %s", tool->command)); + builder.get_logger().log("problems", "Can't find executable %s for %s", command, tag); + problems.push_back(format("Can't find executable %s", command)); } } +void Tool::prepare(Tool &tool) const +{ + if(&tool!=this && tool.get_base_tool()!=this) + throw invalid_argument("Tool::prepare"); + + do_prepare(tool); +} + string Tool::create_build_signature(const BuildInfo &) const { if(executable) diff --git a/source/tool.h b/source/tool.h index 85bae55..dab39e7 100644 --- a/source/tool.h +++ b/source/tool.h @@ -133,7 +133,8 @@ public: virtual std::string create_build_signature(const BuildInfo &) const; - void prepare(Tool * = 0); + void prepare(); + void prepare(Tool &) const; protected: virtual void do_prepare(ToolData &) const { }