From 91ab79f1475371e6e57d00f24f98bccb7749d15a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 14 Jan 2018 18:36:20 +0100 Subject: Add git dependencies --- backend/ninja/Ninja.cpp | 45 +++++++++++++++++++++++++++++---------------- backend/ninja/Ninja.hpp | 5 +++-- 2 files changed, 32 insertions(+), 18 deletions(-) (limited to 'backend/ninja') 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 Ninja::getLinkerFlags(const SibsConfig &config, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback, GlobalIncludeDirCallbackFunc globalIncludeDirCallback, CflagsCallbackFunc cflagsCallbackFunc) const { - const vector &dependencies = config.getDependencies(); - if(dependencies.empty()) return Result::Ok(true); - + const vector &packageListDependencies = config.getPackageListDependencies(); + Result globalLibDirResult = getHomeDir(); if (!globalLibDirResult) return Result::Err(globalLibDirResult); @@ -284,10 +288,10 @@ namespace backend if(createGlobalLibDirResult.isErr()) return createGlobalLibDirResult; - vector globalLibDependencies; + vector globalLibDependencies; #if OS_FAMILY == OS_FAMILY_POSIX - vector pkgConfigDependencies; - for(const Dependency &dependency : dependencies) + vector pkgConfigDependencies; + for(PackageListDependency *dependency : packageListDependencies) { Result 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 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::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 buildTestResult = buildTests(projectGeneratedBinary, config, savePath); + Result buildTestResult = buildTests(projectGeneratedBinary, config, savePath, dependencyExportIncludeDirs); if(!buildTestResult) return buildTestResult; @@ -872,7 +878,7 @@ namespace backend return false; } - Result Ninja::buildTests(const std::string &projectGeneratedBinary, const SibsConfig &config, const _tinydir_char_t *savePath) + Result Ninja::buildTests(const std::string &projectGeneratedBinary, const SibsConfig &config, const _tinydir_char_t *savePath, const string &parentDependencyExportIncludeDirs) { if(testSourceDirs.empty() || !config.shouldBuildTests()) return Result::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 runTestResult = exec(testExecutableName.c_str(), true); if(!runTestResult) return Result::Err(runTestResult); + + if(runTestResult.unwrap().exitCode != 0) + return Result::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::Ok(true); + } else - return Result::Err(execResult.unwrap().execStdout); + return Result::Err(""); } else - return Result::Err(execResult.getErrMsg()); + return Result::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 #include - 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& getSourceFiles() const; sibs::Result 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 buildTests(const std::string &projectGeneratedBinary, const sibs::SibsConfig &config, const _tinydir_char_t *savePath); + sibs::Result 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 getLinkerFlags(const sibs::SibsConfig &config, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback, sibs::GlobalIncludeDirCallbackFunc globalIncludeDirCallback, sibs::CflagsCallbackFunc cflagsCallbackFunc) const; sibs::Result compile(const _tinydir_char_t *buildFilePath); private: + std::string customGlobalIncludeDirs; std::vector sourceFiles; std::vector testSourceDirs; std::vector binaryDependencies; -- cgit v1.2.3