aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-06-28 18:20:15 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:32 +0200
commit5a13015ad932cffb092da080e8ea0ad2ce1f04a0 (patch)
treea896dabecfa59ea3f20697e6fc8332b90d8e27be
parente132c085d2438fec368bdaf26032037bc7e88d00 (diff)
Move compile_commands.json to project root directory, needed for IDEs
-rw-r--r--.gitignore1
-rw-r--r--backend/ninja/Ninja.cpp8
-rw-r--r--backend/ninja/Ninja.hpp2
-rw-r--r--src/main.cpp3
4 files changed, 9 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index 90f7754..e2f4b7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ build/
cmake/build/
cmake-build-debug/
.vs/
+compile_commands.json
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index 59e8486..227a179 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -917,7 +917,7 @@ namespace backend
if(config.isMainProject())
{
- buildResult = buildCompilationDatabase(savePath);
+ buildResult = buildCompilationDatabase(savePath, config.getProjectPath());
if(!buildResult)
return buildResult;
}
@@ -1011,7 +1011,7 @@ namespace backend
// Convenient to have project setup to tests as well
if(config.isMainProject())
{
- buildFileResult = buildCompilationDatabase(buildPath.c_str());
+ buildFileResult = buildCompilationDatabase(buildPath.c_str(), testSourceDirNative);
if(!buildFileResult)
return buildFileResult;
}
@@ -1058,12 +1058,12 @@ namespace backend
return Result<bool>::Err("");
}
- Result<bool> Ninja::buildCompilationDatabase(const _tinydir_char_t *buildFilePath)
+ Result<bool> Ninja::buildCompilationDatabase(const _tinydir_char_t *buildFilePath, const FileString &saveDir)
{
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 += saveDir;
command += TINYDIR_STRING("/compile_commands.json\"");
Result<ExecResult> execResult = exec(command.c_str(), false);
if(execResult.isOk())
diff --git a/backend/ninja/Ninja.hpp b/backend/ninja/Ninja.hpp
index 575a9bc..68e51b1 100644
--- a/backend/ninja/Ninja.hpp
+++ b/backend/ninja/Ninja.hpp
@@ -56,7 +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);
+ sibs::Result<bool> buildCompilationDatabase(const _tinydir_char_t *buildFilePath, const sibs::FileString &savePath);
private:
std::string customGlobalIncludeDirs;
std::vector<std::string> sourceFiles;
diff --git a/src/main.cpp b/src/main.cpp
index 22198b5..ecbf9cd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -90,6 +90,9 @@ using namespace std::chrono;
// TODO: Add program command for generating compile_commands.json without compiling code, without using Ninja
+// TODO: Make Process::exec safe to use. Currently you pass an argument and it's run as a command, but the string can be escaped to perform malicious acts.
+// Process::exec should be modified to take a list of arguments to execute command with.
+
#if OS_FAMILY == OS_FAMILY_POSIX
#define fout std::cout
#define ferr std::cerr