Merge pull request #622 from MihailRis/fix-versions-operators
Fix versions operators
This commit is contained in:
@@ -255,30 +255,33 @@ function check_dependencies(packinfo)
|
|||||||
if packinfo.dependencies == nil then
|
if packinfo.dependencies == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for i,dep in ipairs(packinfo.dependencies) do
|
for i, dep in ipairs(packinfo.dependencies) do
|
||||||
local depid, depver = unpack(string.split(dep:sub(2,-1), "@"))
|
local depid, depver = unpack(string.split(dep:sub(2,-1), "@"))
|
||||||
|
|
||||||
if dep:sub(1,1) == '!' then
|
if dep:sub(1,1) ~= '!' then
|
||||||
if not table.has(packs_all, depid) then
|
goto continue
|
||||||
return string.format(
|
|
||||||
"%s (%s)", gui.str("error.dependency-not-found"), depid
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local dep_pack = pack.get_info(depid);
|
|
||||||
|
|
||||||
if not compare_version(depver, dep_pack.version) then
|
|
||||||
local op, ver = Version.parse(depver);
|
|
||||||
|
|
||||||
print(string.format("%s: %s !%s %s (%s)", gui.str("error.dependency-version-not-met"), dep_pack.version, op, ver, depid));
|
|
||||||
return string.format("%s: %s != %s (%s)", gui.str("error.dependency-version-not-met"), dep_pack.version, ver, depid);
|
|
||||||
end
|
|
||||||
|
|
||||||
if table.has(packs_installed, packinfo.id) then
|
|
||||||
table.insert(required, depid)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
if not table.has(packs_all, depid) then
|
||||||
|
return string.format(
|
||||||
|
"%s (%s)", gui.str("error.dependency-not-found"), depid
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local dep_pack = pack.get_info(depid);
|
||||||
|
|
||||||
|
if not compare_version(depver, dep_pack.version) then
|
||||||
|
local op, ver = Version.parse(depver)
|
||||||
|
return string.format(
|
||||||
|
"%s: %s != %s (%s)",
|
||||||
|
gui.str("error.dependency-version-not-met"),
|
||||||
|
dep_pack.version, ver, depid
|
||||||
|
);
|
||||||
|
end
|
||||||
|
|
||||||
|
if table.has(packs_installed, packinfo.id) then
|
||||||
|
table.insert(required, depid)
|
||||||
|
end
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#define VC_ENABLE_REFLECTION
|
||||||
#include "ContentPack.hpp"
|
#include "ContentPack.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -146,7 +147,7 @@ ContentPack ContentPack::read(const io::path& folder) {
|
|||||||
std::uint8_t op_size = 0;
|
std::uint8_t op_size = 0;
|
||||||
|
|
||||||
// Two symbol operators
|
// Two symbol operators
|
||||||
if (op == ">=" || op == "=>" || op == "<=" || op == "=<") {
|
if (op == ">=" || op == "<=") {
|
||||||
op_size = 2;
|
op_size = 2;
|
||||||
depVerOperator = op;
|
depVerOperator = op;
|
||||||
}
|
}
|
||||||
@@ -169,7 +170,16 @@ ContentPack ContentPack::read(const io::path& folder) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pack.dependencies.push_back({level, depName, depVer, depVerOperator});
|
VersionOperator versionOperator;
|
||||||
|
if (VersionOperatorMeta.getItem(depVerOperator, versionOperator)) {
|
||||||
|
pack.dependencies.push_back(
|
||||||
|
{level, depName, depVer, versionOperator}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw contentpack_error(
|
||||||
|
pack.id, folder, "invalid version operator"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "typedefs.hpp"
|
||||||
|
#include "content_fwd.hpp"
|
||||||
|
#include "io/io.hpp"
|
||||||
|
#include "util/EnumMetadata.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "typedefs.hpp"
|
|
||||||
#include "content_fwd.hpp"
|
|
||||||
#include "io/io.hpp"
|
|
||||||
|
|
||||||
class EnginePaths;
|
class EnginePaths;
|
||||||
|
|
||||||
class contentpack_error : public std::runtime_error {
|
class contentpack_error : public std::runtime_error {
|
||||||
@@ -25,11 +26,19 @@ public:
|
|||||||
io::path getFolder() const;
|
io::path getFolder() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class DependencyVersionOperator {
|
enum class VersionOperator {
|
||||||
EQUAL, GREATHER, LESS,
|
EQUAL, GREATHER, LESS,
|
||||||
GREATHER_OR_EQUAL, LESS_OR_EQUAL
|
GREATHER_OR_EQUAL, LESS_OR_EQUAL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
VC_ENUM_METADATA(VersionOperator)
|
||||||
|
{"=", VersionOperator::EQUAL},
|
||||||
|
{">", VersionOperator::GREATHER},
|
||||||
|
{"<", VersionOperator::LESS},
|
||||||
|
{">=", VersionOperator::GREATHER_OR_EQUAL},
|
||||||
|
{"<=", VersionOperator::LESS_OR_EQUAL},
|
||||||
|
VC_ENUM_END
|
||||||
|
|
||||||
enum class DependencyLevel {
|
enum class DependencyLevel {
|
||||||
REQUIRED, // dependency must be installed
|
REQUIRED, // dependency must be installed
|
||||||
OPTIONAL, // dependency will be installed if found
|
OPTIONAL, // dependency will be installed if found
|
||||||
@@ -41,7 +50,7 @@ struct DependencyPack {
|
|||||||
DependencyLevel level;
|
DependencyLevel level;
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string version;
|
std::string version;
|
||||||
std::string op;
|
VersionOperator op;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ContentPackStats {
|
struct ContentPackStats {
|
||||||
|
|||||||
@@ -26,26 +26,11 @@ Version::Version(const std::string& version) {
|
|||||||
if (parts.size() > 2) patch = parts[2];
|
if (parts.size() > 2) patch = parts[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
DependencyVersionOperator Version::string_to_operator(const std::string& op) {
|
|
||||||
if (op == "=")
|
|
||||||
return DependencyVersionOperator::EQUAL;
|
|
||||||
else if (op == ">")
|
|
||||||
return DependencyVersionOperator::GREATHER;
|
|
||||||
else if (op == "<")
|
|
||||||
return DependencyVersionOperator::LESS;
|
|
||||||
else if (op == ">=" || op == "=>")
|
|
||||||
return DependencyVersionOperator::GREATHER_OR_EQUAL;
|
|
||||||
else if (op == "<=" || op == "=<")
|
|
||||||
return DependencyVersionOperator::LESS_OR_EQUAL;
|
|
||||||
else
|
|
||||||
return DependencyVersionOperator::EQUAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNumber(const std::string& s) {
|
bool isNumber(const std::string& s) {
|
||||||
return !s.empty() && std::all_of(s.begin(), s.end(), ::is_digit);
|
return !s.empty() && std::all_of(s.begin(), s.end(), ::is_digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Version::matches_pattern(const std::string& version) {
|
bool Version::matchesPattern(const std::string& version) {
|
||||||
for (char c : version) {
|
for (char c : version) {
|
||||||
if (!isdigit(c) && c != '.') {
|
if (!isdigit(c) && c != '.') {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -33,25 +33,22 @@ public:
|
|||||||
return !(*this > other);
|
return !(*this > other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool process_operator(const std::string& op, const Version& other) const {
|
bool processOperator(VersionOperator op, const Version& other) const {
|
||||||
auto dep_op = Version::string_to_operator(op);
|
switch (op) {
|
||||||
|
case VersionOperator::EQUAL:
|
||||||
switch (dep_op) {
|
|
||||||
case DependencyVersionOperator::EQUAL:
|
|
||||||
return *this == other;
|
return *this == other;
|
||||||
case DependencyVersionOperator::GREATHER:
|
case VersionOperator::GREATHER:
|
||||||
return *this > other;
|
return *this > other;
|
||||||
case DependencyVersionOperator::LESS:
|
case VersionOperator::LESS:
|
||||||
return *this < other;
|
return *this < other;
|
||||||
case DependencyVersionOperator::LESS_OR_EQUAL:
|
case VersionOperator::LESS_OR_EQUAL:
|
||||||
return *this <= other;
|
return *this <= other;
|
||||||
case DependencyVersionOperator::GREATHER_OR_EQUAL:
|
case VersionOperator::GREATHER_OR_EQUAL:
|
||||||
return *this >= other;
|
return *this >= other;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DependencyVersionOperator string_to_operator(const std::string& op);
|
static bool matchesPattern(const std::string& version);
|
||||||
static bool matches_pattern(const std::string& version);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#define VC_ENABLE_REFLECTION
|
||||||
#include "PacksManager.hpp"
|
#include "PacksManager.hpp"
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
@@ -109,9 +110,9 @@ static bool resolve_dependencies(
|
|||||||
|
|
||||||
auto dep_pack = found -> second;
|
auto dep_pack = found -> second;
|
||||||
|
|
||||||
if (Version::matches_pattern(dep.version) && Version::matches_pattern(dep_pack.version)
|
if (Version::matchesPattern(dep.version) && Version::matchesPattern(dep_pack.version)
|
||||||
&& Version(dep_pack.version)
|
&& Version(dep_pack.version)
|
||||||
.process_operator(dep.op, Version(dep.version))
|
.processOperator(dep.op, Version(dep.version))
|
||||||
) {
|
) {
|
||||||
// dependency pack version meets the required one
|
// dependency pack version meets the required one
|
||||||
continue;
|
continue;
|
||||||
@@ -120,7 +121,11 @@ static bool resolve_dependencies(
|
|||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
throw contentpack_error(
|
throw contentpack_error(
|
||||||
dep.id, io::path(), "does not meet required version '" + dep.op + dep.version +"' of '" + pack->id + "'"
|
dep.id,
|
||||||
|
io::path(),
|
||||||
|
"does not meet required version '" +
|
||||||
|
VersionOperatorMeta.getNameString(dep.op) + dep.version +
|
||||||
|
"' of '" + pack->id + "'"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
#include <algorithm>
|
#define VC_ENABLE_REFLECTION
|
||||||
#include <filesystem>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include "assets/AssetsLoader.hpp"
|
#include "assets/AssetsLoader.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
@@ -19,6 +15,12 @@
|
|||||||
#include "world/World.hpp"
|
#include "world/World.hpp"
|
||||||
#include "api_lua.hpp"
|
#include "api_lua.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
static int l_pack_get_folder(lua::State* L) {
|
static int l_pack_get_folder(lua::State* L) {
|
||||||
@@ -114,8 +116,16 @@ static int l_pack_get_info(
|
|||||||
default:
|
default:
|
||||||
throw std::runtime_error("");
|
throw std::runtime_error("");
|
||||||
}
|
}
|
||||||
|
auto opString = VersionOperatorMeta.getNameString(dpack.op);
|
||||||
|
|
||||||
lua::pushfstring(L, "%s%s@%s%s", prefix.c_str(), dpack.id.c_str(), dpack.op.c_str(), dpack.version.c_str());
|
lua::pushfstring(
|
||||||
|
L,
|
||||||
|
"%s%s@%s%s",
|
||||||
|
prefix.c_str(),
|
||||||
|
dpack.id.c_str(),
|
||||||
|
(dpack.op == VersionOperator::EQUAL ? "" : opString).c_str(),
|
||||||
|
dpack.version.c_str()
|
||||||
|
);
|
||||||
lua::rawseti(L, i + 1);
|
lua::rawseti(L, i + 1);
|
||||||
}
|
}
|
||||||
lua::setfield(L, "dependencies");
|
lua::setfield(L, "dependencies");
|
||||||
|
|||||||
Reference in New Issue
Block a user