-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1053 from janhq/fix/dynamically-get-cuda-dependen…
…cy-version fix: dynamically get cuda toolkit version
- Loading branch information
Showing
3 changed files
with
139 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,61 @@ | ||
#include <trantor/utils/Logger.h> | ||
#include <sstream> | ||
#include <vector> | ||
|
||
namespace semantic_version_utils { | ||
inline std::vector<int> SplitVersion(const std::string& version) { | ||
std::vector<int> parts; | ||
std::stringstream ss(version); | ||
std::string part; | ||
struct SemVer { | ||
int major; | ||
int minor; | ||
int patch; | ||
}; | ||
|
||
while (std::getline(ss, part, '.')) { | ||
parts.push_back(std::stoi(part)); | ||
inline SemVer SplitVersion(const std::string& version) { | ||
if (version.empty()) { | ||
LOG_WARN << "Passed in version is empty!"; | ||
} | ||
SemVer semVer = {0, 0, 0}; // default value | ||
std::stringstream ss(version); | ||
std::string part; | ||
|
||
while (parts.size() < 3) { | ||
parts.push_back(0); | ||
int index = 0; | ||
while (std::getline(ss, part, '.') && index < 3) { | ||
int value = std::stoi(part); | ||
switch (index) { | ||
case 0: | ||
semVer.major = value; | ||
break; | ||
case 1: | ||
semVer.minor = value; | ||
break; | ||
case 2: | ||
semVer.patch = value; | ||
break; | ||
} | ||
++index; | ||
} | ||
|
||
return parts; | ||
return semVer; | ||
} | ||
|
||
inline int CompareSemanticVersion(const std::string& version1, | ||
const std::string& version2) { | ||
std::vector<int> v1 = SplitVersion(version1); | ||
std::vector<int> v2 = SplitVersion(version2); | ||
|
||
for (size_t i = 0; i < 3; ++i) { | ||
if (v1[i] < v2[i]) | ||
return -1; | ||
if (v1[i] > v2[i]) | ||
return 1; | ||
} | ||
SemVer v1 = SplitVersion(version1); | ||
SemVer v2 = SplitVersion(version2); | ||
|
||
if (v1.major < v2.major) | ||
return -1; | ||
if (v1.major > v2.major) | ||
return 1; | ||
|
||
if (v1.minor < v2.minor) | ||
return -1; | ||
if (v1.minor > v2.minor) | ||
return 1; | ||
|
||
if (v1.patch < v2.patch) | ||
return -1; | ||
if (v1.patch > v2.patch) | ||
return 1; | ||
|
||
return 0; | ||
} | ||
} // namespace semantic_version_utils | ||
} // namespace semantic_version_utils |