From 33872fc72e40331c23a82f2b5ec3e509c7191d7a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 16 Dec 2017 18:23:00 +0100 Subject: Modify ninja interface to build after creating build file This setup is needed because we need to build the project before building tests --- backend/ninja/Ninja.cpp | 8 ++++++-- backend/ninja/Ninja.hpp | 4 ++-- src/GlobalLib.cpp | 6 +----- src/main.cpp | 9 +-------- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 2402ec1..6e9079a 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -196,7 +196,7 @@ namespace backend return Result::Ok(true); } - Result Ninja::createBuildFile(const SibsConfig &config, const char *savePath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback) + Result Ninja::build(const SibsConfig &config, const char *savePath, LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, LinkerFlagCallbackFunc dynamicLinkerFlagCallback) { // TODO: Do not quit here if no source files are provided. The source-less project could have dependencies if(sourceFiles.empty()) @@ -368,6 +368,10 @@ namespace backend printf("Created ninja build file: %s\n", ninjaBuildFilePath.c_str()); + Result buildResult = build(savePath); + if(!buildResult) + return buildResult; + Result buildTestResult = buildTests(projectGeneratedBinary); if(!buildTestResult) return buildTestResult; @@ -430,7 +434,7 @@ namespace backend if(!ninja.getSourceFiles().empty()) { string debugBuildPath = testSourceDir + "/sibs-build/debug"; - Result buildFileResult = ninja.createBuildFile(sibsTestConfig, debugBuildPath.c_str()); + Result buildFileResult = ninja.build(sibsTestConfig, debugBuildPath.c_str()); if (!buildFileResult) return buildFileResult; diff --git a/backend/ninja/Ninja.hpp b/backend/ninja/Ninja.hpp index 7013f78..ea73c81 100644 --- a/backend/ninja/Ninja.hpp +++ b/backend/ninja/Ninja.hpp @@ -28,14 +28,14 @@ namespace backend void addTestSourceDir(const char *dir); void addDependency(const std::string &binaryFile); const std::vector& getSourceFiles() const; - sibs::Result createBuildFile(const sibs::SibsConfig &config, const char *savePath, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc = nullptr, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback = nullptr); - sibs::Result build(const char *buildFilePath); + sibs::Result build(const sibs::SibsConfig &config, const char *savePath, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc = nullptr, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback = nullptr); private: sibs::Result buildTests(const std::string &projectGeneratedBinary); 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 std::vector &dependencies, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback) const; + sibs::Result build(const char *buildFilePath); private: std::vector sourceFiles; std::vector testSourceDirs; diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index c38e22f..30a044f 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -203,14 +203,10 @@ namespace sibs if(createBuildDirResult.isErr()) return Result::Err(createBuildDirResult); - Result buildFileResult = ninja.createBuildFile(sibsConfig, debugBuildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc); + Result buildFileResult = ninja.build(sibsConfig, debugBuildPath.c_str(), staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc); if (buildFileResult.isErr()) return Result::Err(buildFileResult.getErrMsg()); - Result buildResult = ninja.build(debugBuildPath.c_str()); - if (buildResult.isErr()) - return Result::Err(buildResult.getErrMsg()); - return Result::Ok(libPath); } } diff --git a/src/main.cpp b/src/main.cpp index 3d970f4..e645b70 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,20 +187,13 @@ int buildProject(int argc, const char **argv) walkDir(projectPath.c_str(), collectSourceFiles); string debugBuildPath = projectPath + "/sibs-build/debug"; - Result buildFileResult = ninja.createBuildFile(sibsConfig, debugBuildPath.c_str()); + Result buildFileResult = ninja.build(sibsConfig, debugBuildPath.c_str()); if(buildFileResult.isErr()) { cerr << "Failed to build ninja file: " << buildFileResult.getErrMsg() << endl; exit(7); } - Result buildResult = ninja.build(debugBuildPath.c_str()); - if(buildResult.isErr()) - { - cerr << "Failed to build ninja file: " << buildResult.getErrMsg() << endl; - exit(8); - } - return 0; } -- cgit v1.2.3