From e516e78510ad455eebc0e06645c9f12943117525 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 24 May 2013 20:27:01 +0300 Subject: [PATCH] Redesign the way commands are set for tools This is necessary for some future developments. --- source/datatool.cpp | 6 +----- source/datatool.h | 3 --- source/gnuarchiver.cpp | 6 +----- source/gnuarchiver.h | 3 --- source/gnuccompiler.cpp | 3 ++- source/gnucompiler.cpp | 10 ++-------- source/gnucompiler.h | 8 +------- source/gnucxxcompiler.cpp | 3 ++- source/gnulinker.cpp | 21 ++++++++------------- source/mingwdlltool.cpp | 9 +++------ source/mingwdlltool.h | 5 ----- source/tool.cpp | 27 +++++++++++++++++---------- source/tool.h | 15 +++++++++------ 13 files changed, 46 insertions(+), 73 deletions(-) diff --git a/source/datatool.cpp b/source/datatool.cpp index eeeec4e..9b101c7 100644 --- a/source/datatool.cpp +++ b/source/datatool.cpp @@ -15,6 +15,7 @@ using namespace Msp; DataTool::DataTool(Builder &b): Tool(b, "DATA") { + set_command("mspdatatool"); input_suffixes.push_back(".mdt"); } @@ -47,11 +48,6 @@ Target *DataTool::create_target(const list &sources, const string &arg throw invalid_argument("DataTool::create_target"); } -void DataTool::do_prepare() -{ - set_executable("mspdatatool"); -} - Task *DataTool::run(const Target &tgt) const { const Component &comp = *tgt.get_component(); diff --git a/source/datatool.h b/source/datatool.h index f2720c0..264ddc1 100644 --- a/source/datatool.h +++ b/source/datatool.h @@ -10,9 +10,6 @@ public: virtual Target *create_source(const Component &, const Msp::FS::Path &) const; virtual Target *create_target(const std::list &, const std::string &); -private: - virtual void do_prepare(); -public: virtual Task *run(const Target &) const; }; diff --git a/source/gnuarchiver.cpp b/source/gnuarchiver.cpp index cc4359e..6cf4adb 100644 --- a/source/gnuarchiver.cpp +++ b/source/gnuarchiver.cpp @@ -16,6 +16,7 @@ using namespace Msp; GnuArchiver::GnuArchiver(Builder &b, const Architecture &a): Tool(b, a, "AR") { + set_command("ar", true); input_suffixes.push_back(".o"); } @@ -39,11 +40,6 @@ Target *GnuArchiver::create_target(const list &sources, const string & return lib; } -void GnuArchiver::do_prepare() -{ - set_executable("ar", true); -} - Task *GnuArchiver::run(const Target &target) const { const StaticLibrary &lib = dynamic_cast(target); diff --git a/source/gnuarchiver.h b/source/gnuarchiver.h index 2c625b6..eab4933 100644 --- a/source/gnuarchiver.h +++ b/source/gnuarchiver.h @@ -9,9 +9,6 @@ public: GnuArchiver(Builder &, const Architecture &); virtual Target *create_target(const std::list &, const std::string &); -private: - virtual void do_prepare(); -public: virtual Task *run(const Target &) const; }; diff --git a/source/gnuccompiler.cpp b/source/gnuccompiler.cpp index 7089a26..cedea10 100644 --- a/source/gnuccompiler.cpp +++ b/source/gnuccompiler.cpp @@ -5,8 +5,9 @@ using namespace std; using namespace Msp; GnuCCompiler::GnuCCompiler(Builder &b, const Architecture &a): - GnuCompiler(b, a, "CC", "gcc") + GnuCompiler(b, a, "CC") { + set_command("gcc", true); input_suffixes.push_back(".c"); aux_suffixes.push_back(".h"); } diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 5f69c0d..cd7391f 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -13,9 +13,8 @@ using namespace std; using namespace Msp; -GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t, const string &c): - Tool(b, a, t), - command(c) +GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t): + Tool(b, a, t) { if(architecture->is_native()) system_path.push_back("/usr/include"); @@ -52,11 +51,6 @@ string GnuCompiler::create_build_signature(const BuildInfo &binfo) const return result; } -void GnuCompiler::do_prepare() -{ - set_executable(command, true); -} - Task *GnuCompiler::run(const Target &target) const { const ObjectFile &object = dynamic_cast(target); diff --git a/source/gnucompiler.h b/source/gnucompiler.h index 0c283e2..af3761b 100644 --- a/source/gnucompiler.h +++ b/source/gnucompiler.h @@ -12,18 +12,12 @@ appropriate type. */ class GnuCompiler: public Tool { -private: - std::string command; - protected: - GnuCompiler(Builder &, const Architecture &, const std::string &, const std::string &); + GnuCompiler(Builder &, const Architecture &, const std::string &); public: virtual Target *create_target(const std::list &, const std::string &); virtual std::string create_build_signature(const BuildInfo &) const; -protected: - virtual void do_prepare(); -public: virtual Task *run(const Target &) const; }; diff --git a/source/gnucxxcompiler.cpp b/source/gnucxxcompiler.cpp index 1926a5e..55f7109 100644 --- a/source/gnucxxcompiler.cpp +++ b/source/gnucxxcompiler.cpp @@ -11,8 +11,9 @@ using namespace std; using namespace Msp; GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a): - GnuCompiler(b, a, "CXX", "g++") + GnuCompiler(b, a, "CXX") { + set_command("g++", true); input_suffixes.push_back(".cpp"); input_suffixes.push_back(".cc"); aux_suffixes.push_back(".hpp"); diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 9ae5d64..ea448ac 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -115,7 +115,14 @@ Task *GnuLinker::run(const Target &) const GnuLinker::Linker::Linker(GnuLinker &p, const string &ct): SubTool(p), compiler_tag(ct) -{ } +{ + if(compiler_tag=="CC") + set_command("gcc", true); + else if(compiler_tag=="CXX") + set_command("g++", true); + else + throw invalid_argument("GnuLinker::Linker::Linker"); +} Target *GnuLinker::Linker::create_target(const list &sources, const string &arg) { @@ -150,18 +157,6 @@ void GnuLinker::Linker::do_prepare() compiler.prepare(); executable = compiler.get_executable(); } - else - { - string command; - if(compiler_tag=="CC") - command = "gcc"; - else if(compiler_tag=="CXX") - command = "g++"; - else - throw invalid_argument("GnuLinker::Linker::Linker"); - - set_executable(command, true); - } } Task *GnuLinker::Linker::run(const Target &target) const diff --git a/source/mingwdlltool.cpp b/source/mingwdlltool.cpp index 1bb3509..03babd4 100644 --- a/source/mingwdlltool.cpp +++ b/source/mingwdlltool.cpp @@ -17,7 +17,9 @@ using namespace Msp; MingwDllTool::MingwDllTool(Builder &b, const Architecture &a): Tool(b, a, "DLL") -{ } +{ + set_command("dlltool", true); +} Target *MingwDllTool::create_target(const list &sources, const string &) { @@ -55,11 +57,6 @@ Target *MingwDllTool::create_install(Target &target) const return 0; } -void MingwDllTool::do_prepare() -{ - set_executable("dlltool", true); -} - Task *MingwDllTool::run(const Target &target) const { const ImportLibrary *imp = dynamic_cast(&target); diff --git a/source/mingwdlltool.h b/source/mingwdlltool.h index 796da75..2930831 100644 --- a/source/mingwdlltool.h +++ b/source/mingwdlltool.h @@ -10,11 +10,6 @@ public: virtual Target *create_target(const std::list &, const std::string &); virtual Target *create_install(Target &) const; - -private: - virtual void do_prepare(); - -public: virtual Task *run(const Target &) const; }; diff --git a/source/tool.cpp b/source/tool.cpp index 8aa75dc..abded33 100644 --- a/source/tool.cpp +++ b/source/tool.cpp @@ -23,6 +23,17 @@ Tool::Tool(Builder &b, const Architecture &a, const string &t): prepared(false) { } +void Tool::set_command(const string &cmd, bool cross) +{ + if(cmd.empty()) + throw invalid_argument("Tool::set_command"); + + if(cross && architecture->is_cross()) + command = format("%s-%s", architecture->get_cross_prefix(), cmd); + else + command = cmd; +} + bool Tool::accepts_suffix(const string &suffix, bool aux) const { if(find(input_suffixes.begin(), input_suffixes.end(), suffix)!=input_suffixes.end()) @@ -47,16 +58,12 @@ void Tool::prepare() prepared = true; 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) - problems.push_back(format("Can't find executable %s", command)); + if(!executable && !command.empty()) + { + executable = builder.get_vfs().find_binary(command); + if(!executable) + problems.push_back(format("Can't find executable %s", command)); + } } diff --git a/source/tool.h b/source/tool.h index be3646c..7531bbf 100644 --- a/source/tool.h +++ b/source/tool.h @@ -27,6 +27,7 @@ protected: Builder &builder; const Architecture *architecture; std::string tag; + std::string command; FileTarget *executable; SuffixList input_suffixes; SuffixList aux_suffixes; @@ -45,8 +46,15 @@ public: tool is architecture-agnostic. */ const Architecture *get_architecture() const { return architecture; } + /** Overrides the command used by the tool. The new command should accept + the same command line arguments. Only works on tools that use an external + command. If cross is true and the architecture is not native, a cross + prefix is added to the command. May have no effect after prepare() has been + called. */ + void set_command(const std::string &cmd, bool cross = false); + /** Returns a target for the tool's own executable. If the tool does not - use an external program, returns null. */ + use an external program, returns null. The tool must be prepared first. */ FileTarget *get_executable() const { return executable; } /// Returns a list of suffixes that can be processed with this tool. @@ -90,11 +98,6 @@ 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: const std::list &get_problems() const { return problems; } -- 2.43.0