aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-18 07:05:43 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit6bb79ef033c2a2e8f12c9da6409e3547af40417c (patch)
tree6fe6c5bea99cc0b38af92a7aa4714e5614de4868 /include
parent4e38f2af2b97850ec5b395d4e0ea8310e664e52f (diff)
Use ranges for dependency version
Diffstat (limited to 'include')
-rw-r--r--include/Conf.hpp4
-rw-r--r--include/Dependency.hpp3
-rw-r--r--include/FileUtil.hpp5
-rw-r--r--include/GlobalLib.hpp4
-rw-r--r--include/Package.hpp8
-rw-r--r--include/PkgConfig.hpp2
-rw-r--r--include/Version.hpp68
-rw-r--r--include/VersionParser.hpp51
8 files changed, 135 insertions, 10 deletions
diff --git a/include/Conf.hpp b/include/Conf.hpp
index a60bc36..ee61a21 100644
--- a/include/Conf.hpp
+++ b/include/Conf.hpp
@@ -8,6 +8,7 @@
#include "Dependency.hpp"
#include "Package.hpp"
#include "Platform.hpp"
+#include "Version.hpp"
#include <vector>
#include <unordered_map>
#include <cassert>
@@ -402,7 +403,8 @@ namespace sibs
bool zigTestAllFiles;
bool packaging;
bool bundling;
- std::string version;
+ std::string versionStr;
+ PackageVersion version;
Platform platform;
protected:
virtual void processObject(StringView name) override;
diff --git a/include/Dependency.hpp b/include/Dependency.hpp
index 7c8bbf1..0381625 100644
--- a/include/Dependency.hpp
+++ b/include/Dependency.hpp
@@ -3,6 +3,7 @@
#include <string>
#include <cassert>
+#include "Version.hpp";
namespace sibs
{
@@ -45,7 +46,7 @@ namespace sibs
}
std::string name;
- std::string version;
+ PackageVersionRange version;
};
class GitDependency : public Dependency
diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp
index 3e2e302..0487227 100644
--- a/include/FileUtil.hpp
+++ b/include/FileUtil.hpp
@@ -36,7 +36,8 @@ namespace sibs
void replaceChar(FileString &input, wchar_t charToReplace, wchar_t charToReplaceWith);
#endif
- using FileWalkCallbackFunc = std::function<void(tinydir_file*)>;
+ // Return true if you want to continue iterating the remaining files, return false if you want to stop
+ using FileWalkCallbackFunc = std::function<bool(tinydir_file*)>;
enum class FileType
{
@@ -48,7 +49,7 @@ namespace sibs
FileType getFileType(const _tinydir_char_t *path);
void walkDir(const _tinydir_char_t *directory, FileWalkCallbackFunc callbackFunc);
void walkDirFiles(const _tinydir_char_t *directory, FileWalkCallbackFunc callbackFunc);
- void walkDirFilesRecursive(const _tinydir_char_t *directory, FileWalkCallbackFunc callbackFunc);
+ bool walkDirFilesRecursive(const _tinydir_char_t *directory, FileWalkCallbackFunc callbackFunc);
Result<StringView> getFileContent(const _tinydir_char_t *filepath);
Result<bool> fileWrite(const _tinydir_char_t *filepath, StringView data);
Result<bool> fileOverwrite(const _tinydir_char_t *filepath, StringView data);
diff --git a/include/GlobalLib.hpp b/include/GlobalLib.hpp
index 8647a65..6a6c72a 100644
--- a/include/GlobalLib.hpp
+++ b/include/GlobalLib.hpp
@@ -21,9 +21,9 @@ namespace sibs
static Result<bool> getLibs(const std::vector<PackageListDependency*> &libs, const SibsConfig &parentConfig, const FileString &globalLibRootDir, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
static Result<bool> validatePackageExists(const FileString &globalLibRootDir, const std::string &name);
- static Result<bool> getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, const std::string &name, const std::string &version, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
+ static Result<bool> getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, const std::string &name, const PackageVersionRange &versionRange, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
static Result<bool> getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, GitDependency *gitDependency, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
- static Result<bool> downloadDependency(PackageListDependency *dependency);
+ static Result<bool> downloadDependency(PackageListDependency *dependency, Platform platform);
static Result<bool> downloadDependency(GitDependency *dependency);
private:
static Result<bool> getLibsLinkerFlagsCommon(const SibsConfig &parentConfig, const FileString &packageDir, const std::string &dependencyName, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback);
diff --git a/include/Package.hpp b/include/Package.hpp
index dbae5f2..72652be 100644
--- a/include/Package.hpp
+++ b/include/Package.hpp
@@ -4,6 +4,7 @@
#include "../external/rapidjson/document.h"
#include "Platform.hpp"
#include "Result.hpp"
+#include "Version.hpp"
#include <string>
#include <vector>
@@ -30,7 +31,7 @@ namespace sibs
struct PackageMetadata
{
std::string description;
- std::string version;
+ PackageVersion version;
std::vector<std::string> platforms;
std::vector<std::string> urls;
};
@@ -45,11 +46,10 @@ namespace sibs
static Result<rapidjson::Document*> getPackageList(const char *url);
/*
- * Return the first url in list.
+ * Return the package data for the package we can use
* TODO: If we fail to fetch package from first url, try other other ones in the list (or if the first url is too slow / takes too long to respond).
- * TODO: Add version matching with wildcard etc. If we specify "1.2.*", then it should get the latest version that matches; etc...
*/
- static Result<std::string> getPackageUrl(const char *packageName, const char *packageVersion, Platform platform);
+ static Result<PackageMetadata> getPackage(const char *packageName, const PackageVersionRange &versionRange, Platform platform);
};
}
diff --git a/include/PkgConfig.hpp b/include/PkgConfig.hpp
index 9181a2f..24aeb78 100644
--- a/include/PkgConfig.hpp
+++ b/include/PkgConfig.hpp
@@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include "FileUtil.hpp"
+#include "Version.hpp"
namespace sibs
{
@@ -24,6 +25,7 @@ namespace sibs
static Result<bool> validatePkgConfigPackageVersionExists(PackageListDependency *dependency);
static Result<bool> validatePackageExists(const std::string &name);
static Result<bool> validatePackageVersionAtLeast(const std::string &name, const std::string &version);
+ static Result<PackageVersion> getPackageVersion(const std::string &name);
static Result<std::string> getDynamicLibsLinkerFlags(const std::vector<PackageListDependency*> &libs);
static Result<std::string> getDynamicLibsCflags(const std::vector<PackageListDependency*> &libs);
static Result<PkgConfigFlags> getDynamicLibsFlags(const std::vector<PackageListDependency*> &libs);
diff --git a/include/Version.hpp b/include/Version.hpp
new file mode 100644
index 0000000..915f622
--- /dev/null
+++ b/include/Version.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include <string>
+
+namespace sibs
+{
+ enum class VersionOperation
+ {
+ LESS,
+ LESS_EQUAL,
+ EQUAL,
+ GREATER,
+ GREATER_EQUAL
+ };
+
+ const char* asString(VersionOperation operation);
+
+ struct PackageVersion
+ {
+ int major;
+ int minor;
+ int patch;
+
+ bool operator < (const PackageVersion &other) const
+ {
+ if(major < other.major) return true;
+ if(major == other.major && minor < other.minor) return true;
+ if(major == other.major && minor == other.minor && patch < other.patch) return true;
+ return false;
+ }
+
+ bool operator == (const PackageVersion &other) const
+ {
+ return (major == other.major) && (minor == other.minor) && (patch == other.patch);
+ }
+
+ bool operator <= (const PackageVersion &other) const
+ {
+ return *this < other || *this == other;
+ }
+
+ std::string toString() const;
+ };
+ static_assert(sizeof(PackageVersion) == sizeof(int) * 3, "Expected PackageVersion to be the same size as 3 ints");
+
+ struct PackageVersionRange
+ {
+ PackageVersionRange()
+ {
+ start = { 0, 0, 0 };
+ end = { 0, 0, 0 };
+ startDefined = false;
+ endDefined = false;
+ startOperation = VersionOperation::LESS;
+ endOperation = VersionOperation::LESS;
+ }
+
+ bool isInRange(const PackageVersion &version) const;
+ std::string toString() const;
+
+ PackageVersion start;
+ PackageVersion end;
+ bool startDefined;
+ bool endDefined;
+ VersionOperation startOperation;
+ VersionOperation endOperation;
+ };
+} \ No newline at end of file
diff --git a/include/VersionParser.hpp b/include/VersionParser.hpp
new file mode 100644
index 0000000..eba4d33
--- /dev/null
+++ b/include/VersionParser.hpp
@@ -0,0 +1,51 @@
+#pragma once
+
+#include "types.hpp"
+#include "Version.hpp"
+#include "Result.hpp"
+#include "StringView.hpp"
+#include <string>
+
+namespace sibs
+{
+ Result<PackageVersion> parsePackageVersion(const StringView &versionStr, int *size);
+
+ enum class VersionToken
+ {
+ NONE,
+ END_OF_FILE,
+ INVALID,
+ OPERATION,
+ AND,
+ VERSION_NUMBER
+ };
+
+ struct VersionTokenizer
+ {
+ VersionTokenizer();
+ VersionTokenizer(const char *start, const usize size);
+ VersionTokenizer(const VersionTokenizer &other);
+ VersionToken next();
+
+
+ const char *start;
+ const char *code;
+ usize size;
+ usize index;
+ PackageVersion version;
+ VersionOperation operation;
+ StringView identifier;
+ std::string errMsg;
+ };
+
+ struct VersionParser
+ {
+ Result<PackageVersionRange> parse(const char *code, const usize size);
+
+ VersionTokenizer tokenizer;
+ PackageVersionRange versionRange;
+ private:
+ VersionToken parseStart();
+ VersionToken parseEnd();
+ };
+} \ No newline at end of file