From: Mikko Rasa Date: Sat, 24 Dec 2022 21:21:37 +0000 (+0200) Subject: Refactor GnuCompiler::prepare_version a bit X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1009314aed27a555033e743f84a1e4347d0bad69;p=builder.git Refactor GnuCompiler::prepare_version a bit --- diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 91d5a17..424a5b4 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -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 version_parts = split(version_str, '.'); - version = 0; + unsigned ver = 0; for(unsigned i=0; (i<3 && i(version_parts[i])<<(16-8*i); + ver |= lexical_cast(version_parts[i])<<(16-8*i); + return ver; } catch(const runtime_error &) { } + + return 0; } Task *GnuCompiler::_run(const ObjectFile &object) diff --git a/source/gnucompiler.h b/source/gnucompiler.h index 8257dd8..8521a1f 100644 --- a/source/gnucompiler.h +++ b/source/gnucompiler.h @@ -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 &);