summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2016-04-03 15:37:01 +1000
committerChris Johns <chrisj@rtems.org>2016-04-03 15:37:01 +1000
commit0c0b2d4b529817f4561088c61827af797eee6def (patch)
tree9f174317a926452c0d2b535aec7ae9e21bc65bd4
parenttester: Fix reraising an exception with Python2 and Python3. (diff)
downloadrtems-tools-0c0b2d4b529817f4561088c61827af797eee6def.tar.bz2
rtemstoolkit: Add version number parsing to get major, minor, revision.
Add support to return the major, minor or revision numbers as numbers.
-rw-r--r--rtemstoolkit/rld-rtems.cpp43
-rw-r--r--rtemstoolkit/rld-rtems.h15
-rw-r--r--rtemstoolkit/rld.cpp85
-rw-r--r--rtemstoolkit/rld.h27
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 <chrisj@rtems.org>
+ * Copyright (c) 2011-2016, Chris Johns <chrisj@rtems.org>
*
* 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
@@ -52,6 +52,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.
*/
const std::string arch_bsp ();
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)
@@ -184,6 +194,44 @@ namespace rld
}
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 ()
{
++verbose_level;
@@ -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 <cctype>
#include <functional>
#include <iostream>
+#include <list>
#include <locale>
#include <sstream>
#include <string>
@@ -63,6 +64,8 @@ namespace rld
class image;
class archive;
class object;
+ class cache;
+ typedef std::list < object* > object_list;
}
}
@@ -179,6 +182,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.
*/
void verbose_inc ();
@@ -195,6 +207,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.
*/
typedef std::vector < std::string > strings;