diff options
-rw-r--r-- | backend/ninja/Ninja.cpp | 18 | ||||
-rw-r--r-- | backend/ninja/Ninja.hpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 6 |
3 files changed, 24 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; diff --git a/src/main.cpp b/src/main.cpp index 9f14c67..05a6a03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -190,5 +190,11 @@ int main(int argc, const char **argv) exit(7); } + Result<bool> buildResult = ninja.build(debugBuildPath.c_str()); + if(buildResult.isErr()) + { + exit(8); + } + return 0; }
\ No newline at end of file |