aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/ninja/Ninja.cpp65
-rw-r--r--backend/ninja/Ninja.hpp1
2 files changed, 56 insertions, 10 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 28e4ea1..78ac68b 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -512,7 +512,7 @@ namespace backend
result += " depfile = $out.d\n";
result += " command = ccache c++ $ARGS -c $in -o $out\n\n";
- result += "rule cpp_BUILD_EXEC\n";
+ result += "rule BUILD_EXEC\n";
result += " depfile = $out.d\n";
result += " command = ccache c++ $ARGS -o $out $in $LINK_ARGS $aliasing\n\n";
@@ -526,7 +526,7 @@ namespace backend
result += "rule cpp_COMPILER\n";
result += " command = cl.exe $ARGS /c $in /Fo$out\n\n";
- result += "rule cpp_BUILD_EXEC\n";
+ result += "rule BUILD_EXEC\n";
result += " command = cl.exe $ARGS $in /Fe$out $LINK_ARGS\n\n";
result += "rule c_COMPILER\n";
@@ -535,7 +535,7 @@ namespace backend
}
}
- buildJob = "cpp_BUILD_EXEC";
+ buildJob = "BUILD_EXEC";
break;
}
case LibraryType::STATIC:
@@ -548,7 +548,7 @@ namespace backend
result += " depfile = $out.d\n";
result += " command = ccache c++ $ARGS -c -fPIC $in -o $out\n\n";
- result += "rule cpp_BUILD_STATIC\n";
+ result += "rule BUILD_STATIC\n";
result += " command = ar rcs lib";
result += config.getPackageName();
result += ".a";
@@ -564,7 +564,7 @@ namespace backend
result += "rule cpp_COMPILER\n";
result += " command = cl.exe $ARGS /c $in /Fo$out\n\n";
- result += "rule cpp_BUILD_STATIC\n";
+ result += "rule BUILD_STATIC\n";
result += " command = lib.exe /OUT:$out $in\n\n";
result += "rule c_COMPILER\n";
@@ -573,7 +573,7 @@ namespace backend
}
}
- buildJob = "cpp_BUILD_STATIC";
+ buildJob = "BUILD_STATIC";
break;
}
case LibraryType::DYNAMIC:
@@ -587,7 +587,7 @@ namespace backend
result += " command = ccache c++ $ARGS -c -fPIC $in -o $out\n\n";
// --whole-archive
- result += "rule cpp_BUILD_DYNAMIC\n";
+ result += "rule BUILD_DYNAMIC\n";
result += " depfile = $out.d\n";
result += " command = ccache c++ $in -shared -o $out $LINK_ARGS $aliasing\n\n";
@@ -601,10 +601,10 @@ namespace backend
result += "rule cpp_COMPILER\n";
result += " command = cl.exe $ARGS /c $in /Fo$out\n\n";
- //result += "rule cpp_BUILD_DYNAMIC\n";
+ //result += "rule BUILD_DYNAMIC\n";
//result += " command = cl.exe /LD $in /Fe$out $LINK_ARGS\n\n";
- result += "rule cpp_BUILD_DYNAMIC\n";
+ result += "rule BUILD_DYNAMIC\n";
result += " command = lib.exe /OUT:$out $in\n\n";
result += "rule c_COMPILER\n";
@@ -613,7 +613,7 @@ namespace backend
}
}
- buildJob = "cpp_BUILD_DYNAMIC";
+ buildJob = "BUILD_DYNAMIC";
break;
}
default:
@@ -895,6 +895,13 @@ namespace backend
Result<bool> buildResult = compile(savePath);
if (!buildResult)
return buildResult;
+
+ if(config.isMainProject())
+ {
+ buildResult = buildCompilationDatabase(savePath);
+ if(!buildResult)
+ return buildResult;
+ }
}
// TODO: If tests are being run (sibs test) and root project is an executable, do not run compile (above code) as executable.
@@ -984,6 +991,14 @@ namespace backend
if (!buildResult)
return buildResult;
+ // Convenient to have project setup to tests as well
+ if(config.isMainProject())
+ {
+ buildResult = buildCompilationDatabase(buildPath.c_str());
+ if(!buildResult)
+ return buildResult;
+ }
+
FileString testExecutableName = buildPath;
testExecutableName += TINYDIR_STRING("/");
testExecutableName += toFileString(sibsTestConfig.getPackageName());
@@ -1025,4 +1040,34 @@ namespace backend
else
return Result<bool>::Err("");
}
+
+ Result<bool> Ninja::buildCompilationDatabase(const _tinydir_char_t *buildFilePath)
+ {
+ FileString command = TINYDIR_STRING("ninja -C \"");
+ command += buildFilePath;
+ command += TINYDIR_STRING("\" -t compdb c_COMPILER cpp_COMPILER BUILD_EXEC BUILD_STATIC BUILD_DYNAMIC > \"");
+ command += buildFilePath;
+ command += TINYDIR_STRING("/compile_commands.json\"");
+ Result<ExecResult> execResult = exec(command.c_str(), false);
+ if(execResult.isOk())
+ {
+ if(execResult.unwrap().exitCode == 0)
+ {
+ //printf("%s\n", execResult.unwrap().execStdout.c_str());
+ return Result<bool>::Ok(true);
+ }
+ else
+ {
+ string errMsg = "Failed to build compilation database, reason: ";
+ errMsg += execResult.unwrap().execStdout;
+ return Result<bool>::Err(errMsg);
+ }
+ }
+ else
+ {
+ string errMsg = "Failed to build compilation database, reason: ";
+ errMsg += execResult.getErrMsg();
+ return Result<bool>::Err(errMsg);
+ }
+ }
}
diff --git a/backend/ninja/Ninja.hpp b/backend/ninja/Ninja.hpp
index 7bbff51..575a9bc 100644
--- a/backend/ninja/Ninja.hpp
+++ b/backend/ninja/Ninja.hpp
@@ -56,6 +56,7 @@ namespace backend
bool containsDependency(const std::string &dependency) const;
sibs::Result<bool> getLinkerFlags(const sibs::SibsConfig &config, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback, sibs::GlobalIncludeDirCallbackFunc globalIncludeDirCallback, sibs::CflagsCallbackFunc cflagsCallbackFunc) const;
sibs::Result<bool> compile(const _tinydir_char_t *buildFilePath);
+ sibs::Result<bool> buildCompilationDatabase(const _tinydir_char_t *buildFilePath);
private:
std::string customGlobalIncludeDirs;
std::vector<std::string> sourceFiles;