diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-01-04 01:01:35 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-01-04 01:01:42 +0100 |
commit | a548abb5a6a83c9318e9db3cf71170a7610e2758 (patch) | |
tree | e8556530f15102054f6175dc7a3438aaaaf8d77e /src/GlobalLib.cpp | |
parent | e862bb76a2f4c9c293fe2638c7fb034de2af709c (diff) |
Use packages list to find packages
Diffstat (limited to 'src/GlobalLib.cpp')
-rw-r--r-- | src/GlobalLib.cpp | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index d3131a1..0256685 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -64,6 +64,43 @@ namespace sibs { return _tinydir_strncmp(path, subPathOf.c_str(), subPathOf.size()) == 0; } + + Result<bool> GlobalLib::getLibs(const std::vector<Dependency> &libs, const SibsConfig &parentConfig, const FileString &globalLibRootDir, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback) + { + for(const Dependency &globalLibDependency : libs) + { + printf("Dependency %s is missing from pkg-config, trying global lib\n", globalLibDependency.name.c_str()); + Result<bool> globalLibLinkerFlagsResult = GlobalLib::getLibsLinkerFlags(parentConfig, globalLibRootDir, globalLibDependency.name, globalLibDependency.version, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback); + if(globalLibLinkerFlagsResult.isErr()) + { + if(globalLibLinkerFlagsResult.getErrorCode() == GlobalLib::DependencyError::DEPENDENCY_NOT_FOUND || globalLibLinkerFlagsResult.getErrorCode() == GlobalLib::DependencyError::DEPENDENCY_VERSION_NO_MATCH) + { + printf("Dependency not found in global lib, trying to download from github\n"); + // TODO: Download several dependencies at the same time by adding them to a list + // and then iterate them and download them all using several threads. + // All dependecies should be downloaded at the same time, this includes dependencies of dependencies. + // If a dependency is missing, fail build BEFORE downloading dependencies and before compiling anything. + // You do not want to possibly wait several minutes only for build to fail when there is no compilation error. + + // TODO: If return error is invalid url, then the message should be converted to + // invalid package name/version. A check should be done if it is the name or version + // that is invalid. + Result<bool> downloadDependencyResult = GlobalLib::downloadDependency(globalLibDependency); + if(downloadDependencyResult.isErr()) + return downloadDependencyResult; + + globalLibLinkerFlagsResult = GlobalLib::getLibsLinkerFlags(parentConfig, globalLibRootDir, globalLibDependency.name, globalLibDependency.version, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback); + if(globalLibLinkerFlagsResult.isErr()) + return Result<bool>::Err(globalLibLinkerFlagsResult); + } + else + { + return Result<bool>::Err(globalLibLinkerFlagsResult); + } + } + } + return Result<bool>::Ok(true); + } Result<bool> GlobalLib::getLibsLinkerFlags(const SibsConfig &parentConfig, const FileString &globalLibRootDir, const std::string &name, const std::string &version, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallbackFunc, GlobalIncludeDirCallbackFunc globalIncludeDirCallback) { @@ -281,11 +318,11 @@ namespace sibs Result<bool> GlobalLib::downloadDependency(const Dependency &dependency) { - string url = "https://github.com/DEC05EBA/"; - url += dependency.name; - url += "/archive/"; - url += dependency.version; - url += ".tar.gz"; + Result<string> packageUrlResult = Package::getPackageUrl(dependency.name.c_str(), dependency.version.c_str()); + if(!packageUrlResult) + return Result<bool>::Err(packageUrlResult); + + const string &url = packageUrlResult.unwrap(); Result<FileString> libPathResult = getHomeDir(); if (!libPathResult) |