aboutsummaryrefslogtreecommitdiff
path: root/backend/ninja
diff options
context:
space:
mode:
Diffstat (limited to 'backend/ninja')
-rw-r--r--backend/ninja/Ninja.cpp45
-rw-r--r--backend/ninja/Ninja.hpp5
2 files changed, 32 insertions, 18 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 530dffe..0ca7c7a 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -206,6 +206,11 @@ namespace backend
{
}
+
+ void Ninja::addGlobalIncludeDirs(const string &globalIncludeDirs)
+ {
+ customGlobalIncludeDirs = globalIncludeDirs;
+ }
void Ninja::addSourceFile(const char *filepath)
{
@@ -272,9 +277,8 @@ namespace backend
// If pkg-config is installed and dependency is not installed, check in dependencies sub directory.
Result<bool> Ninja::getLinkerFlags(const SibsConfig &config, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback, CflagsCallbackFunc cflagsCallbackFunc) const
{
- const vector<Dependency> &dependencies = config.getDependencies();
- if(dependencies.empty()) return Result<bool>::Ok(true);
-
+ const vector<PackageListDependency*> &packageListDependencies = config.getPackageListDependencies();
+
Result<FileString> globalLibDirResult = getHomeDir();
if (!globalLibDirResult)
return Result<bool>::Err(globalLibDirResult);
@@ -284,10 +288,10 @@ namespace backend
if(createGlobalLibDirResult.isErr())
return createGlobalLibDirResult;
- vector<Dependency> globalLibDependencies;
+ vector<PackageListDependency*> globalLibDependencies;
#if OS_FAMILY == OS_FAMILY_POSIX
- vector<Dependency> pkgConfigDependencies;
- for(const Dependency &dependency : dependencies)
+ vector<PackageListDependency*> pkgConfigDependencies;
+ for(PackageListDependency *dependency : packageListDependencies)
{
Result<bool> pkgConfigDependencyValidation = PkgConfig::validatePkgConfigPackageVersionExists(dependency);
if(pkgConfigDependencyValidation.isOk())
@@ -305,7 +309,7 @@ namespace backend
{
printf("%s, using global lib...\n", pkgConfigFlagsResult.getErrMsg().c_str());
globalLibDependencies.reserve(globalLibDependencies.size() + pkgConfigDependencies.size());
- for (const Dependency &pkgConfigDependency : pkgConfigDependencies)
+ for (PackageListDependency *pkgConfigDependency : pkgConfigDependencies)
{
globalLibDependencies.push_back(pkgConfigDependency);
}
@@ -353,7 +357,7 @@ namespace backend
ninjaBuildFilePath += TINYDIR_STRING("/build.ninja");
string result;
- result.reserve(16384);
+ result.reserve(2048);
Result<FileString> globalIncDirResult = getHomeDir();
if (!globalIncDirResult)
@@ -384,10 +388,11 @@ namespace backend
parentGlobalIncludeDirCallback(globalIncludeDirFull);
}
- globalIncludeDirCallback = [&parentGlobalIncludeDirCallback, &globalIncludeDirCallback, &result, &config](const string &globalIncludeDir)
+ string dependencyExportIncludeDirs = customGlobalIncludeDirs;
+ globalIncludeDirCallback = [&parentGlobalIncludeDirCallback, &globalIncludeDirCallback, &dependencyExportIncludeDirs, &config](const string &globalIncludeDir)
{
- result += " ";
- result += getIncludeOptionFlag(config.getCompiler(), globalIncludeDir);
+ dependencyExportIncludeDirs += " ";
+ dependencyExportIncludeDirs += getIncludeOptionFlag(config.getCompiler(), globalIncludeDir);
if (parentGlobalIncludeDirCallback)
parentGlobalIncludeDirCallback(globalIncludeDir);
};
@@ -437,6 +442,7 @@ namespace backend
if (linkerFlags.isErr())
return Result<bool>::Err(linkerFlags.getErrMsg());
+ result += dependencyExportIncludeDirs;
result += "\n\n";
string defines;
@@ -780,7 +786,7 @@ namespace backend
result += ".a: " + buildJob + " ";
result += join(objectNames, " ");
result += "\n\n";
- projectGeneratedBinary += config.getPackageName() + ".a";
+ projectGeneratedBinary += "lib" + config.getPackageName() + ".a";
break;
}
case Compiler::MSVC:
@@ -850,7 +856,7 @@ namespace backend
return buildResult;
}
- Result<bool> buildTestResult = buildTests(projectGeneratedBinary, config, savePath);
+ Result<bool> buildTestResult = buildTests(projectGeneratedBinary, config, savePath, dependencyExportIncludeDirs);
if(!buildTestResult)
return buildTestResult;
@@ -872,7 +878,7 @@ namespace backend
return false;
}
- Result<bool> Ninja::buildTests(const std::string &projectGeneratedBinary, const SibsConfig &config, const _tinydir_char_t *savePath)
+ Result<bool> Ninja::buildTests(const std::string &projectGeneratedBinary, const SibsConfig &config, const _tinydir_char_t *savePath, const string &parentDependencyExportIncludeDirs)
{
if(testSourceDirs.empty() || !config.shouldBuildTests())
return Result<bool>::Ok(true);
@@ -913,6 +919,7 @@ namespace backend
}
backend::Ninja ninja;
+ ninja.addGlobalIncludeDirs(parentDependencyExportIncludeDirs);
if(!projectGeneratedBinary.empty())
ninja.addDependency(projectGeneratedBinary);
// TODO: Use same source file finder as in main.cpp
@@ -955,6 +962,9 @@ namespace backend
Result<ExecResult> runTestResult = exec(testExecutableName.c_str(), true);
if(!runTestResult)
return Result<bool>::Err(runTestResult);
+
+ if(runTestResult.unwrap().exitCode != 0)
+ return Result<bool>::Err("Tests failed", runTestResult.unwrap().exitCode);
}
}
@@ -970,11 +980,14 @@ namespace backend
if(execResult.isOk())
{
if(execResult.unwrap().exitCode == 0)
+ {
+ //printf("%s\n", execResult.unwrap().execStdout.c_str());
return Result<bool>::Ok(true);
+ }
else
- return Result<bool>::Err(execResult.unwrap().execStdout);
+ return Result<bool>::Err("");
}
else
- return Result<bool>::Err(execResult.getErrMsg());
+ return Result<bool>::Err("");
}
}
diff --git a/backend/ninja/Ninja.hpp b/backend/ninja/Ninja.hpp
index fc6842f..8411137 100644
--- a/backend/ninja/Ninja.hpp
+++ b/backend/ninja/Ninja.hpp
@@ -9,7 +9,6 @@
#include <string>
#include <functional>
-
namespace backend
{
class Ninja
@@ -24,19 +23,21 @@ namespace backend
Ninja();
+ void addGlobalIncludeDirs(const std::string &globalIncludeDirs);
void addSourceFile(const char *filepath);
void addTestSourceDir(const char *dir);
void addDependency(const std::string &binaryFile);
const std::vector<std::string>& getSourceFiles() const;
sibs::Result<bool> build(const sibs::SibsConfig &config, const _tinydir_char_t *savePath, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc = nullptr, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback = nullptr, sibs::GlobalIncludeDirCallbackFunc globalIncludeDirCallback = nullptr);
private:
- sibs::Result<bool> buildTests(const std::string &projectGeneratedBinary, const sibs::SibsConfig &config, const _tinydir_char_t *savePath);
+ sibs::Result<bool> buildTests(const std::string &projectGeneratedBinary, const sibs::SibsConfig &config, const _tinydir_char_t *savePath, const std::string &parentDependencyExportIncludeDirs);
bool containsSourceFile(const std::string &filepath) const;
bool containsTestSourceDir(const std::string &dir) const;
bool containsDependency(const std::string &dependency) const;
sibs::Result<bool> getLinkerFlags(const sibs::SibsConfig &config, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback, sibs::GlobalIncludeDirCallbackFunc globalIncludeDirCallback, sibs::CflagsCallbackFunc cflagsCallbackFunc) const;
sibs::Result<bool> compile(const _tinydir_char_t *buildFilePath);
private:
+ std::string customGlobalIncludeDirs;
std::vector<std::string> sourceFiles;
std::vector<std::string> testSourceDirs;
std::vector<std::string> binaryDependencies;