aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/ninja/Ninja.cpp104
-rw-r--r--backend/ninja/Ninja.hpp2
-rw-r--r--include/PkgConfig.hpp3
-rw-r--r--src/GlobalLib.cpp6
-rw-r--r--src/PkgConfig.cpp6
5 files changed, 67 insertions, 54 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 87dd873..ede150c 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -81,70 +81,79 @@ namespace backend
// TODO: First check if pkg-config is installed. If it's not, only check dependencies that exists in the dependencies sub directory.
// If pkg-config is installed and dependency is not installed, check in dependencies sub directory.
- Result<string> Ninja::getLinkerFlags(const vector<Dependency> &dependencies, LinkerFlagCallbackFunc linkerFlagCallbackFunc) const
+ Result<bool> Ninja::getLinkerFlags(const vector<Dependency> &dependencies, LinkerFlagCallbackFunc linkerFlagCallbackFunc) const
{
- if(dependencies.empty()) return Result<string>::Ok("");
+ if(dependencies.empty()) return Result<bool>::Ok(true);
string globalLibDir = getHomeDir();
globalLibDir += "/.sibs/lib";
Result<bool> createGlobalLibDirResult = createDirectoryRecursive(globalLibDir.c_str());
if(createGlobalLibDirResult.isErr())
- return Result<string>::Err(createGlobalLibDirResult);
+ return createGlobalLibDirResult;
- string globalLibLinkerFlags;
- vector<string> pkgConfigDependencies;
- for(const sibs::Dependency &dependency : dependencies)
+ vector<Dependency> pkgConfigDependencies;
+ vector<Dependency> globalLibDependencies;
+ for(const Dependency &dependency : dependencies)
{
Result<bool> pkgConfigDependencyValidation = validatePkgConfigPackageVersionExists(dependency);
if(pkgConfigDependencyValidation.isOk())
{
- pkgConfigDependencies.push_back(dependency.name);
+ pkgConfigDependencies.push_back(dependency);
}
else
{
- printf("%s, trying global lib\n", pkgConfigDependencyValidation.getErrMsg().c_str());
- Result<string> globalLibLinkerFlagsResult = GlobalLib::getStaticLibsLinkerFlags(globalLibDir, dependency.name, dependency.version, linkerFlagCallbackFunc);
- 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.
-
- // 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(dependency);
- if(downloadDependencyResult.isErr())
- return Result<string>::Err(downloadDependencyResult.getErrMsg());
-
- globalLibLinkerFlagsResult = GlobalLib::getStaticLibsLinkerFlags(globalLibDir, dependency.name, dependency.version, linkerFlagCallbackFunc);
- if(globalLibLinkerFlagsResult.isErr())
- return globalLibLinkerFlagsResult;
- }
- else
- {
- return globalLibLinkerFlagsResult;
- }
- }
-
- globalLibLinkerFlags += " '";
- globalLibLinkerFlags += globalLibLinkerFlagsResult.unwrap();
- globalLibLinkerFlags += "'";
+ globalLibDependencies.push_back(dependency);
}
}
Result<string> pkgConfigLinkerFlagsResult = PkgConfig::getDynamicLibsLinkerFlags(pkgConfigDependencies);
if(pkgConfigLinkerFlagsResult.isErr())
- return pkgConfigLinkerFlagsResult;
+ {
+ printf("%s, using global lib...\n", pkgConfigLinkerFlagsResult.getErrMsg().c_str());
+ globalLibDependencies.reserve(globalLibDependencies.size() + pkgConfigDependencies.size());
+ for(const Dependency &pkgConfigDependency : pkgConfigDependencies)
+ {
+ globalLibDependencies.push_back(pkgConfigDependency);
+ }
+ pkgConfigDependencies.clear();
+ }
+ else
+ {
+ if(!pkgConfigLinkerFlagsResult.unwrap().empty())
+ linkerFlagCallbackFunc(pkgConfigLinkerFlagsResult.unwrap());
+ }
- if(!pkgConfigLinkerFlagsResult.unwrap().empty())
- linkerFlagCallbackFunc(pkgConfigLinkerFlagsResult.unwrap());
+ for(const Dependency &globalLibDependency : globalLibDependencies)
+ {
+ printf("Dependency %s is missing from pkg-config, trying global lib\n", globalLibDependency.name.c_str());
+ Result<string> globalLibLinkerFlagsResult = GlobalLib::getStaticLibsLinkerFlags(globalLibDir, globalLibDependency.name, globalLibDependency.version, linkerFlagCallbackFunc);
+ 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.
+
+ // 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::getStaticLibsLinkerFlags(globalLibDir, globalLibDependency.name, globalLibDependency.version, linkerFlagCallbackFunc);
+ if(globalLibLinkerFlagsResult.isErr())
+ return Result<bool>::Err(globalLibLinkerFlagsResult);
+ }
+ else
+ {
+ return Result<bool>::Err(globalLibLinkerFlagsResult);
+ }
+ }
+ }
- string allLinkerFlags = pkgConfigLinkerFlagsResult.unwrap();
- allLinkerFlags += globalLibLinkerFlags;
- return Result<string>::Ok(allLinkerFlags);
+ return Result<bool>::Ok(true);
}
Result<bool> Ninja::createBuildFile(const std::string &packageName, const vector<Dependency> &dependencies, const char *savePath, LinkerFlagCallbackFunc linkerFlagCallbackFunc)
@@ -223,11 +232,10 @@ namespace backend
case LibraryType::EXECUTABLE:
{
string allLinkerFlags;
- Result<string> linkerFlags = getLinkerFlags(dependencies, [&allLinkerFlags](const string &linkerFlag)
+ Result<bool> linkerFlags = getLinkerFlags(dependencies, [&allLinkerFlags](const string &linkerFlag)
{
- allLinkerFlags += " '";
+ allLinkerFlags += " ";
allLinkerFlags += linkerFlag;
- allLinkerFlags += "'";
});
if(linkerFlags.isErr())
return Result<bool>::Err(linkerFlags.getErrMsg());
@@ -245,9 +253,9 @@ namespace backend
case LibraryType::STATIC:
{
string allLinkerFlags;
- Result<string> linkerFlags = getLinkerFlags(dependencies, linkerFlagCallbackFunc);
+ Result<bool> linkerFlags = getLinkerFlags(dependencies, linkerFlagCallbackFunc);
if(linkerFlags.isErr())
- return Result<bool>::Err(linkerFlags.getErrMsg());
+ return linkerFlags;
result += "build ";
result += packageName;
diff --git a/backend/ninja/Ninja.hpp b/backend/ninja/Ninja.hpp
index 3ccee1e..b82139c 100644
--- a/backend/ninja/Ninja.hpp
+++ b/backend/ninja/Ninja.hpp
@@ -29,7 +29,7 @@ namespace backend
sibs::Result<bool> build(const char *buildFilePath);
private:
bool containsSourceFile(const char *filepath) const;
- sibs::Result<std::string> getLinkerFlags(const std::vector<sibs::Dependency> &dependencies, sibs::LinkerFlagCallbackFunc linkerFlagCallbackFunc) const;
+ sibs::Result<bool> getLinkerFlags(const std::vector<sibs::Dependency> &dependencies, sibs::LinkerFlagCallbackFunc linkerFlagCallbackFunc) const;
private:
std::vector<std::string> sourceFiles;
LibraryType libraryType;
diff --git a/include/PkgConfig.hpp b/include/PkgConfig.hpp
index 4bafa18..2af4ac9 100644
--- a/include/PkgConfig.hpp
+++ b/include/PkgConfig.hpp
@@ -2,6 +2,7 @@
#define SIBS_PKGCONFIG_HPP
#include "Result.hpp"
+#include "Dependency.hpp"
#include <string>
#include <vector>
@@ -12,7 +13,7 @@ namespace sibs
public:
static Result<bool> validatePackageExists(const std::string &name);
static Result<bool> validatePackageVersionAtLeast(const std::string &name, const std::string &version);
- static Result<std::string> getDynamicLibsLinkerFlags(const std::vector<std::string> &libs);
+ static Result<std::string> getDynamicLibsLinkerFlags(const std::vector<Dependency> &libs);
};
}
diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp
index 203cd0f..617f993 100644
--- a/src/GlobalLib.cpp
+++ b/src/GlobalLib.cpp
@@ -145,7 +145,11 @@ namespace sibs
staticLibPath += "/lib";
staticLibPath += name;
staticLibPath += ".a";
- linkerFlagCallbackFunc(staticLibPath);
+
+ string staticLibPathCmd = "'";
+ staticLibPathCmd += staticLibPath;
+ staticLibPathCmd += "'";
+ linkerFlagCallbackFunc(staticLibPathCmd);
// TODO: Use different directories depending on the project type, but .o build files should be in the same directory
// no matter what project type, since they are used for executables, static/dynamic libraries
diff --git a/src/PkgConfig.cpp b/src/PkgConfig.cpp
index 3307ff1..5f85549 100644
--- a/src/PkgConfig.cpp
+++ b/src/PkgConfig.cpp
@@ -89,15 +89,15 @@ namespace sibs
return Result<bool>::Ok(true);
}
- Result<string> PkgConfig::getDynamicLibsLinkerFlags(const vector<string> &libs)
+ Result<string> PkgConfig::getDynamicLibsLinkerFlags(const vector<Dependency> &libs)
{
if(libs.empty()) return Result<string>::Ok("");
string args;
- for(const string &lib : libs)
+ for(const Dependency &lib : libs)
{
args += " '";
- args += lib;
+ args += lib.name;
args += "'";
}