From 7ed7c30ee0ceb734f17fe0c6d4bc6d37fb2ab5a7 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 8 May 2013 11:16:36 +0300 Subject: [PATCH] Add a utility function for setting the executable for a Tool --- source/datatool.cpp | 5 +---- source/gnuarchiver.cpp | 6 +----- source/gnucompiler.cpp | 6 +----- source/gnulinker.cpp | 5 ++--- source/mingwdlltool.cpp | 6 +----- source/tool.cpp | 14 ++++++++++++++ source/tool.h | 5 +++++ 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/source/datatool.cpp b/source/datatool.cpp index 4a4fc8a..eeeec4e 100644 --- a/source/datatool.cpp +++ b/source/datatool.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "builder.h" #include "component.h" #include "datacollection.h" @@ -50,9 +49,7 @@ Target *DataTool::create_target(const list &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 diff --git a/source/gnuarchiver.cpp b/source/gnuarchiver.cpp index 7482b0d..cc4359e 100644 --- a/source/gnuarchiver.cpp +++ b/source/gnuarchiver.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include "builder.h" #include "component.h" @@ -42,10 +41,7 @@ Target *GnuArchiver::create_target(const list &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 diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 7d1d166..ec1959a 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -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 diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index cfdee8d..02708cc 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -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); } } diff --git a/source/mingwdlltool.cpp b/source/mingwdlltool.cpp index f44f575..1bb3509 100644 --- a/source/mingwdlltool.cpp +++ b/source/mingwdlltool.cpp @@ -1,7 +1,6 @@ #include #include #include -#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 diff --git a/source/tool.cpp b/source/tool.cpp index a23de63..65a4504 100644 --- a/source/tool.cpp +++ b/source/tool.cpp @@ -1,7 +1,11 @@ #include +#include +#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), diff --git a/source/tool.h b/source/tool.h index 73be90d..93e2196 100644 --- a/source/tool.h +++ b/source/tool.h @@ -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. */ -- 2.43.0