mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-14 19:15:05 -05:00
versions now support tag numbers + tags are now used in comparisons
This commit is contained in:
parent
ed17f11979
commit
bbbf3324eb
8 changed files with 164 additions and 65 deletions
|
@ -15,14 +15,32 @@ string(STRIP "${GEODE_VERSION}" GEODE_VERSION)
|
|||
|
||||
# Check if version has a tag like v1.0.0-alpha
|
||||
string(FIND ${GEODE_VERSION} "-" GEODE_VERSION_HAS_TAG)
|
||||
if (GEODE_VERSION_HAS_TAG)
|
||||
string(REGEX MATCH "[a-z]+[0-9]?$" GEODE_VERSION_TAG ${GEODE_VERSION})
|
||||
if (NOT ${GEODE_VERSION_HAS_TAG} EQUAL "-1")
|
||||
string(REGEX MATCH "[a-z]+(\.[0-9]+)?$" GEODE_VERSION_TAG ${GEODE_VERSION})
|
||||
string(SUBSTRING "${GEODE_VERSION}" 0 ${GEODE_VERSION_HAS_TAG} GEODE_VERSION)
|
||||
string(FIND ${GEODE_VERSION_TAG} "." GEODE_VERSION_TAG_HAS_NUMBER)
|
||||
|
||||
# Extract tag type and number from tag
|
||||
if (NOT ${GEODE_VERSION_TAG_HAS_NUMBER} EQUAL "-1")
|
||||
string(SUBSTRING "${GEODE_VERSION_TAG}" 0 ${GEODE_VERSION_TAG_HAS_NUMBER} GEODE_VERSION_TAG_TYPE)
|
||||
math(EXPR GEODE_VERSION_TAG_HAS_NUMBER "${GEODE_VERSION_TAG_HAS_NUMBER} + 1")
|
||||
string(SUBSTRING "${GEODE_VERSION_TAG}" ${GEODE_VERSION_TAG_HAS_NUMBER} -1 GEODE_VERSION_TAG_NUMBER)
|
||||
else()
|
||||
set(GEODE_VERSION_TAG_TYPE "${GEODE_VERSION_TAG}")
|
||||
set(GEODE_VERSION_TAG_NUMBER "")
|
||||
endif()
|
||||
|
||||
# Capitalize first letter of tag type
|
||||
string(SUBSTRING ${GEODE_VERSION_TAG_TYPE} 0 1 FIRST_LETTER)
|
||||
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
|
||||
string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" GEODE_VERSION_TAG_TYPE "${GEODE_VERSION_TAG_TYPE}")
|
||||
else()
|
||||
set(GEODE_VERSION_TAG "")
|
||||
set(GEODE_VERSION_TAG_TYPE "")
|
||||
set(GEODE_VERSION_TAG_NUMBER "")
|
||||
endif()
|
||||
|
||||
message(STATUS "Version: ${GEODE_VERSION}, tag: ${GEODE_VERSION_TAG}")
|
||||
message(STATUS "Version: ${GEODE_VERSION}, tag: ${GEODE_VERSION_TAG} (type: ${GEODE_VERSION_TAG_TYPE}, number: ${GEODE_VERSION_TAG_NUMBER})")
|
||||
|
||||
project(geode-sdk VERSION ${GEODE_VERSION} LANGUAGES CXX C)
|
||||
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.0.0-beta
|
||||
1.0.0-beta.6
|
|
@ -1,8 +1,21 @@
|
|||
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
|
||||
|
||||
project(geode-loader VERSION ${GEODE_VERSION} LANGUAGES C CXX)
|
||||
set(PROJECT_VERSION_TYPE geode::VersionTag::Beta)
|
||||
set(PROJECT_VERSION_SUFFIX -beta)
|
||||
if (GEODE_VERSION_TAG_TYPE)
|
||||
if (GEODE_VERSION_TAG_NUMBER)
|
||||
set(PROJECT_VERSION_TAG_CONSTR "geode::VersionTag(geode::VersionTag::${GEODE_VERSION_TAG_TYPE}, ${GEODE_VERSION_TAG_NUMBER})")
|
||||
else()
|
||||
set(PROJECT_VERSION_TAG_CONSTR "geode::VersionTag::${GEODE_VERSION_TAG_TYPE}")
|
||||
endif()
|
||||
else()
|
||||
set(PROJECT_VERSION_TAG_CONSTR "std::nullopt")
|
||||
endif()
|
||||
|
||||
if (GEODE_VERSION_TAG)
|
||||
set(PROJECT_VERSION_SUFFIX "-${GEODE_VERSION_TAG}")
|
||||
else()
|
||||
set(PROJECT_VERSION_SUFFIX "")
|
||||
endif()
|
||||
|
||||
# Package info file for internal representation
|
||||
configure_file(resources/mod.json.in ${CMAKE_CURRENT_SOURCE_DIR}/resources/mod.json)
|
||||
|
|
|
@ -14,24 +14,73 @@ namespace geode {
|
|||
};
|
||||
|
||||
/**
|
||||
* A version label, like v1.0.0-alpha or v2.3.4-prerelease. Purely semantic,
|
||||
* and not used in comparisons; so for example v1.0.0-alpha == v1.0.0.
|
||||
* A version label, like v1.0.0-alpha or v2.3.4-prerelease. Limited to these
|
||||
* options; arbitary identifiers are not supported. Additional numbering
|
||||
* may be added after the identifier, such as v1.0.0-beta.1
|
||||
*/
|
||||
enum class VersionTag {
|
||||
Alpha,
|
||||
Beta,
|
||||
Prerelease,
|
||||
struct VersionTag {
|
||||
enum {
|
||||
Alpha,
|
||||
Beta,
|
||||
Prerelease,
|
||||
} value;
|
||||
std::optional<size_t> number;
|
||||
|
||||
using Type = decltype(value);
|
||||
|
||||
constexpr VersionTag(Type const& value) : value(value) {}
|
||||
constexpr VersionTag(Type const& value, std::optional<size_t> number)
|
||||
: value(value), number(number) {}
|
||||
|
||||
constexpr bool operator==(VersionTag const& other) const {
|
||||
return value == other.value && number == other.number;
|
||||
}
|
||||
constexpr bool operator<(VersionTag const& other) const {
|
||||
if (value == other.value) {
|
||||
if (number && other.number) return number < other.number;
|
||||
if (number) return true;
|
||||
if (other.number) return false;
|
||||
return false;
|
||||
}
|
||||
return value < other.value;
|
||||
}
|
||||
constexpr bool operator<=(VersionTag const& other) const {
|
||||
if (value == other.value) {
|
||||
if (number && other.number) return number <= other.number;
|
||||
if (number) return true;
|
||||
if (other.number) return false;
|
||||
return true;
|
||||
}
|
||||
return value <= other.value;
|
||||
}
|
||||
constexpr bool operator>(VersionTag const& other) const {
|
||||
if (value == other.value) {
|
||||
if (number && other.number) return number > other.number;
|
||||
if (number) return true;
|
||||
if (other.number) return false;
|
||||
return false;
|
||||
}
|
||||
return value > other.value;
|
||||
}
|
||||
constexpr bool operator>=(VersionTag const& other) const {
|
||||
if (value == other.value) {
|
||||
if (number && other.number) return number >= other.number;
|
||||
if (number) return true;
|
||||
if (other.number) return false;
|
||||
return true;
|
||||
}
|
||||
return value >= other.value;
|
||||
}
|
||||
|
||||
static Result<VersionTag> parse(std::stringstream& str);
|
||||
std::string toSuffixString() const;
|
||||
std::string toString() const;
|
||||
};
|
||||
GEODE_DLL std::optional<VersionTag> versionTagFromString(std::string const& str);
|
||||
GEODE_DLL std::string versionTagToSuffixString(VersionTag tag);
|
||||
GEODE_DLL std::string versionTagToString(VersionTag tag);
|
||||
|
||||
/**
|
||||
* Class representing version information. Not strictly semver, notably in
|
||||
* regard to identifiers; identifiers are restricted to a few common ones,
|
||||
* and are purely semantic, i.e. not used in comparisons. See VersionTag
|
||||
* for details
|
||||
* @class VersionInfo
|
||||
* Class representing version information. Uses a limited subset of SemVer;
|
||||
* identifiers are restricted to a few predefined ones, and only one
|
||||
* identifier is allowed. See VersionTag for details
|
||||
*/
|
||||
class GEODE_DLL VersionInfo final {
|
||||
protected:
|
||||
|
@ -78,24 +127,24 @@ namespace geode {
|
|||
// Apple clang does not support operator<=>! Yippee!
|
||||
|
||||
constexpr bool operator==(VersionInfo const& other) const {
|
||||
return std::tie(m_major, m_minor, m_patch) ==
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch);
|
||||
return std::tie(m_major, m_minor, m_patch, m_tag) ==
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch, other.m_tag);
|
||||
}
|
||||
constexpr bool operator<(VersionInfo const& other) const {
|
||||
return std::tie(m_major, m_minor, m_patch) <
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch);
|
||||
return std::tie(m_major, m_minor, m_patch, m_tag) <
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch, other.m_tag);
|
||||
}
|
||||
constexpr bool operator<=(VersionInfo const& other) const {
|
||||
return std::tie(m_major, m_minor, m_patch) <=
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch);
|
||||
return std::tie(m_major, m_minor, m_patch, m_tag) <=
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch, other.m_tag);
|
||||
}
|
||||
constexpr bool operator>(VersionInfo const& other) const {
|
||||
return std::tie(m_major, m_minor, m_patch) >
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch);
|
||||
return std::tie(m_major, m_minor, m_patch, m_tag) >
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch, other.m_tag);
|
||||
}
|
||||
constexpr bool operator>=(VersionInfo const& other) const {
|
||||
return std::tie(m_major, m_minor, m_patch) >=
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch);
|
||||
return std::tie(m_major, m_minor, m_patch, m_tag) >=
|
||||
std::tie(other.m_major, other.m_minor, other.m_patch, other.m_tag);
|
||||
}
|
||||
|
||||
std::string toString(bool includeTag = true) const;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"geode": "@PROJECT_VERSION@",
|
||||
"geode": "@PROJECT_VERSION@@PROJECT_VERSION_SUFFIX@",
|
||||
"id": "geode.loader",
|
||||
"version": "@PROJECT_VERSION@@PROJECT_VERSION_SUFFIX@",
|
||||
"name": "Geode",
|
||||
|
|
|
@ -11,6 +11,6 @@ static constexpr geode::VersionInfo LOADER_VERSION = {
|
|||
@PROJECT_VERSION_MAJOR@,
|
||||
@PROJECT_VERSION_MINOR@,
|
||||
@PROJECT_VERSION_PATCH@,
|
||||
@PROJECT_VERSION_TYPE@,
|
||||
@PROJECT_VERSION_TAG_CONSTR@,
|
||||
};
|
||||
static constexpr const char* LOADER_MOD_JSON = R"JSON_SEPARATOR(@LOADER_MOD_JSON@)JSON_SEPARATOR";
|
||||
|
|
|
@ -79,9 +79,7 @@ void ModListCell::setupInfo(
|
|||
this->addChild(versionLabel);
|
||||
|
||||
if (auto tag = info.version().getTag()) {
|
||||
auto tagLabel = TagNode::create(
|
||||
versionTagToString(tag.value()).c_str()
|
||||
);
|
||||
auto tagLabel = TagNode::create(tag.value().toString().c_str());
|
||||
tagLabel->setAnchorPoint({ .0f, .5f });
|
||||
tagLabel->setScale(.3f);
|
||||
tagLabel->setPosition(
|
||||
|
|
|
@ -10,31 +10,57 @@ USE_GEODE_NAMESPACE();
|
|||
|
||||
// VersionTag
|
||||
|
||||
std::optional<VersionTag> geode::versionTagFromString(std::string const& str) {
|
||||
switch (hash(str.c_str())) {
|
||||
case hash("alpha"): return VersionTag::Alpha;
|
||||
case hash("beta"): return VersionTag::Beta;
|
||||
case hash("prerelease"): return VersionTag::Prerelease;
|
||||
default: return std::nullopt;
|
||||
Result<VersionTag> VersionTag::parse(std::stringstream& str) {
|
||||
std::string iden;
|
||||
while ('a' <= str.peek() && str.peek() <= 'z') {
|
||||
iden += str.get();
|
||||
}
|
||||
if (str.fail()) {
|
||||
return Err("Unable to parse tag");
|
||||
}
|
||||
VersionTag tag = VersionTag::Alpha;
|
||||
switch (hash(iden.c_str())) {
|
||||
case hash("alpha"): tag = VersionTag::Alpha; break;
|
||||
case hash("beta"): tag = VersionTag::Beta; break;
|
||||
case hash("prerelease"): case hash("pr"): tag = VersionTag::Prerelease; break;
|
||||
default: return Err("Invalid tag \"" + iden + "\"");
|
||||
}
|
||||
if (str.peek() == '.') {
|
||||
str.get();
|
||||
size_t num;
|
||||
str >> num;
|
||||
if (str.fail()) {
|
||||
return Err("Unable to parse tag number");
|
||||
}
|
||||
tag.number = num;
|
||||
}
|
||||
return Ok(tag);
|
||||
}
|
||||
|
||||
std::string geode::versionTagToSuffixString(VersionTag tag) {
|
||||
switch (tag) {
|
||||
case VersionTag::Alpha: return "-alpha";
|
||||
case VersionTag::Beta: return "-beta";
|
||||
case VersionTag::Prerelease: return "-prerelease";
|
||||
std::string VersionTag::toSuffixString() const {
|
||||
std::string res = "";
|
||||
switch (value) {
|
||||
case Alpha: res += "-alpha"; break;
|
||||
case Beta: res += "-beta"; break;
|
||||
case Prerelease: res += "-prerelease"; break;
|
||||
}
|
||||
return "";
|
||||
if (number) {
|
||||
res += "." + std::to_string(number.value());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string geode::versionTagToString(VersionTag tag) {
|
||||
switch (tag) {
|
||||
case VersionTag::Alpha: return "Alpha";
|
||||
case VersionTag::Beta: return "Beta";
|
||||
case VersionTag::Prerelease: return "Prerelease";
|
||||
std::string VersionTag::toString() const {
|
||||
std::string res = "";
|
||||
switch (value) {
|
||||
case Alpha: res += "Alpha"; break;
|
||||
case Beta: res += "Beta"; break;
|
||||
case Prerelease: res += "Prerelease"; break;
|
||||
}
|
||||
return "";
|
||||
if (number) {
|
||||
res += " " + std::to_string(number.value());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// VersionInfo
|
||||
|
@ -77,18 +103,13 @@ Result<VersionInfo> VersionInfo::parse(std::string const& string) {
|
|||
std::optional<VersionTag> tag;
|
||||
if (str.peek() == '-') {
|
||||
str.get();
|
||||
std::string iden;
|
||||
str >> iden;
|
||||
if (str.fail()) {
|
||||
return Err("Unable to parse tag");
|
||||
}
|
||||
if (auto t = versionTagFromString(iden)) {
|
||||
tag = t;
|
||||
}
|
||||
else {
|
||||
return Err("Invalid tag \"" + iden + "\"");
|
||||
}
|
||||
GEODE_UNWRAP_INTO(tag, VersionTag::parse(str));
|
||||
}
|
||||
|
||||
if (!str.eof()) {
|
||||
return Err("Expected end of version, found '" + std::string(1, str.get()) + "'");
|
||||
}
|
||||
|
||||
return Ok(VersionInfo(major, minor, patch, tag));
|
||||
}
|
||||
|
||||
|
@ -97,7 +118,7 @@ std::string VersionInfo::toString(bool includeTag) const {
|
|||
return fmt::format(
|
||||
"v{}.{}.{}{}",
|
||||
m_major, m_minor, m_patch,
|
||||
versionTagToSuffixString(m_tag.value())
|
||||
m_tag.value().toSuffixString()
|
||||
);
|
||||
}
|
||||
return fmt::format("v{}.{}.{}", m_major, m_minor, m_patch);
|
||||
|
|
Loading…
Reference in a new issue