aboutsummaryrefslogtreecommitdiff
path: root/backend/ninja
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-09 17:27:08 +0100
committerdec05eba <dec05eba@protonmail.com>2017-12-09 17:28:43 +0100
commit2ed7d0b09caa872e44e2eb09b09b2387e93f9b34 (patch)
tree2abb2aeab1cdb679a79f82ef686b0ecbba1ae281 /backend/ninja
parente7384a7672e4449bc194ca3ec66cdd4fcc63801e (diff)
Add project compilation after ninja file is created
Diffstat (limited to 'backend/ninja')
-rw-r--r--backend/ninja/Ninja.cpp18
-rw-r--r--backend/ninja/Ninja.hpp1
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;