summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2019-08-02 14:59:22 +0200
committerJan Niklas Hasse <jhasse@bixense.com>2019-08-02 14:59:46 +0200
commit20af31d586c1f1bddeaad0583adc17933d5465ce (patch)
treef02d5e74f98ed52d962b4cede3aab5bec433c11c
parent66b4cc94c4f2d34289cc6bfa827e7cb862a70c67 (diff)
downloadninja-20af31d586c1f1bddeaad0583adc17933d5465ce.tar.gz
compdb: Dump every rule without any arguments, fix #1377
-rw-r--r--src/ninja.cc44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index b25f11e..c24f09d 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -757,6 +757,19 @@ std::string EvaluateCommandWithRspfile(const Edge* edge,
return command;
}
+void printCompdb(const char* const directory, const Edge* const edge,
+ const EvaluateCommandMode eval_mode) {
+ printf("\n {\n \"directory\": \"");
+ EncodeJSONString(directory);
+ printf("\",\n \"command\": \"");
+ EncodeJSONString(EvaluateCommandWithRspfile(edge, eval_mode).c_str());
+ printf("\",\n \"file\": \"");
+ EncodeJSONString(edge->inputs_[0]->path().c_str());
+ printf("\",\n \"output\": \"");
+ EncodeJSONString(edge->outputs_[0]->path().c_str());
+ printf("\"\n }");
+}
+
int NinjaMain::ToolCompilationDatabase(const Options* options, int argc,
char* argv[]) {
// The compdb tool uses getopt, and expects argv[0] to contain the name of
@@ -805,22 +818,21 @@ int NinjaMain::ToolCompilationDatabase(const Options* options, int argc,
e != state_.edges_.end(); ++e) {
if ((*e)->inputs_.empty())
continue;
- for (int i = 0; i != argc; ++i) {
- if ((*e)->rule_->name() == argv[i]) {
- if (!first)
- putchar(',');
-
- printf("\n {\n \"directory\": \"");
- EncodeJSONString(&cwd[0]);
- printf("\",\n \"command\": \"");
- EncodeJSONString(EvaluateCommandWithRspfile(*e, eval_mode).c_str());
- printf("\",\n \"file\": \"");
- EncodeJSONString((*e)->inputs_[0]->path().c_str());
- printf("\",\n \"output\": \"");
- EncodeJSONString((*e)->outputs_[0]->path().c_str());
- printf("\"\n }");
-
- first = false;
+ if (argc == 0) {
+ if (!first) {
+ putchar(',');
+ }
+ printCompdb(&cwd[0], *e, eval_mode);
+ first = false;
+ } else {
+ for (int i = 0; i != argc; ++i) {
+ if ((*e)->rule_->name() == argv[i]) {
+ if (!first) {
+ putchar(',');
+ }
+ printCompdb(&cwd[0], *e, eval_mode);
+ first = false;
+ }
}
}
}