]> git.tdb.fi Git - builder.git/commitdiff
Fix logic issues with Tool::prepare
authorMikko Rasa <tdb@tdb.fi>
Mon, 26 Dec 2022 12:07:51 +0000 (14:07 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 26 Dec 2022 19:12:48 +0000 (21:12 +0200)
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.

source/customizedtool.cpp
source/tool.cpp
source/tool.h

index 681d87e6c933a97669085e53ae234fce55ed09e1..9171996dcbb1a2082dbbc998e3d6806dc61f16ff 100644 (file)
@@ -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 &>(tool));
+       parent.prepare(static_cast<Tool &>(tool));
 }
index d7b27ff275e39cfbdd908ffbc21119474a40d540..82349e18eea50b747d8870ffb3f3113980dc7216 100644 (file)
@@ -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)
index 85bae55d88f2e063c9dd9ee7cef9d054f0bc21fd..dab39e7424882ffc10a840bbda2fe916bc938a59 100644 (file)
@@ -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 { }