From 61d9e8699687342c2e32c32c8d4eb71760d5d290 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 26 Jun 2021 17:33:24 +0200 Subject: Use fork/exec instead of popen. Add Path class --- include/Conf.hpp | 36 +++++++++++++++--------------------- include/Exec.hpp | 4 ++-- include/FileUtil.hpp | 24 ++++++++++++++++++++++++ include/GlobalLib.hpp | 4 ++-- include/PkgConfig.hpp | 9 ++++----- 5 files changed, 47 insertions(+), 30 deletions(-) (limited to 'include') diff --git a/include/Conf.hpp b/include/Conf.hpp index 8098206..cfe0133 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -237,10 +237,10 @@ namespace sibs switch(optimizationLevel) { case OPT_LEV_DEBUG: - cmakeArgsGlobal = TINYDIR_STRING("-G Ninja \"-DCMAKE_BUILD_TYPE=Debug\""); + cmakeArgsGlobal = { TINYDIR_STRING("-G"), TINYDIR_STRING("Ninja"), TINYDIR_STRING("-DCMAKE_BUILD_TYPE=Debug") }; break; case OPT_LEV_RELEASE: - cmakeArgsGlobal = TINYDIR_STRING("-G Ninja \"-DCMAKE_BUILD_TYPE=Release\""); + cmakeArgsGlobal = { TINYDIR_STRING("-G"), TINYDIR_STRING("Ninja"), TINYDIR_STRING("-DCMAKE_BUILD_TYPE=Release") }; break; } } @@ -274,7 +274,7 @@ namespace sibs this->testPath = testPath; } - virtual const std::vector& getPackageListDependencies() const + virtual const std::vector& getPackageListDependencies() const { return packageListDependencies; } @@ -340,30 +340,24 @@ namespace sibs } // Get cmake args for all builds. This is args under [cmake] only - const FileString& getCmakeArgs() const + const std::vector& getCmakeArgs() const { return cmakeArgsGlobal; } // Get cmake args for static build. This is a combination of args under [cmake] and under [cmake.static] - FileString getCmakeArgsStatic() const + std::vector getCmakeArgsStatic() const { - FileString result; - result.reserve(cmakeArgsGlobal.size() + 1 + cmakeArgsStatic.size()); - result += cmakeArgsGlobal; - result += TINYDIR_STRING(" "); - result += cmakeArgsStatic; + std::vector result = cmakeArgsGlobal; + result.insert(result.end(), cmakeArgsStatic.begin(), cmakeArgsStatic.end()); return result; } // Get cmake args for dynamic build. This is a combination of args under [cmake] and under [cmake.dynamic] - FileString getCmakeArgsDynamic() const + std::vector getCmakeArgsDynamic() const { - FileString result; - result.reserve(cmakeArgsGlobal.size() + 1 + cmakeArgsDynamic.size()); - result += cmakeArgsGlobal; - result += TINYDIR_STRING(" "); - result += cmakeArgsDynamic; + std::vector result = cmakeArgsGlobal; + result.insert(result.end(), cmakeArgsDynamic.begin(), cmakeArgsDynamic.end()); return result; } @@ -451,7 +445,7 @@ namespace sibs std::string parsePlatformConfigStatic(const StringView &fieldName, const ConfigValue &fieldValue); void parsePlatformConfigStaticDebug(const StringView &fieldName, const ConfigValue &fieldValue); void parsePlatformConfigStaticRelease(const StringView &fieldName, const ConfigValue &fieldValue); - void parseCmake(const StringView &fieldName, const ConfigValue &fieldValue, FileString &cmakeDir, FileString &cmakeArgs); + void parseCmake(const StringView &fieldName, const ConfigValue &fieldValue, FileString &cmakeDir, std::vector &cmakeArgs); void validatePackageName() const; protected: StringView currentObject; @@ -460,7 +454,7 @@ namespace sibs std::string packageName; FileString testPath; PackageType packageType; - std::vector packageListDependencies; + std::vector packageListDependencies; std::vector platforms; std::unordered_map defines; OptimizationLevel optimizationLevel; @@ -469,9 +463,9 @@ namespace sibs FileString cmakeDirGlobal; FileString cmakeDirStatic; FileString cmakeDirDynamic; - FileString cmakeArgsGlobal; - FileString cmakeArgsStatic; - FileString cmakeArgsDynamic; + std::vector cmakeArgsGlobal; + std::vector cmakeArgsStatic; + std::vector cmakeArgsDynamic; CVersion cVersion; CPPVersion cppVersion; bool useCmake; diff --git a/include/Exec.hpp b/include/Exec.hpp index 93ce307..538f0dc 100644 --- a/include/Exec.hpp +++ b/include/Exec.hpp @@ -4,6 +4,7 @@ #include "Result.hpp" #include "../include/FileUtil.hpp" #include +#include namespace sibs { @@ -13,8 +14,7 @@ namespace sibs int exitCode; }; - Result exec(const _tinydir_char_t *cmd, bool print = false); - Result exec(const FileString &cmd, bool print = false); + Result exec(const std::vector &args, bool print_instead_of_pipe = false); } #endif //SIBS_EXEC_HPP diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp index f2a1799..5bd4d33 100644 --- a/include/FileUtil.hpp +++ b/include/FileUtil.hpp @@ -38,6 +38,30 @@ namespace sibs void replaceChar(FileString &input, wchar_t charToReplace, wchar_t charToReplaceWith); #endif + class Path { + public: + Path(const FileString &str) : data(str) {} + + Path& join(const _tinydir_char_t *str) { + data += TINYDIR_STRING("/"); + data += str; + return *this; + } + + Path& join(const Path &other) { + data += TINYDIR_STRING("/"); + data += other.data; + return *this; + } + + Path& append(const FileString &str) { + data += str; + return *this; + } + + FileString data; + }; + // Return true if you want to continue iterating the remaining files, return false if you want to stop using FileWalkCallbackFunc = std::function; diff --git a/include/GlobalLib.hpp b/include/GlobalLib.hpp index 92739df..953df7e 100644 --- a/include/GlobalLib.hpp +++ b/include/GlobalLib.hpp @@ -18,10 +18,10 @@ namespace sibs DEPENDENCY_VERSION_NO_MATCH = 20 }; - static Result getLibs(const std::vector &libs, const SibsConfig &parentConfig, const FileString &globalLibRootDir, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback); + static Result getLibs(const std::vector &libs, const SibsConfig &parentConfig, const FileString &globalLibRootDir, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback); static Result validatePackageExists(const FileString &globalLibRootDir, const std::string &name); static Result getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, const std::string &name, const PackageVersionRange &versionRange, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback); - static Result downloadDependency(PackageListDependency *dependency, Platform platform); + static Result downloadDependency(const PackageListDependency &dependency, Platform platform); private: static Result getLibsLinkerFlagsCommon(const SibsConfig &parentConfig, const FileString &packageDir, const std::string &dependencyName, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback); }; diff --git a/include/PkgConfig.hpp b/include/PkgConfig.hpp index 24aeb78..23c1b12 100644 --- a/include/PkgConfig.hpp +++ b/include/PkgConfig.hpp @@ -22,13 +22,12 @@ namespace sibs { public: static void setPkgConfigPath(const FileString &path); - static Result validatePkgConfigPackageVersionExists(PackageListDependency *dependency); + static Result validatePkgConfigPackageVersionExists(const PackageListDependency &dependency); static Result validatePackageExists(const std::string &name); - static Result validatePackageVersionAtLeast(const std::string &name, const std::string &version); static Result getPackageVersion(const std::string &name); - static Result getDynamicLibsLinkerFlags(const std::vector &libs); - static Result getDynamicLibsCflags(const std::vector &libs); - static Result getDynamicLibsFlags(const std::vector &libs); + static Result getDynamicLibsLinkerFlags(const std::vector &libs); + static Result getDynamicLibsCflags(const std::vector &libs); + static Result getDynamicLibsFlags(const std::vector &libs); }; } -- cgit v1.2.3