From f3b7b7d34b3bf2b1be18914577c96b66dead379a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 12 Dec 2017 17:33:03 +0100 Subject: Download and extract missing dependencies from github Using libcurl and libarchive --- include/Archive.hpp | 15 +++++++++++++++ include/GlobalLib.hpp | 8 ++++++++ include/Result.hpp | 26 ++++++++++++++++++++------ include/curl.hpp | 15 +++++++++++++++ include/env.hpp | 4 ++++ include/utils.hpp | 1 - 6 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 include/Archive.hpp create mode 100644 include/curl.hpp (limited to 'include') diff --git a/include/Archive.hpp b/include/Archive.hpp new file mode 100644 index 0000000..6d6a55d --- /dev/null +++ b/include/Archive.hpp @@ -0,0 +1,15 @@ +#ifndef SIBS_ZLIB_HPP +#define SIBS_ZLIB_HPP + +#include "Result.hpp" + +namespace sibs +{ + class Archive + { + public: + static Result extract(const char *source, const char *destination); + }; +} + +#endif //SIBS_ZLIB_HPP diff --git a/include/GlobalLib.hpp b/include/GlobalLib.hpp index d5e21d1..ca542f9 100644 --- a/include/GlobalLib.hpp +++ b/include/GlobalLib.hpp @@ -3,14 +3,22 @@ #include "Result.hpp" #include "Linker.hpp" +#include "Dependency.hpp" namespace sibs { class GlobalLib { public: + enum DependencyError + { + DEPENDENCY_NOT_FOUND = 10, + DEPENDENCY_VERSION_NO_MATCH = 20 + }; + static Result validatePackageExists(const std::string &globalLibRootDir, const std::string &name); static Result getStaticLibsLinkerFlags(const std::string &globalLibRootDir, const std::string &name, const std::string &version, LinkerFlagCallbackFunc linkerFlagCallbackFunc); + static Result downloadDependency(const Dependency &dependency); }; } diff --git a/include/Result.hpp b/include/Result.hpp index f755b15..eb0aa01 100644 --- a/include/Result.hpp +++ b/include/Result.hpp @@ -13,20 +13,29 @@ namespace sibs static Result Ok(const T &value) { Result result(value); - result.error = false; + result.errorCode = 0; return result; } - static Result Err(const std::string &errMsg) + template + static Result Err(const Result &other) + { + Result result; + result.errMsg = other.getErrMsg(); + result.errorCode = other.getErrorCode(); + return result; + } + + static Result Err(const std::string &errMsg, int errorCode = 1) { Result result; result.errMsg = errMsg; - result.error = true; + result.errorCode = errorCode; return result; } - bool isOk() const { return !error; } - bool isErr() const { return error; } + bool isOk() const { return !errorCode; } + bool isErr() const { return errorCode; } T& unwrap() { @@ -39,12 +48,17 @@ namespace sibs assert(isErr()); return errMsg; } + + int getErrorCode() const + { + return errorCode; + } private: Result(const T &_value = T()) : value(_value) {} private: T value; std::string errMsg; - bool error; + int errorCode; }; } diff --git a/include/curl.hpp b/include/curl.hpp new file mode 100644 index 0000000..49dfe12 --- /dev/null +++ b/include/curl.hpp @@ -0,0 +1,15 @@ +#ifndef SIBS_CURL_HPP +#define SIBS_CURL_HPP + +#include "Result.hpp" + +namespace sibs +{ + class curl + { + public: + static Result downloadFile(const char *url, const char *filepath); + }; +} + +#endif //SIBS_CURL_HPP diff --git a/include/env.hpp b/include/env.hpp index 325db6e..f5b1213 100644 --- a/include/env.hpp +++ b/include/env.hpp @@ -33,4 +33,8 @@ #error "System not support. Only Windows and Posix systems support" #endif +#if !defined(DEBUG) && !defined(NDEBUG) +#define DEBUG +#endif + #endif // SIBS_ENV_HPP diff --git a/include/utils.hpp b/include/utils.hpp index 9ad9d97..926749d 100755 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -4,7 +4,6 @@ // Disable copying for a class or struct #define DISABLE_COPY(ClassName) \ ClassName(ClassName&) = delete; \ - ClassName(ClassName&&) = delete; \ ClassName& operator = (ClassName&) = delete; #endif // SIBS_UTILS_HPP -- cgit v1.2.3