From 7777d548fddca66b21f26273faedfdf675b10234 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 2 Oct 2014 18:24:26 +0300 Subject: [PATCH] Refactor version discovery into the base GnuCompiler class --- source/gnucompiler.cpp | 21 +++++++++++++++++++++ source/gnucompiler.h | 5 +++++ source/gnucxxcompiler.cpp | 34 ++++++---------------------------- source/gnucxxcompiler.h | 5 +---- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index da579ba..bff5f8c 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "architecture.h" #include "builder.h" #include "component.h" @@ -51,6 +52,26 @@ string GnuCompiler::create_build_signature(const BuildInfo &binfo) const return result; } +void GnuCompiler::do_prepare() +{ + executable = builder.get_vfs().find_binary(command); + if(executable) + { + ExternalTask::Arguments argv; + argv.push_back(executable->get_path().str()); + argv.push_back("-dumpversion"); + + builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end()))); + try + { + version = strip(ExternalTask::run_and_capture_output(argv)); + builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), version)); + } + catch(const runtime_error &) + { } + } +} + Task *GnuCompiler::run(const Target &target) const { const ObjectFile &object = dynamic_cast(target); diff --git a/source/gnucompiler.h b/source/gnucompiler.h index af3761b..9f0304d 100644 --- a/source/gnucompiler.h +++ b/source/gnucompiler.h @@ -13,11 +13,16 @@ appropriate type. class GnuCompiler: public Tool { protected: + std::string version; + 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 cff2c0c..af001b3 100644 --- a/source/gnucxxcompiler.cpp +++ b/source/gnucxxcompiler.cpp @@ -1,10 +1,5 @@ #include -#include -#include -#include -#include "builder.h" #include "csourcefile.h" -#include "externaltask.h" #include "gnucxxcompiler.h" using namespace std; @@ -19,26 +14,6 @@ GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a): aux_suffixes.push_back(".hpp"); } -void GnuCxxCompiler::query_version() -{ - ExternalTask::Arguments argv; - argv.push_back(executable->get_path().str()); - argv.push_back("-dumpversion"); - builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end()))); - try - { - string cxx_ver = strip(ExternalTask::run_and_capture_output(argv)); - FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver; - if(FS::is_dir(cxx_path)) - { - builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), cxx_ver)); - system_path.push_back(cxx_path); - } - } - catch(const runtime_error &) - { } -} - Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const { return new CSourceFile(builder, comp, path); @@ -52,7 +27,10 @@ Target *GnuCxxCompiler::create_source(const FS::Path &path) const void GnuCxxCompiler::do_prepare() { GnuCompiler::do_prepare(); - executable = builder.get_vfs().find_binary(command); - if(executable) - query_version(); + if(!version.empty()) + { + FS::Path cxx_path = FS::Path("/usr/include/c++")/version; + if(FS::is_dir(cxx_path)) + system_path.push_back(cxx_path); + } } diff --git a/source/gnucxxcompiler.h b/source/gnucxxcompiler.h index 5cdc34b..04c1fb2 100644 --- a/source/gnucxxcompiler.h +++ b/source/gnucxxcompiler.h @@ -10,14 +10,11 @@ class GnuCxxCompiler: public GnuCompiler { public: GnuCxxCompiler(Builder &, const Architecture &); -private: - void query_version(); -public: virtual Target *create_source(const Component &, const Msp::FS::Path &) const; virtual Target *create_source(const Msp::FS::Path &) const; -private: +protected: virtual void do_prepare(); }; -- 2.43.0