From 1d3e221a7a20bfd03517e3ae1e35e4a309a69b6a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 10 Dec 2017 01:10:48 +0100 Subject: Add support for dependencies in global lib dir Global lib dir is located at ~/.sibs/lib TODO: If global lib dir doesn't exist, download it from github/server --- include/Conf.hpp | 31 +++++++++++++++++++++++++++++++ include/Exec.hpp | 18 ++++++++++++++++++ include/FileUtil.hpp | 3 +++ include/GlobalLib.hpp | 16 ++++++++++++++++ include/PkgConfig.hpp | 19 +++++++++++++++++++ include/Result.hpp | 2 +- include/env.hpp | 12 ++++++++++++ 7 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 include/Exec.hpp create mode 100644 include/GlobalLib.hpp create mode 100644 include/PkgConfig.hpp (limited to 'include') diff --git a/include/Conf.hpp b/include/Conf.hpp index 8b98189..3634f4c 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -4,6 +4,7 @@ #include "Result.hpp" #include "StringView.hpp" #include "utils.hpp" +#include "Dependency.hpp" #include #include #include @@ -79,6 +80,36 @@ namespace sibs public: static Result readFromFile(const char *filepath, const ConfigCallback &callback); }; + + class SibsConfig : public ConfigCallback + { + public: + SibsConfig() : finishedProcessing(false) {} + + const std::string& getPackageName() const + { + assert(finishedProcessing); + return packageName; + } + + const std::vector& getDependencies() const + { + return dependencies; + } + protected: + void processObject(StringView name) override; + void processField(StringView name, const ConfigValue &value) override; + + void finished() override + { + finishedProcessing = true; + } + private: + StringView currentObject; + std::string packageName; + std::vector dependencies; + bool finishedProcessing; + }; } #endif //SIBS_CONF_HPP diff --git a/include/Exec.hpp b/include/Exec.hpp new file mode 100644 index 0000000..42b6905 --- /dev/null +++ b/include/Exec.hpp @@ -0,0 +1,18 @@ +#ifndef SIBS_EXEC_HPP +#define SIBS_EXEC_HPP + +#include "Result.hpp" +#include + +namespace sibs +{ + struct ExecResult + { + std::string execStdout; + int exitCode; + }; + + Result exec(const char *cmd, bool print = false); +} + +#endif //SIBS_EXEC_HPP diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp index 4083cb1..5a0bbc3 100644 --- a/include/FileUtil.hpp +++ b/include/FileUtil.hpp @@ -18,9 +18,12 @@ namespace sibs }; FileType getFileType(const char *path); + void walkDir(const char *directory, FileWalkCallbackFunc callbackFunc); void walkDirFiles(const char *directory, FileWalkCallbackFunc callbackFunc); + void walkDirFilesRecursive(const char *directory, FileWalkCallbackFunc callbackFunc); Result getFileContent(const char *filepath); bool fileOverwrite(const char *filepath, StringView data); + const char* getHomeDir(); } #endif //SIBS_FILEUTIL_HPP diff --git a/include/GlobalLib.hpp b/include/GlobalLib.hpp new file mode 100644 index 0000000..e5a9374 --- /dev/null +++ b/include/GlobalLib.hpp @@ -0,0 +1,16 @@ +#ifndef SIBS_GLOBALLIB_HPP +#define SIBS_GLOBALLIB_HPP + +#include "Result.hpp" + +namespace sibs +{ + class GlobalLib + { + public: + static Result validatePackageExists(const std::string &globalLibRootDir, const std::string &name); + static Result getDynamicLibsLinkerFlags(const std::string &globalLibRootDir, const std::string &name, const std::string &version); + }; +} + +#endif //SIBS_GLOBALLIB_HPP diff --git a/include/PkgConfig.hpp b/include/PkgConfig.hpp new file mode 100644 index 0000000..4bafa18 --- /dev/null +++ b/include/PkgConfig.hpp @@ -0,0 +1,19 @@ +#ifndef SIBS_PKGCONFIG_HPP +#define SIBS_PKGCONFIG_HPP + +#include "Result.hpp" +#include +#include + +namespace sibs +{ + class PkgConfig + { + public: + static Result validatePackageExists(const std::string &name); + static Result validatePackageVersionAtLeast(const std::string &name, const std::string &version); + static Result getDynamicLibsLinkerFlags(const std::vector &libs); + }; +} + +#endif //SIBS_PKGCONFIG_HPP diff --git a/include/Result.hpp b/include/Result.hpp index 3ee60e5..f755b15 100644 --- a/include/Result.hpp +++ b/include/Result.hpp @@ -28,7 +28,7 @@ namespace sibs bool isOk() const { return !error; } bool isErr() const { return error; } - const T& unwrap() const + T& unwrap() { assert(isOk()); return value; diff --git a/include/env.hpp b/include/env.hpp index 5d0a163..325db6e 100644 --- a/include/env.hpp +++ b/include/env.hpp @@ -1,12 +1,20 @@ #ifndef SIBS_ENV_HPP #define SIBS_ENV_HPP +#define OS_FAMILY_WINDOWS 0 +#define OS_FAMILY_POSIX 1 + #if defined(_WIN32) || defined(_WIN64) #if defined(_WIN64) #define CISB_ENV_64BIT #else #define CISB_ENV_32BIT #endif + #define OS_FAMILY OS_FAMILY_WINDOWS +#endif + +#if defined(__linux__) || defined(__unix__) || defined(__APPLE__) || defined(_POSIX_VERSION) + #define OS_FAMILY OS_FAMILY_POSIX #endif #if defined(__GNUC__) @@ -21,4 +29,8 @@ #error "System is not detected as either 32-bit or 64-bit" #endif +#if !defined(OS_FAMILY) + #error "System not support. Only Windows and Posix systems support" +#endif + #endif // SIBS_ENV_HPP -- cgit v1.2.3