Use messmer/gitversion instead of own version parser code
This commit is contained in:
parent
fc7316f06c
commit
12f1e7983b
@ -1,4 +1,5 @@
|
||||
INCLUDE(messmer/cmake/tools)
|
||||
INCLUDE(messmer/gitversion/cmake)
|
||||
|
||||
SETUP_GOOGLETEST()
|
||||
|
||||
@ -9,7 +10,7 @@ ACTIVATE_CPP14()
|
||||
|
||||
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
|
||||
|
||||
ADD_GIT_VERSION(git_version.h)
|
||||
GIT_VERSION_INIT()
|
||||
|
||||
ENABLE_STYLE_WARNINGS()
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
messmer/cmake: 3
|
||||
messmer/cpp-utils: 2
|
||||
messmer/fspp: 0
|
||||
messmer/gitversion: 0
|
||||
|
||||
[parent]
|
||||
messmer/cryfs: 0
|
||||
|
10
src/main.cpp
10
src/main.cpp
@ -10,7 +10,7 @@
|
||||
#include "filesystem/CryDevice.h"
|
||||
#include "config/CryConfigLoader.h"
|
||||
|
||||
#include "version/VersionHandler.h"
|
||||
#include <messmer/gitversion/gitversion.h>
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
@ -23,10 +23,10 @@ using std::endl;
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
cout << "CryFS Version "<<version::VERSION.toString() << endl;
|
||||
if (version::VERSION.is_dev()) {
|
||||
cout << "WARNING! This is a development version based on git commit " << version::GIT_COMMIT_ID << ". Please do not use in production!" << endl;
|
||||
} else if (!version::VERSION.is_stable()) {
|
||||
cout << "CryFS Version " << gitversion::VERSION.toString() << endl;
|
||||
if (gitversion::VERSION.isDev()) {
|
||||
cout << "WARNING! This is a development version based on git commit " << gitversion::VERSION.gitCommitId().toStdString() << ". Please do not use in production!" << endl;
|
||||
} else if (!gitversion::VERSION.isStable()) {
|
||||
cout << "WARNING! This is an experimental version. Please backup your data frequently!" << endl;
|
||||
}
|
||||
cout << endl;
|
||||
|
@ -1,78 +0,0 @@
|
||||
#ifndef MESSMER_CRYFS_VERSION_H
|
||||
#define MESSMER_CRYFS_VERSION_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <messmer/cpp-utils/constexpr/const_string.h>
|
||||
|
||||
namespace version {
|
||||
enum class VersionTag : unsigned char {
|
||||
ALPHA, BETA, RC1, FINAL
|
||||
};
|
||||
|
||||
constexpr cpputils::const_string VersionTagToString(VersionTag tag) {
|
||||
return (tag == VersionTag::ALPHA) ? "alpha" :
|
||||
(tag == VersionTag::BETA) ? "beta" :
|
||||
(tag == VersionTag::RC1) ? "rc1" :
|
||||
(tag == VersionTag::FINAL) ? "" :
|
||||
throw std::logic_error("Unknown version tag");
|
||||
}
|
||||
|
||||
class Version {
|
||||
public:
|
||||
constexpr Version(unsigned int major, unsigned int minor, VersionTag tag, unsigned int commitsSinceVersion,
|
||||
const cpputils::const_string &gitCommitId)
|
||||
: _major(major), _minor(minor), _tag(tag), _commitsSinceVersion(commitsSinceVersion),
|
||||
_gitCommitId(gitCommitId) { }
|
||||
|
||||
constexpr unsigned int major() {
|
||||
return _major;
|
||||
}
|
||||
|
||||
constexpr unsigned int minor() {
|
||||
return _minor;
|
||||
}
|
||||
|
||||
constexpr VersionTag tag() {
|
||||
return _tag;
|
||||
}
|
||||
|
||||
constexpr bool is_dev() {
|
||||
return _commitsSinceVersion != 0;
|
||||
}
|
||||
|
||||
constexpr bool is_stable() {
|
||||
return (!is_dev()) && _tag == VersionTag::FINAL;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const Version &rhs) {
|
||||
return _major == rhs._major && _minor == rhs._minor && _tag == rhs._tag;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const Version &rhs) {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
std::string toString() const {
|
||||
if (is_dev()) {
|
||||
return _versionTagString() + "-dev" + std::to_string(_commitsSinceVersion) + "-" + _gitCommitId.toStdString();
|
||||
} else {
|
||||
return _versionTagString();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string _versionTagString() const {
|
||||
return std::to_string(_major) + "." + std::to_string(_minor) + VersionTagToString(_tag).toStdString();
|
||||
}
|
||||
|
||||
const unsigned int _major;
|
||||
const unsigned int _minor;
|
||||
const VersionTag _tag;
|
||||
const unsigned int _commitsSinceVersion;
|
||||
const cpputils::const_string _gitCommitId;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
#ifndef MESSMER_CRYFS_VERSIONHANDLER_H
|
||||
#define MESSMER_CRYFS_VERSIONHANDLER_H
|
||||
|
||||
#include "Version.h"
|
||||
#include "VersionParser.h"
|
||||
|
||||
namespace git_version_builder {
|
||||
#include "git_version.h"
|
||||
}
|
||||
|
||||
namespace version {
|
||||
constexpr unsigned int COMMITS_SINCE_TAG = git_version_builder::version::COMMITS_SINCE_TAG;
|
||||
constexpr const char *GIT_COMMIT_ID = git_version_builder::version::GIT_COMMIT_ID;
|
||||
constexpr const Version VERSION = VersionParser::parse(git_version_builder::version::TAG_NAME,
|
||||
git_version_builder::version::COMMITS_SINCE_TAG,
|
||||
git_version_builder::version::GIT_COMMIT_ID);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,46 +0,0 @@
|
||||
#ifndef MESSMER_CRYFS_VERSIONPARSER_H
|
||||
#define MESSMER_CRYFS_VERSIONPARSER_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include "Version.h"
|
||||
#include <messmer/cpp-utils/constexpr/const_string.h>
|
||||
|
||||
namespace version {
|
||||
class VersionParser {
|
||||
public:
|
||||
static constexpr Version parse(const cpputils::const_string &tagName, unsigned int commitsSinceVersion,
|
||||
const cpputils::const_string &gitCommitId) {
|
||||
return Version(VersionParser::extractMajor(tagName),
|
||||
VersionParser::extractMinor(tagName),
|
||||
parseTag(extractTag(tagName)),
|
||||
commitsSinceVersion,
|
||||
gitCommitId
|
||||
);
|
||||
}
|
||||
|
||||
static constexpr unsigned int extractMajor(const cpputils::const_string &input) {
|
||||
return input.parseUIntPrefix();
|
||||
}
|
||||
|
||||
static constexpr unsigned int extractMinor(const cpputils::const_string &input) {
|
||||
return (input.dropUIntPrefix()[0] == '.') ? input.dropUIntPrefix().dropPrefix(1).parseUIntPrefix()
|
||||
: throw std::logic_error(
|
||||
"Minor version should be separated by a dot");
|
||||
}
|
||||
|
||||
static constexpr cpputils::const_string extractTag(const cpputils::const_string &input) {
|
||||
return input.dropUIntPrefix().dropPrefix(1).dropUIntPrefix();
|
||||
}
|
||||
|
||||
static constexpr VersionTag parseTag(const cpputils::const_string &input) {
|
||||
return (VersionTagToString(VersionTag::ALPHA) == input) ? VersionTag::ALPHA :
|
||||
(VersionTagToString(VersionTag::BETA) == input) ? VersionTag::BETA :
|
||||
(VersionTagToString(VersionTag::RC1) == input) ? VersionTag::RC1 :
|
||||
(VersionTagToString(VersionTag::FINAL) == input) ? VersionTag::FINAL :
|
||||
throw std::logic_error("Not a valid version tag");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,54 +0,0 @@
|
||||
#include "../../src/version/Version.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <google/gtest/gtest.h>
|
||||
|
||||
using namespace version;
|
||||
using cpputils::const_string;
|
||||
|
||||
static_assert(const_string("alpha") == VersionTagToString(VersionTag::ALPHA), "VersionTag::ALPHA toString");
|
||||
static_assert(const_string("beta") == VersionTagToString(VersionTag::BETA), "VersionTag::BETA toString");
|
||||
static_assert(const_string("rc1") == VersionTagToString(VersionTag::RC1), "VersionTag::RC1 toString");
|
||||
static_assert(const_string("") == VersionTagToString(VersionTag::FINAL), "VersionTag::FINAL toString");
|
||||
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 0, "commitid") == Version(1, 0, VersionTag::ALPHA, 0, "commitid"), "Equality for equals");
|
||||
static_assert(Version(0, 8, VersionTag::FINAL, 2, "commitid") == Version(0, 8, VersionTag::FINAL, 2, "commitid"), "Equality for equals");
|
||||
static_assert(!(Version(1, 0, VersionTag::ALPHA, 0, "commitid") != Version(1, 0, VersionTag::ALPHA, 0, "commitid")), "Inequality for equals");
|
||||
static_assert(!(Version(0, 8, VersionTag::FINAL, 2, "commitid") != Version(0, 8, VersionTag::FINAL, 2, "commitid")), "Inequality for equals");
|
||||
|
||||
static_assert(!(Version(1, 0, VersionTag::ALPHA, 0, "commitid") == Version(2, 0, VersionTag::ALPHA, 0, "commitid")), "Equality for inequal major");
|
||||
static_assert(!(Version(1, 0, VersionTag::ALPHA, 0, "commitid") == Version(1, 1, VersionTag::ALPHA, 0, "commitid")), "Equality for inequal minor");
|
||||
static_assert(!(Version(1, 0, VersionTag::ALPHA, 0, "commitid") == Version(1, 0, VersionTag::FINAL, 0, "commitid")), "Equality for inequal tag");
|
||||
static_assert(!(Version(1, 0, VersionTag::ALPHA, 0, "commitid") == Version(1, 0, VersionTag::FINAL, 1, "commitid")), "Equality for inequal commitsSinceVersion");
|
||||
static_assert(!(Version(1, 0, VersionTag::ALPHA, 0, "commitid") == Version(1, 0, VersionTag::FINAL, 0, "commitid2")), "Equality for inequal gitCommitId");
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 0, "commitid") != Version(2, 0, VersionTag::ALPHA, 0, "commitid"), "Inequality for inequal major");
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 0, "commitid") != Version(1, 1, VersionTag::ALPHA, 0, "commitid"), "Inequality for inequal minor");
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 0, "commitid") != Version(1, 0, VersionTag::FINAL, 0, "commitid"), "Inequality for inequal tag");
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 0, "commitid") != Version(1, 0, VersionTag::FINAL, 1, "commitid"), "Inequality for inequal commitsSinceVersion");
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 0, "commitid") != Version(1, 0, VersionTag::FINAL, 0, "commitid2"), "Inequality for inequal gitCommitId");
|
||||
|
||||
static_assert(!Version(1, 0, VersionTag::ALPHA, 0, "commitid").is_stable(), "Alpha is not stable");
|
||||
static_assert(!Version(1, 0, VersionTag::BETA, 0, "commitid").is_stable(), "Beta is not stable");
|
||||
static_assert(!Version(1, 0, VersionTag::RC1, 0, "commitid").is_stable(), "RC1 is not stable");
|
||||
static_assert(Version(1, 0, VersionTag::FINAL, 0, "commitid").is_stable(), "Final is stable");
|
||||
static_assert(!Version(1, 0, VersionTag::FINAL, 1, "commitid").is_stable(), "Final is not stable if there have been commits since");
|
||||
|
||||
static_assert(!Version(1, 0, VersionTag::FINAL, 0, "commitid").is_dev(), "Is not dev version when there haven't been commits since the last tag");
|
||||
static_assert(!Version(1, 0, VersionTag::ALPHA, 0, "commitid").is_dev(), "Is not dev version when there haven't been commits since the last tag, also for alpha versions");
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 1, "commitid").is_dev(), "Is dev version when there haven't been commits since the last tag");
|
||||
static_assert(Version(1, 0, VersionTag::FINAL, 1, "commitid").is_dev(), "Is dev version when there haven't been commits since the last tag, also for final versions");
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 103, "commitid").is_dev(), "Is dev version when there haven't been commits since the last tag, also for higher commit counts");
|
||||
|
||||
TEST(VersionTest, ToString) {
|
||||
EXPECT_EQ("0.8alpha", Version(0, 8, VersionTag::ALPHA, 0, "commitid").toString());
|
||||
EXPECT_EQ("1.2beta", Version(1, 2, VersionTag::BETA, 0, "commitid").toString());
|
||||
EXPECT_EQ("12.0rc1", Version(12, 0, VersionTag::RC1, 0, "commitid").toString());
|
||||
EXPECT_EQ("12.34", Version(12, 34, VersionTag::FINAL, 0, "commitid").toString());
|
||||
}
|
||||
|
||||
TEST(VersionTest, ToString_WithCommitsSinceVersion) {
|
||||
EXPECT_EQ("0.8alpha-dev2-commitid1", Version(0, 8, VersionTag::ALPHA, 2, "commitid1").toString());
|
||||
EXPECT_EQ("1.2beta-dev1-commitid2", Version(1, 2, VersionTag::BETA, 1, "commitid2").toString());
|
||||
EXPECT_EQ("12.0rc1-dev5-commitid3", Version(12, 0, VersionTag::RC1, 5, "commitid3").toString());
|
||||
EXPECT_EQ("12.34-dev103-commitid4", Version(12, 34, VersionTag::FINAL, 103, "commitid4").toString());
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#include "../../src/version/VersionParser.h"
|
||||
#include <cstring>
|
||||
|
||||
using namespace version;
|
||||
using cpputils::const_string;
|
||||
|
||||
static_assert(0 == VersionParser::extractMajor("0.8"), "\"0.8\" has major version 0");
|
||||
static_assert(0 == VersionParser::extractMajor("0.8alpha"), "\"0.8alpha\" has major version 0");
|
||||
static_assert(1 == VersionParser::extractMajor("1.0"), "\"1.0\" has major version 1");
|
||||
static_assert(1 == VersionParser::extractMajor("1.0alpha"), "\"1.0alpha\" has major version 1");
|
||||
static_assert(1 == VersionParser::extractMajor("01.0"), "\"01.0\" has major version 1");
|
||||
static_assert(12 == VersionParser::extractMajor("12.3"), "\"12.3\" has major version 12");
|
||||
static_assert(12 == VersionParser::extractMajor("12.3alpha"), "\"12.3alpha\" has major version 12");
|
||||
|
||||
static_assert(0 == VersionParser::extractMinor("0.0"), "\"0.0\" has minor version 0");
|
||||
static_assert(1 == VersionParser::extractMinor("0.01"), "\"0.01\" has minor version 1");
|
||||
static_assert(34 == VersionParser::extractMinor("12.34"), "\"12.34\" has minor version 34");
|
||||
static_assert(34 == VersionParser::extractMinor("12.34alpha"), "\"12.34alpha\" has minor version 34");
|
||||
|
||||
static_assert(const_string("") == VersionParser::extractTag("0.0"), "\"0.0\" has no version tag");
|
||||
static_assert(const_string("") == VersionParser::extractTag("0.01"), "\"0.01\" has no version tag");
|
||||
static_assert(const_string("") == VersionParser::extractTag("12.34"), "\"12.34\" has no version tag");
|
||||
static_assert(const_string("alpha") == VersionParser::extractTag("12.34alpha"), "\"12.34alpha\" has alpha version tag");
|
||||
static_assert(const_string("rc1") == VersionParser::extractTag("12.34rc1"), "\"12.34rc1\" has rc1 version tag");
|
||||
static_assert(const_string("rc1") == VersionParser::extractTag("1.0rc1"), "\"1.0rc1\" has rc1 version tag");
|
||||
|
||||
static_assert(VersionTag::ALPHA == VersionParser::parseTag("alpha"), "alpha version tag should be parseable");
|
||||
static_assert(VersionTag::BETA == VersionParser::parseTag("beta"), "beta version tag should be parseable");
|
||||
static_assert(VersionTag::RC1 == VersionParser::parseTag("rc1"), "rc1 version tag should be parseable");
|
||||
static_assert(VersionTag::FINAL == VersionParser::parseTag(""), "final version tag should be parseable");
|
||||
|
||||
static_assert(Version(1, 0, VersionTag::ALPHA, 0, "commitid") == VersionParser::parse("1.0alpha", 0, "commitid"), "1.0alpha should parse correctly");
|
||||
static_assert(Version(12, 34, VersionTag::BETA, 0, "commitid") == VersionParser::parse("12.34beta", 0, "commitid"), "12.34beta should parse correctly");
|
||||
static_assert(Version(0, 8, VersionTag::RC1, 0, "commitid") == VersionParser::parse("0.8rc1", 0, "commitid"), "0.8rc1 should parse correctly");
|
||||
static_assert(Version(1, 2, VersionTag::FINAL, 0, "commitid") == VersionParser::parse("1.2", 0, "commitid"), "1.2 should parse correctly");
|
||||
static_assert(Version(1, 2, VersionTag::FINAL, 0, "commitid") == VersionParser::parse("1.02", 0, "commitid"), "1.02 should parse correctly");
|
||||
static_assert(Version(1, 20, VersionTag::FINAL, 0, "commitid") == VersionParser::parse("1.20", 0, "commitid"), "1.20 should parse correctly");
|
||||
static_assert(Version(1, 20, VersionTag::FINAL, 0, "commitid") == VersionParser::parse("1.020", 0, "commitid"), "1.020 should parse correctly");
|
||||
|
||||
static_assert(Version(1, 20, VersionTag::FINAL, 103, "commitid") == VersionParser::parse("1.020", 103, "commitid"), "commitsSinceVersion should parse correctly");
|
||||
static_assert(Version(1, 20, VersionTag::FINAL, 103, "other_commitid") == VersionParser::parse("1.020", 103, "other_commitid"), "commitId should parse correctly");
|
Loading…
Reference in New Issue
Block a user