]> git.tdb.fi Git - builder.git/commitdiff
Add a utility function for setting the executable for a Tool
authorMikko Rasa <tdb@tdb.fi>
Wed, 8 May 2013 08:16:36 +0000 (11:16 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 8 May 2013 08:16:36 +0000 (11:16 +0300)
source/datatool.cpp
source/gnuarchiver.cpp
source/gnucompiler.cpp
source/gnulinker.cpp
source/mingwdlltool.cpp
source/tool.cpp
source/tool.h

index 4a4fc8a0cd89360d875bc7682de8c8b02afc6cd5..eeeec4ea68b30706a670c6b84ffd0af98d64cfdf 100644 (file)
@@ -1,6 +1,5 @@
 #include <stdexcept>
 #include <msp/fs/utils.h>
-#include <msp/strings/format.h>
 #include "builder.h"
 #include "component.h"
 #include "datacollection.h"
@@ -50,9 +49,7 @@ Target *DataTool::create_target(const list<Target *> &sources, const string &arg
 
 void DataTool::do_prepare()
 {
-       executable = builder.get_vfs().find_binary("mspdatatool");
-       if(!executable)
-               builder.problem(string(), format("Can't find executable mspdatatool for tool %s", tag));
+       set_executable("mspdatatool");
 }
 
 Task *DataTool::run(const Target &tgt) const
index 7482b0d17caf004d66125f4a82c8c098d0bb2331..cc4359e90071235a57df19c0ac59a3a58fd12088 100644 (file)
@@ -1,7 +1,6 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
-#include <msp/strings/format.h>
 #include <stdexcept>
 #include "builder.h"
 #include "component.h"
@@ -42,10 +41,7 @@ Target *GnuArchiver::create_target(const list<Target *> &sources, const string &
 
 void GnuArchiver::do_prepare()
 {
-       string command = "ar";
-       if(architecture->is_cross())
-               command = format("%s-%s", architecture->get_cross_prefix(), command);
-       executable = builder.get_vfs().find_binary(command);
+       set_executable("ar", true);
 }
 
 Task *GnuArchiver::run(const Target &target) const
index 7d1d166579467f4213735f0975d354a2690c55d4..ec1959afae67cfaf3a3f4a82e25e8a8c748f1a7a 100644 (file)
@@ -54,11 +54,7 @@ string GnuCompiler::create_build_signature(const BuildInfo &binfo) const
 
 void GnuCompiler::do_prepare()
 {
-       if(architecture->is_cross())
-               command = format("%s-%s", architecture->get_cross_prefix(), command);
-       executable = builder.get_vfs().find_binary(command);
-       if(!executable)
-               builder.problem(string(), format("Can't find executable %s for tool %s", command, tag));
+       set_executable(command, true);
 }
 
 Task *GnuCompiler::run(const Target &target) const
index cfdee8daffc3570e572006d85093733bbe35c75f..02708cc9b68d2a2587d92691fa72d788f6e329bd 100644 (file)
@@ -159,9 +159,8 @@ void GnuLinker::Linker::do_prepare()
                        command = "g++";
                else
                        throw invalid_argument("GnuLinker::Linker::Linker");
-               if(architecture->is_cross())
-                       command = format("%s-%s", architecture->get_cross_prefix(), command);
-               executable = builder.get_vfs().find_binary(command);
+
+               set_executable(command, true);
        }
 }
 
index f44f5754a1ef4f8d45ec639ff045716a9f7b830a..1bb35093620aac6edfda6f85dd149514bdd91596 100644 (file)
@@ -1,7 +1,6 @@
 #include <cstdlib>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
-#include "architecture.h"
 #include "builder.h"
 #include "component.h"
 #include "exportdefinitions.h"
@@ -58,10 +57,7 @@ Target *MingwDllTool::create_install(Target &target) const
 
 void MingwDllTool::do_prepare()
 {
-       string command = "dlltool";
-       if(architecture->is_cross())
-               command = format("%s-%s", architecture->get_cross_prefix(), command);
-       executable = builder.get_vfs().find_binary(command);
+       set_executable("dlltool", true);
 }
 
 Task *MingwDllTool::run(const Target &target) const
index a23de6322e8ad3fef1422531d8577944b18000de..65a45041286e6a054649461bd65770cccc614d69 100644 (file)
@@ -1,7 +1,11 @@
 #include <algorithm>
+#include <msp/strings/format.h>
+#include "architecture.h"
+#include "builder.h"
 #include "tool.h"
 
 using namespace std;
+using namespace Msp;
 
 Tool::Tool(Builder &b, const string &t):
        builder(b),
@@ -45,6 +49,16 @@ void Tool::prepare()
        do_prepare();
 }
 
+void Tool::set_executable(const string &command, bool cross)
+{
+       if(cross && architecture->is_cross())
+               return set_executable(format("%s-%s", architecture->get_cross_prefix(), command), false);
+
+       executable = builder.get_vfs().find_binary(command);
+       if(!executable)
+               builder.problem(string(), format("Can't find executable %s for tool %s", command, tag));
+}
+
 
 SubTool::SubTool(Tool &p):
        Tool(p),
index 73be90d30a34a92f18235d9f9ece3d29f623318d..93e2196189ca1f110f3a7d5774f4523420f03a28 100644 (file)
@@ -85,6 +85,11 @@ public:
 protected:
        virtual void do_prepare() { }
 
+       /** Locates an executable for the tool from the VFS.  If it isn't found, a
+       problem is reported.  If cross is true and the architecture is not native,
+       a cross prefix is added to the command. */
+       void set_executable(const std::string &command, bool cross = false);
+
 public:
        /** Invokes the tool to build a target.  This should not be called directly;
        use Target::build() instead. */