diff options
Diffstat (limited to 'backend/ninja')
-rw-r--r-- | backend/ninja/Ninja.cpp | 18 | ||||
-rw-r--r-- | backend/ninja/Ninja.hpp | 1 |
2 files changed, 18 insertions, 1 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 683fb67..73a6dc3 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -42,7 +42,7 @@ namespace backend int exitCode; }; - Result<ExecResult> exec(const char *cmd) + Result<ExecResult> exec(const char *cmd, bool print = false) { char buffer[128]; string result; @@ -53,7 +53,11 @@ namespace backend while(!feof(pipe)) { if(fgets(buffer, 128, pipe)) + { result += buffer; + if(print) + printf("%s", buffer); + } } ExecResult execResult; @@ -258,4 +262,16 @@ namespace backend printf("Created ninja build file: %s\n", savePath); return Result<bool>::Ok(true); } + + Result<bool> Ninja::build(const char *buildFilePath) + { + string command = "ninja -C '"; + command += buildFilePath; + command += "'"; + Result<ExecResult> execResult = exec(command.c_str(), true); + if(execResult.isOk()) + return Result<bool>::Ok(true); + else + return Result<bool>::Err(execResult.getErrMsg()); + } }
\ No newline at end of file diff --git a/backend/ninja/Ninja.hpp b/backend/ninja/Ninja.hpp index 1ba20c7..fdaa890 100644 --- a/backend/ninja/Ninja.hpp +++ b/backend/ninja/Ninja.hpp @@ -14,6 +14,7 @@ namespace backend public: void addSourceFile(const char *filepath); sibs::Result<bool> createBuildFile(const std::string &packageName, const std::vector<sibs::Dependency> &dependencies, const char *savePath); + 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) const; |