]> git.tdb.fi Git - builder.git/blobdiff - source/gnucompiler.cpp
Refactor GnuCompiler::prepare_version a bit
[builder.git] / source / gnucompiler.cpp
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)