]> git.tdb.fi Git - builder.git/commitdiff
Refactor version discovery into the base GnuCompiler class
authorMikko Rasa <tdb@tdb.fi>
Thu, 2 Oct 2014 15:24:26 +0000 (18:24 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 2 Oct 2014 15:24:26 +0000 (18:24 +0300)
source/gnucompiler.cpp
source/gnucompiler.h
source/gnucxxcompiler.cpp
source/gnucxxcompiler.h

index da579ba5d0c132caf0b7c09d17e87bd3281e762e..bff5f8cd145106520005052184d04da274e4ae90 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #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<const ObjectFile &>(target);
index af3761bcfa62de57535332503edbac10955b286b..9f0304d82daa0408c4ae3817b36d7b828a5d4ee7 100644 (file)
@@ -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<Target *> &, const std::string &);
        virtual std::string create_build_signature(const BuildInfo &) const;
+protected:
+       virtual void do_prepare();
+public:
        virtual Task *run(const Target &) const;
 };
 
index cff2c0c23671c0be09b952bcf5aa8875adeb787a..af001b3b569cfcd68e06dd67b5a4f16b4a6320af 100644 (file)
@@ -1,10 +1,5 @@
 #include <msp/fs/stat.h>
-#include <msp/fs/utils.h>
-#include <msp/io/print.h>
-#include <msp/strings/utils.h>
-#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);
+       }
 }
index 5cdc34bd8a214d575cd8b5ed520354fcb237dbbc..04c1fb22b5b2d5c38d5a056edf289b028d7fda1f 100644 (file)
@@ -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();
 };