Use SemanticVersion for BuildInfo

This commit is contained in:
Vinnie Falco
2013-08-01 14:12:48 -07:00
parent 786d9ec56e
commit 1a37c99b87
4 changed files with 51 additions and 186 deletions

View File

@@ -1,5 +1,10 @@
Vinnie Falco's Change Log
2013/08/01
- Add beast::SemanticVersion
- Change rippled to use SemanticVersion
2013/07/31
- Add "hostname" to server_info output

View File

@@ -17,6 +17,8 @@ Vinnie's List: Changes day to day, descending priority
- Improved Mutex to track deadlocks
- Work on KeyvaDB
- Allow skipped/disabled unit tests and reporting.
- Supress useless gcc warnings
http://stackoverflow.com/questions/3378560/how-to-disable-gcc-warnings-for-a-few-lines-of-code
David Features:
- override config items from command line

View File

@@ -4,7 +4,7 @@
*/
//==============================================================================
String const& BuildInfo::getVersionString ()
char const* BuildInfo::getRawVersionString ()
{
static char const* const rawText =
@@ -12,29 +12,16 @@ String const& BuildInfo::getVersionString ()
//
// The build version number (edit this for each release)
//
"0.010-rc1"
"0.11.0-rc1"
//
// Must follow the format described here:
//
// http://semver.org/
//
//--------------------------------------------------------------------------
;
struct SanityChecker
{
SanityChecker ()
{
Version v;
if (! v.parse (rawText) || v.print () != rawText)
Throw (std::invalid_argument ("illegal server version format string"));
versionString = rawText;
}
String versionString;
};
static SanityChecker value;
return value.versionString;
return rawText;
}
BuildInfo::Protocol const& BuildInfo::getCurrentProtocol ()
@@ -71,10 +58,36 @@ BuildInfo::Protocol const& BuildInfo::getMinimumProtocol ()
return minimumProtocol;
}
//
//
// Don't touch anything below this line
//
//------------------------------------------------------------------------------
String const& BuildInfo::getVersionString ()
{
struct SanityChecker
{
SanityChecker ()
{
SemanticVersion v;
char const* const rawText = getRawVersionString ();
if (! v.parse (rawText) || v.print () != rawText)
FatalError ("Bad server version string", __FILE__, __LINE__);
versionString = rawText;
}
String versionString;
};
static SanityChecker value;
return value.versionString;
}
char const* BuildInfo::getFullVersionString ()
{
struct PrettyPrinter
@@ -98,90 +111,6 @@ char const* BuildInfo::getFullVersionString ()
//------------------------------------------------------------------------------
BuildInfo::Version::Version ()
: vmajor (0)
, vminor (0)
{
}
bool BuildInfo::Version::parse (String const& s)
{
// Many not have leading or trailing whitespace
if (s.trim () != s)
return false;
int const indexOfDot = s.indexOfChar ('.');
// Must have a dot
if (indexOfDot == -1)
return false;
String const majorString = s.substring (0, indexOfDot);
// Must only contain digits
if (! majorString.containsOnly ("0123456789"))
return false;
// Must match after conversion back and forth
if (String (majorString.getIntValue ()) != majorString)
return false;
int const indexOfDash = s.indexOfChar ('-');
// A dash must come after the dot.
if (indexOfDash >= 0 && indexOfDash <= indexOfDot)
return false;
String const minorString = (indexOfDash == -1) ?
s.substring (indexOfDot + 1) : s.substring (indexOfDot + 1, indexOfDash);
// Must be length three
if (minorString.length () != 3)
return false;
// Must only contain digits
if (! minorString.containsOnly ("0123456789"))
return false;
String const suffixString = (indexOfDash == -1) ?
"" : s.substring (indexOfDash + 1);
if (suffixString.length () > 0)
{
// Must be 4 characters or less
if (suffixString.length () > 4)
return false;
// Must start with a letter
if (! String::charToString (suffixString [0]).containsOnly ("abcdefghijklmnopqrstuvwxyz"))
return false;
// Must only contain letters and numbers
if (! String::charToString (suffixString [0]).containsOnly ("abcdefghijklmnopqrstuvwxyz01234567890"))
return false;
}
vmajor = majorString.getIntValue ();
vminor = minorString.getIntValue ();
suffix = suffixString;
return true;
}
String BuildInfo::Version::print () const noexcept
{
String s;
s << String (vmajor) << "." << String (vminor).paddedLeft ('0', 3);
if (suffix.isNotEmpty ())
s << "-" << suffix;
return s;
}
//------------------------------------------------------------------------------
BuildInfo::Protocol::Protocol ()
: vmajor (0)
, vminor (0)
@@ -223,45 +152,13 @@ public:
{
}
void checkVersion (String const& s)
{
BuildInfo::Version v;
expect (v.parse (s));
// Conversion back and forth should be identical
expect (v.print () == s);
}
void testVersion ()
{
beginTestCase ("version");
BuildInfo::Version v;
SemanticVersion v;
checkVersion ("0.000");
checkVersion ("1.002");
checkVersion ("10.002");
checkVersion ("99.999");
checkVersion ("99.999-r");
checkVersion ("99.999-r1");
checkVersion ("99.999-r123");
unexpected (v.parse (" 1.2")); // Many not have leading or trailing whitespace
unexpected (v.parse ("1.2 ")); // Many not have leading or trailing whitespace
unexpected (v.parse (" 1.2 ")); // Many not have leading or trailing whitespace
unexpected (v.parse ("2")); // Must have a dot
unexpected (v.parse ("23")); // Must have a dot
unexpected (v.parse ("4-rc1")); // Must have a dot
unexpected (v.parse ("01.000")); // No leading zeroes
unexpected (v.parse ("4-4.r")); // A dash must come after the dot.
unexpected (v.parse ("1.2345")); // Must be length three
unexpected (v.parse ("1a.2")); // Must only contain digits
unexpected (v.parse ("1.2b")); // Must only contain digits
unexpected (v.parse ("1.2-rxxx1")); // Must be 4 characters or less
unexpected (v.parse ("1.2-")); // Must start with a letter
unexpected (v.parse ("1.2-3")); // Must start with a letter
unexpected (v.parse ("1.2-r!")); // Must only contain letters and numbers
expect (v.parse (BuildInfo::getRawVersionString ()));
}
void checkProtcol (unsigned short vmajor, unsigned short vminor)

View File

@@ -12,33 +12,9 @@ struct BuildInfo
{
/** Server version.
The server version has three parts:
Follows the Semantic Versioning Specification:
<major> A non negative integer.
<minor> An integer between 0 and 999 inclusive.
<suffix> An optional string. For example, "rc1"
The version string is formatted thusly:
<major> '.' <minor> ['-' <suffix>]
The minor version number is always padded with leading zeroes
to bring the number of characters up to exactly three. For example,
the server version string "12.045-rc1" has major version 12, minor
version 45, and suffix "rc1". A suffix may only consist of lowercase
letters and digits, and must start with a letter. The suffix may
be up to 4 characters. The major version may not be prefixed with
extra leading zeroes.
The suffix for a new official release is usually omitted. If hotfixes
are added to official releases they get a single leter suffix.
Release candidates are marked with suffixes starting with "rc" and
followed by a number starting from 1 to indicate the first
release candidate, with subsequent release candidates incrementing
the number. A final release candidate which becomes an official
release loses the suffix. The next release candidate will have a
new major or minor version number, and start back at "rc1".
http://semver.org/
*/
static String const& getVersionString ();
@@ -49,26 +25,6 @@ struct BuildInfo
*/
static char const* getFullVersionString ();
/** The server version's components. */
struct Version
{
int vmajor; // 0+
int vminor; // 0-999
String suffix; // Can be empty
//----
Version ();
/** Convert a string to components.
@return `false` if the string is improperly formatted.
*/
bool parse (String const& s);
/** Convert the components to a string. */
String print () const noexcept;
};
//--------------------------------------------------------------------------
/** The wire protocol version.
@@ -107,6 +63,11 @@ struct BuildInfo
/** The oldest protocol version we will accept. */
static Protocol const& getMinimumProtocol ();
private:
friend class BuildInfoTests;
static char const* getRawVersionString ();
};
#endif