Rework how libloot's version is exposed in the API

- Don't use a class, it doesn't add anything.
- Use constexpr for the individual version numbers
- Use a function to get the revision string, for consistency with the
  version string.
This commit is contained in:
Oliver Hamlet
2022-02-23 16:50:58 +00:00
parent 412f5f5e60
commit 00b93526b2
7 changed files with 68 additions and 42 deletions
+13 -3
View File
@@ -4,6 +4,15 @@ API Reference
.. contents::
Constants
=========
.. doxygenvariable:: loot::LIBLOOT_VERSION_MAJOR
.. doxygenvariable:: loot::LIBLOOT_VERSION_MINOR
.. doxygenvariable:: loot::LIBLOOT_VERSION_PATCH
Enumerations
============
@@ -30,6 +39,10 @@ Functions
.. doxygenfunction:: loot::CreateGameHandle
.. doxygenfunction:: loot::GetLiblootVersion
.. doxygenfunction:: loot::GetLiblootRevision
Interfaces
==========
@@ -60,9 +73,6 @@ Classes
.. doxygenclass:: loot::Location
:members:
.. doxygenclass:: loot::LootVersion
:members:
.. doxygenclass:: loot::MessageContent
:members:
+17 -21
View File
@@ -30,30 +30,26 @@ along with LOOT. If not, see
#include "loot/api_decorator.h"
namespace loot {
/** @brief libloot's major version number. */
inline constexpr unsigned int LIBLOOT_VERSION_MAJOR = 0;
/** @brief libloot's minor version number. */
inline constexpr unsigned int LIBLOOT_VERSION_MINOR = 17;
/** @brief libloot's patch version number. */
inline constexpr unsigned int LIBLOOT_VERSION_PATCH = 3;
/**
* @brief A purely static class that provides information about the version of
* libloot that is being run.
* @brief Get the library version.
* @return A string of the form "major.minor.patch".
*/
class LootVersion {
public:
/** @brief The major version number. */
LOOT_API static const unsigned int major;
LOOT_API std::string GetLiblootVersion();
/** @brief The minor version number. */
LOOT_API static const unsigned int minor;
/** @brief The patch version number. */
LOOT_API static const unsigned int patch;
/** @brief The source control revision that the API was built from. */
LOOT_API static const std::string revision;
/**
* @brief Get the API version as a string.
* @return A string of the form "major.minor.patch".
*/
LOOT_API static std::string GetVersionString();
};
/**
* @brief Get the source control revision that libloot was built from.
* @return A string containing the revision ID.
*/
LOOT_API std::string GetLiblootRevision();
}
#endif
+7 -3
View File
@@ -145,7 +145,9 @@ LOOT_API bool operator<=(const Message& lhs, const Message& rhs);
LOOT_API bool operator>=(const Message& lhs, const Message& rhs);
/**
* Get the message as a SimpleMessage given a language.
* Get a given Message as a SimpleMessage given a language.
* @param message
* The message to convert.
* @param language
* The preferred language for the message content.
* @return A SimpleMessage object for the preferred language, or for English
@@ -156,7 +158,9 @@ LOOT_API std::optional<SimpleMessage> ToSimpleMessage(
const std::string& language);
/**
* Get the messages as SimpleMessages given a language.
* Get the given messages as simple messages given a language.
* @param messages
* The messages to convert.
* @param language
* The preferred language for the message content.
* @return A vector of SimpleMessage objects for the preferred language, or for
@@ -165,7 +169,7 @@ LOOT_API std::optional<SimpleMessage> ToSimpleMessage(
* without the preferred language or English content will be omitted.
*/
LOOT_API std::vector<SimpleMessage> ToSimpleMessages(
const std::vector<Message>& message,
const std::vector<Message>& messages,
const std::string& language);
}
+4 -4
View File
@@ -20,9 +20,9 @@ def replace_in_file(path, regex, replacement):
def update_cpp_file(path, version):
version_parts = version.split('.')
replace_in_file(path, 'LootVersion::major = \d+;', 'LootVersion::major = {};'.format(version_parts[0]))
replace_in_file(path, 'LootVersion::minor = \d+;', 'LootVersion::minor = {};'.format(version_parts[1]))
replace_in_file(path, 'LootVersion::patch = \d+;', 'LootVersion::patch = {};'.format(version_parts[2]))
replace_in_file(path, 'LIBLOOT_VERSION_MAJOR = \d+;', 'LIBLOOT_VERSION_MAJOR = {};'.format(version_parts[0]))
replace_in_file(path, 'LIBLOOT_VERSION_MINOR = \d+;', 'LIBLOOT_VERSION_MINOR = {};'.format(version_parts[1]))
replace_in_file(path, 'LIBLOOT_VERSION_PATCH = \d+;', 'LIBLOOT_VERSION_PATCH = {};'.format(version_parts[2]))
def update_resource_file(path, version):
comma_separated_version = version.replace('.', ', ')
@@ -42,5 +42,5 @@ if __name__ == "__main__":
if len(arguments.version[0].split('.')) != 3:
raise RuntimeError('The version number must be a three-part semantic version.')
update_cpp_file(os.path.join('src', 'api', 'loot_version.cpp.in'), arguments.version[0])
update_cpp_file(os.path.join('include', 'loot', 'loot_version.h'), arguments.version[0])
update_resource_file(os.path.join('src', 'api', 'resource.rc'), arguments.version[0])
+2 -2
View File
@@ -67,9 +67,9 @@ LOOT_API bool IsCompatible(const unsigned int versionMajor,
const unsigned int versionMinor,
const unsigned int) {
if (versionMajor > 0)
return versionMajor == loot::LootVersion::major;
return versionMajor == LIBLOOT_VERSION_MAJOR;
else
return versionMinor == loot::LootVersion::minor;
return versionMinor == LIBLOOT_VERSION_MINOR;
}
LOOT_API std::unique_ptr<GameInterface> CreateGameHandle(
+9 -6
View File
@@ -25,12 +25,15 @@
#include "loot/loot_version.h"
namespace loot {
const unsigned int LootVersion::major = 0;
const unsigned int LootVersion::minor = 17;
const unsigned int LootVersion::patch = 3;
const std::string LootVersion::revision = "@GIT_COMMIT_STRING@";
LOOT_API std::string GetLiblootVersion() {
static const std::string version =
std::to_string(LIBLOOT_VERSION_MAJOR) + '.' +
std::to_string(LIBLOOT_VERSION_MINOR) + '.' +
std::to_string(LIBLOOT_VERSION_PATCH);
return version;
}
LOOT_API std::string LootVersion::GetVersionString() {
return std::to_string(major) + '.' + std::to_string(minor) + '.' + std::to_string(patch);
LOOT_API std::string GetLiblootRevision() {
return "@GIT_COMMIT_STRING@";
}
}
+16 -3
View File
@@ -34,13 +34,26 @@ namespace test {
TEST(IsCompatible,
shouldReturnTrueWithEqualMajorAndMinorVersionsAndUnequalPatchVersion) {
EXPECT_TRUE(IsCompatible(
LootVersion::major, LootVersion::minor, LootVersion::patch + 1));
LIBLOOT_VERSION_MAJOR, LIBLOOT_VERSION_MINOR, LIBLOOT_VERSION_PATCH));
}
TEST(IsCompatible,
shouldReturnFalseWithEqualMajorVersionAndUnequalMinorAndPatchVersions) {
EXPECT_FALSE(IsCompatible(
LootVersion::major, LootVersion::minor + 1, LootVersion::patch + 1));
EXPECT_FALSE(IsCompatible(LIBLOOT_VERSION_MAJOR,
LIBLOOT_VERSION_MINOR + 1,
LIBLOOT_VERSION_PATCH + 1));
}
TEST(GetLiblootRevision, shouldReturnANonEmptyString) {
EXPECT_FALSE(GetLiblootRevision().empty());
}
TEST(GetVersion, shouldConcatenateMajorMinorAndPatchVersionNumbersWithPeriods) {
auto expectedVersion = std::to_string(LIBLOOT_VERSION_MAJOR) + "." +
std::to_string(LIBLOOT_VERSION_MINOR) + "." +
std::to_string(LIBLOOT_VERSION_PATCH);
EXPECT_EQ(expectedVersion, GetLiblootVersion());
}
}
}