From 0c0b2d4b529817f4561088c61827af797eee6def Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Sun, 3 Apr 2016 15:37:01 +1000 Subject: rtemstoolkit: Add version number parsing to get major, minor, revision. Add support to return the major, minor or revision numbers as numbers. --- rtemstoolkit/rld-rtems.cpp | 43 ++++++++++++++++++++++- rtemstoolkit/rld-rtems.h | 15 ++++++++ rtemstoolkit/rld.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++--- rtemstoolkit/rld.h | 27 +++++++++++++++ 4 files changed, 164 insertions(+), 6 deletions(-) diff --git a/rtemstoolkit/rld-rtems.cpp b/rtemstoolkit/rld-rtems.cpp index 86351fd..806a2e1 100644 --- a/rtemstoolkit/rld-rtems.cpp +++ b/rtemstoolkit/rld-rtems.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Chris Johns + * Copyright (c) 2011-2016, Chris Johns * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -28,6 +28,10 @@ namespace rld static std::string _path; static std::string _arch_bsp; + static uint64_t _version_major = 0; + static uint64_t _version_minor = 0; + static uint64_t _version_revision = 0; + static void load_cc () { @@ -130,6 +134,10 @@ namespace rld set_version (const std::string& version_) { _version = version_; + rld::version_parse (_version, + _version_major, + _version_minor, + _version_revision); } void @@ -154,6 +162,39 @@ namespace rld return _version; } + uint64_t + version_major () + { + if (_version_major == 0) + rld::version_parse (_version, + _version_major, + _version_minor, + _version_revision); + return _version_major; + } + + uint64_t + version_minor () + { + if (_version_minor == 0) + rld::version_parse (_version, + _version_major, + _version_minor, + _version_revision); + return _version_minor; + } + + uint64_t + version_revision () + { + if (_version_revision == 0) + rld::version_parse (_version, + _version_major, + _version_minor, + _version_revision); + return _version_revision; + } + const std::string arch_bsp () { diff --git a/rtemstoolkit/rld-rtems.h b/rtemstoolkit/rld-rtems.h index 04305ce..a682988 100644 --- a/rtemstoolkit/rld-rtems.h +++ b/rtemstoolkit/rld-rtems.h @@ -51,6 +51,21 @@ namespace rld */ const std::string version (); + /** + * Get the RTEMS major version number. + */ + uint64_t version_major (); + + /** + * Get the RTEMS minor version number. + */ + uint64_t version_minor (); + + /** + * Get the RTEMS revision version number. + */ + uint64_t version_revision (); + /** * Return the arch/bsp string. */ diff --git a/rtemstoolkit/rld.cpp b/rtemstoolkit/rld.cpp index 5168fe9..acce748 100644 --- a/rtemstoolkit/rld.cpp +++ b/rtemstoolkit/rld.cpp @@ -67,9 +67,19 @@ namespace rld static library_container libraries; /** - * The output passed on the command line. + * The version major number. */ - //static std::string output; + static uint64_t _version_major; + + /** + * The version minor number. + */ + static uint64_t _version_minor; + + /** + * The version revision number. + */ + static uint64_t _version_revision; bool starts_with(const std::string& s1, const std::string& s2) @@ -183,6 +193,44 @@ namespace rld return s; } + void + version_parse (const std::string& str, + uint64_t& major, + uint64_t& minor, + uint64_t& revision) + { + strings parts; + + rld::split (parts, str, '.'); + + if (parts.size () >= 1) + { + std::istringstream iss (parts[0]); + iss >> major; + } + + if (parts.size () >= 2) + { + std::istringstream iss (parts[1]); + iss >> minor; + } + + if (parts.size () >= 3) + { + size_t p = parts[2].find ('_'); + + if (p != std::string::npos) + parts[2].erase (p); + + std::istringstream iss (parts[2]); + + if (p != std::string::npos) + iss >> std::hex; + + iss >> revision; + } + } + void verbose_inc () { @@ -201,10 +249,37 @@ namespace rld return RTEMS_RELEASE; } - const std::string - rtems_version () + uint64_t + version_major () + { + if (_version_major == 0) + version_parse (version (), + _version_major, + _version_minor, + _version_revision); + return _version_major; + } + + uint64_t + version_minor () + { + if (_version_major == 0) + version_parse (version (), + _version_major, + _version_minor, + _version_revision); + return _version_minor; + } + + uint64_t + version_revision () { - return RTEMS_VERSION; + if (_version_major == 0) + version_parse (version (), + _version_major, + _version_minor, + _version_revision); + return _version_revision; } void diff --git a/rtemstoolkit/rld.h b/rtemstoolkit/rld.h index 1fedd68..2b6a40d 100644 --- a/rtemstoolkit/rld.h +++ b/rtemstoolkit/rld.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,8 @@ namespace rld class image; class archive; class object; + class cache; + typedef std::list < object* > object_list; } } @@ -178,6 +181,15 @@ namespace rld */ const std::string tolower (const std::string& sin); + /** + * Parse version string of format major.minor.revision where revieion can be + * a git hash. + */ + void version_parse (const std::string& str, + uint64_t& major, + uint64_t& minor, + uint64_t& revision); + /** * Increment the verbose level. */ @@ -194,6 +206,21 @@ namespace rld */ const std::string version (); + /** + * Get the major version number. + */ + uint64_t version_major (); + + /** + * Get the minor version number. + */ + uint64_t version_minor (); + + /** + * Get the revision version number. + */ + uint64_t version_revision (); + /** * Container of strings to hold the results of a split. */ -- cgit v1.2.3