aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-08 15:15:43 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit0073788bfead1239d563e93f60dc8021bbf3dfaf (patch)
tree67bf9245e1ec0645093c53b5f865defe6074be97 /backend
parentdb5d4d6acf462983d9ae20cb9a964dae3608af1c (diff)
Use compdb tool to include header files in compile_commands.json
Diffstat (limited to 'backend')
-rw-r--r--backend/ninja/Ninja.cpp43
1 files changed, 33 insertions, 10 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index a212280..ef6c365 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -979,7 +979,6 @@ namespace backend
compileCCommand.insert(compileCCommand.end(), {
ninja::NinjaArg::createRaw("-MMD"),
- ninja::NinjaArg("-I" + config.getPackageName() + "@exe"),
ninja::NinjaArg::createRaw("$globalIncDir")
});
@@ -1816,20 +1815,18 @@ namespace backend
Result<bool> Ninja::buildCompilationDatabase(const _tinydir_char_t *buildFilePath, const FileString &saveDir)
{
+ Result<ExecResult> compdbAvailableResult = exec(TINYDIR_STRING("compdb version"), false);
+ bool isCompdbAvailable = (compdbAvailableResult && compdbAvailableResult.unwrap().exitCode == 0);
+
FileString command = TINYDIR_STRING("ninja -C \"");
- command += buildFilePath;
+ command += (isCompdbAvailable ? buildFilePath : saveDir);
command += TINYDIR_STRING("\" -t compdb compile_c compile_cpp compile_zig > \"");
- command += saveDir;
+ command += buildFilePath;
command += TINYDIR_STRING("/compile_commands.json\"");
Result<ExecResult> execResult = exec(command.c_str(), false);
- if(execResult.isOk())
+ if(execResult)
{
- if(execResult.unwrap().exitCode == 0)
- {
- //printf("%s\n", execResult.unwrap().execStdout.c_str());
- return Result<bool>::Ok(true);
- }
- else
+ if(execResult.unwrap().exitCode != 0)
{
string errMsg = "Failed to build compilation database, reason: ";
errMsg += execResult.unwrap().execStdout;
@@ -1842,5 +1839,31 @@ namespace backend
errMsg += execResult.getErrMsg();
return Result<bool>::Err(errMsg);
}
+
+ if(isCompdbAvailable)
+ {
+ command = TINYDIR_STRING("compdb -p \"");
+ command += buildFilePath;
+ command += TINYDIR_STRING("\" list > \"");
+ command += saveDir;
+ command += TINYDIR_STRING("/compile_commands.json\"");
+ execResult = exec(command.c_str(), false);
+ if(execResult)
+ {
+ if(execResult.unwrap().exitCode != 0)
+ {
+ 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);
+ }
+ }
+ return Result<bool>::Ok(true);
}
}