From a548abb5a6a83c9318e9db3cf71170a7610e2758 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 4 Jan 2018 01:01:35 +0100 Subject: Use packages list to find packages --- src/GlobalLib.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'src/GlobalLib.cpp') 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 GlobalLib::getLibs(const std::vector &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 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 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::Err(globalLibLinkerFlagsResult); + } + else + { + return Result::Err(globalLibLinkerFlagsResult); + } + } + } + return Result::Ok(true); + } Result 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 GlobalLib::downloadDependency(const Dependency &dependency) { - string url = "https://github.com/DEC05EBA/"; - url += dependency.name; - url += "/archive/"; - url += dependency.version; - url += ".tar.gz"; + Result packageUrlResult = Package::getPackageUrl(dependency.name.c_str(), dependency.version.c_str()); + if(!packageUrlResult) + return Result::Err(packageUrlResult); + + const string &url = packageUrlResult.unwrap(); Result libPathResult = getHomeDir(); if (!libPathResult) -- cgit v1.2.3