aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Version.hpp1
-rw-r--r--src/GlobalLib.cpp2
-rw-r--r--src/VersionParser.cpp20
-rw-r--r--tests/src/confTest/confTest.cpp4
-rw-r--r--tests/src/versionTest.cpp22
5 files changed, 34 insertions, 15 deletions
diff --git a/include/Version.hpp b/include/Version.hpp
index 915f622..57a53f5 100644
--- a/include/Version.hpp
+++ b/include/Version.hpp
@@ -6,6 +6,7 @@ namespace sibs
{
enum class VersionOperation
{
+ NONE,
LESS,
LESS_EQUAL,
EQUAL,
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp
index 61e6648..2dd829f 100644
--- a/src/GlobalLib.cpp
+++ b/src/GlobalLib.cpp
@@ -54,7 +54,7 @@ namespace sibs
for(PackageListDependency *globalLibDependency : libs)
{
if(!parentConfig.packaging)
- printf("Dependency %s is missing from pkg-config, trying global lib\n", globalLibDependency->name.c_str());
+ printf("Dependency %s in version range %s is missing from pkg-config, trying global lib\n", globalLibDependency->name.c_str(), globalLibDependency->version.toString().c_str());
Result<bool> globalLibLinkerFlagsResult = GlobalLib::getLibsLinkerFlags(parentConfig, globalLibRootDir, globalLibDependency->name, globalLibDependency->version, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback);
if(!globalLibLinkerFlagsResult)
{
diff --git a/src/VersionParser.cpp b/src/VersionParser.cpp
index 7b28cef..eccd109 100644
--- a/src/VersionParser.cpp
+++ b/src/VersionParser.cpp
@@ -6,13 +6,9 @@ namespace sibs
static int stringToIntNoVerify(const StringView &str)
{
int result = 0;
- if(str.size > 0)
- result += (str[0] - '0');
-
- for(int i = 1; i < (int)str.size; ++i)
+ for(usize i = 0; i < str.size; ++i)
{
- int num = str[i] - '0';
- result += (10 * ((int)str.size - i) * num);
+ result = (result * 10) + (str[i] - '0');
}
return result;
}
@@ -202,6 +198,16 @@ namespace sibs
{
if(!versionRange.startDefined)
return Result<PackageVersionRange>::Err("version can't be empty");
+
+ if(versionRange.startOperation == VersionOperation::NONE)
+ {
+ versionRange.startOperation = VersionOperation::GREATER_EQUAL;
+ versionRange.end.major = versionRange.start.major + 1;
+ versionRange.end.minor = 0;
+ versionRange.end.patch = 0;
+ versionRange.endOperation = VersionOperation::LESS;
+ versionRange.endDefined = true;
+ }
return Result<PackageVersionRange>::Ok(versionRange);
}
else if(token == VersionToken::INVALID)
@@ -246,7 +252,7 @@ namespace sibs
VersionToken token = tokenizer.next();
if(token == VersionToken::VERSION_NUMBER)
{
- versionRange.startOperation = VersionOperation::GREATER_EQUAL;
+ versionRange.startOperation = VersionOperation::NONE;
versionRange.start = tokenizer.version;
versionRange.startDefined = true;
token = tokenizer.next();
diff --git a/tests/src/confTest/confTest.cpp b/tests/src/confTest/confTest.cpp
index a86dbb3..ec8a563 100644
--- a/tests/src/confTest/confTest.cpp
+++ b/tests/src/confTest/confTest.cpp
@@ -26,11 +26,11 @@ TEST_CASE("parse config")
}
auto *xxhashDependency = sibsConfig.getPackageListDependencies()[0]->asPackageListDependency();
REQUIRE(xxhashDependency->name == "xxhash");
- REQUIRE(xxhashDependency->version.toString() == ">=0.1.0");
+ REQUIRE(xxhashDependency->version.toString() == ">=0.1.0 and <1.0.0");
const auto &catch2Dependency = sibsConfig.getPackageListDependencies()[1]->asPackageListDependency();
REQUIRE(catch2Dependency->name == "catch2");
- REQUIRE(catch2Dependency->version.toString() == ">=1.0.0");
+ REQUIRE(catch2Dependency->version.toString() == ">=1.0.0 and <2.0.0");
REQUIRE(sibsConfig.getGitDependencies().size() == 1);
for(auto *dep : sibsConfig.getGitDependencies())
diff --git a/tests/src/versionTest.cpp b/tests/src/versionTest.cpp
index d5a492c..48a8838 100644
--- a/tests/src/versionTest.cpp
+++ b/tests/src/versionTest.cpp
@@ -7,16 +7,20 @@ TEST_CASE("parse package version")
{
VersionParser parser;
{
- Result<PackageVersionRange> parseResult = parser.parse("2.3.4", 5);
+ Result<PackageVersionRange> parseResult = parser.parse("17.3.4", 6);
if(!parseResult)
FAIL(parseResult.getErrMsg());
PackageVersionRange versionRange = parseResult.unwrap();
REQUIRE(versionRange.startDefined);
- REQUIRE(!versionRange.endDefined);
+ REQUIRE(versionRange.endDefined);
REQUIRE(versionRange.startOperation == VersionOperation::GREATER_EQUAL);
- REQUIRE(versionRange.start.major == 2);
+ REQUIRE(versionRange.start.major == 17);
REQUIRE(versionRange.start.minor == 3);
REQUIRE(versionRange.start.patch == 4);
+ REQUIRE(versionRange.endOperation == VersionOperation::LESS);
+ REQUIRE(versionRange.end.major == 18);
+ REQUIRE(versionRange.end.minor == 0);
+ REQUIRE(versionRange.end.patch == 0);
}
{
Result<PackageVersionRange> parseResult = parser.parse("2.3", 3);
@@ -24,11 +28,15 @@ TEST_CASE("parse package version")
FAIL(parseResult.getErrMsg());
PackageVersionRange versionRange = parseResult.unwrap();
REQUIRE(versionRange.startDefined);
- REQUIRE(!versionRange.endDefined);
+ REQUIRE(versionRange.endDefined);
REQUIRE(versionRange.startOperation == VersionOperation::GREATER_EQUAL);
REQUIRE(versionRange.start.major == 2);
REQUIRE(versionRange.start.minor == 3);
REQUIRE(versionRange.start.patch == 0);
+ REQUIRE(versionRange.endOperation == VersionOperation::LESS);
+ REQUIRE(versionRange.end.major == 3);
+ REQUIRE(versionRange.end.minor == 0);
+ REQUIRE(versionRange.end.patch == 0);
}
{
Result<PackageVersionRange> parseResult = parser.parse("2", 1);
@@ -36,11 +44,15 @@ TEST_CASE("parse package version")
FAIL(parseResult.getErrMsg());
PackageVersionRange versionRange = parseResult.unwrap();
REQUIRE(versionRange.startDefined);
- REQUIRE(!versionRange.endDefined);
+ REQUIRE(versionRange.endDefined);
REQUIRE(versionRange.startOperation == VersionOperation::GREATER_EQUAL);
REQUIRE(versionRange.start.major == 2);
REQUIRE(versionRange.start.minor == 0);
REQUIRE(versionRange.start.patch == 0);
+ REQUIRE(versionRange.endOperation == VersionOperation::LESS);
+ REQUIRE(versionRange.end.major == 3);
+ REQUIRE(versionRange.end.minor == 0);
+ REQUIRE(versionRange.end.patch == 0);
}
{
Result<PackageVersionRange> parseResult = parser.parse(">=2.3.4 and <5.6.7", 18);