]> git.tdb.fi Git - builder.git/commitdiff
Refactor GnuCompiler::prepare_version a bit
authorMikko Rasa <tdb@tdb.fi>
Sat, 24 Dec 2022 21:21:37 +0000 (23:21 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 24 Dec 2022 21:22:45 +0000 (23:22 +0200)
source/gnucompiler.cpp
source/gnucompiler.h

index 91d5a17ca62374e46e4ee2316be51f38baeec61e..424a5b46c854ec9f85df8acce025b750f5c2a6d2 100644 (file)
@@ -172,13 +172,14 @@ void GnuCompiler::prepare_version()
        if(!executable)
                return;
 
-       prepare_version("-dumpversion");
+       string exe_path = executable->get_path().str();
+       version = query_version("-dumpversion");
        if(version>=0x70000)
-               prepare_version("-dumpfullversion");
+               version = query_version("-dumpfullversion");
        builder.get_logger().log("tools", "%s version is %d.%d.%d", FS::basename(executable->get_path()), version>>16, (version>>8)&0xFF, version&0xFF);
 }
 
-void GnuCompiler::prepare_version(const string &arg)
+unsigned GnuCompiler::query_version(const string &arg) const
 {
        ExternalTask::Arguments argv;
        argv.push_back(executable->get_path().str());
@@ -190,12 +191,15 @@ void GnuCompiler::prepare_version(const string &arg)
                string version_str = strip(ExternalTask::run_and_capture_output(argv));
 
                vector<string> version_parts = split(version_str, '.');
-               version = 0;
+               unsigned ver = 0;
                for(unsigned i=0; (i<3 && i<version_parts.size()); ++i)
-                       version |= lexical_cast<unsigned>(version_parts[i])<<(16-8*i);
+                       ver |= lexical_cast<unsigned>(version_parts[i])<<(16-8*i);
+               return ver;
        }
        catch(const runtime_error &)
        { }
+
+       return 0;
 }
 
 Task *GnuCompiler::_run(const ObjectFile &object)
index 8257dd83576e7236233cc88ef49ac92bcb89e42e..8521a1fc300684d652f8c007eb3c3d8d2911d80c 100644 (file)
@@ -28,7 +28,7 @@ protected:
        void do_prepare() override;
        void prepare_syspath();
        void prepare_version();
-       void prepare_version(const std::string &);
+       unsigned query_version(const std::string &) const;
 
 private:
        static Task *_run(const ObjectFile &);