Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ninja -t compdb' should dump every rule #1377

Closed
zmike opened this issue Jan 29, 2018 · 4 comments
Closed

'ninja -t compdb' should dump every rule #1377

zmike opened this issue Jan 29, 2018 · 4 comments
Labels
Milestone

Comments

@zmike
Copy link

zmike commented Jan 29, 2018

I'm trying to use the compdb generation functionality of ninja, but it seems to just output [\n] every time. There's no documentation for this option, so it seems like there should be no other requirements than to run the command with a valid -C option?

Using ninja version 1.8.2 in case that matters.

@charlie-ht
Copy link

charlie-ht commented Feb 21, 2018

I'm also confused by this tool. I don't have problems passing rule names like cc cxx if they exist, but my problem with it was that I figured with no arguments, it should dump every rule it knows about, and only fallback to filtering when you give it arguments to do so.

I'm not sure if it's the project I work on or CMake, but when run using CMake in this project, the rule names are incredibly baroque and plentiful, so typing them all out is a non-starter for me. Instead, I use this patch to the package on my Ubuntu computer,

--- ninja-build-1.7.2.orig/src/ninja.cc
+++ ninja-build-1.7.2/src/ninja.cc
@@ -638,20 +638,36 @@ int NinjaMain::ToolCompilationDatabase(c
        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((*e)->EvaluateCommand().c_str());
-        printf("\",\n    \"file\": \"");
-        EncodeJSONString((*e)->inputs_[0]->path().c_str());
-        printf("\"\n  }");
+    if (argc == 0) {
+      if (!first)
+        putchar(',');
 
-        first = false;
+      printf("\n  {\n    \"directory\": \"");
+      EncodeJSONString(&cwd[0]);
+      printf("\",\n    \"command\": \"");
+      EncodeJSONString((*e)->EvaluateCommand().c_str());
+      printf("\",\n    \"file\": \"");
+      EncodeJSONString((*e)->inputs_[0]->path().c_str());
+      printf("\"\n  }");
+
+      first = false;
+    } else {
+      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((*e)->EvaluateCommand().c_str());
+          printf("\",\n    \"file\": \"");
+          EncodeJSONString((*e)->inputs_[0]->path().c_str());
+          printf("\"\n  }");
+
+          first = false;
+        }
       }
     }
   }

I never bothered cleaning it and posting to the list, because CMake provides it's own way to generate compile commands, but the above might help you in your situation.

@jhasse
Copy link
Collaborator

jhasse commented Nov 2, 2018

I figured with no arguments, it should dump every rule it knows about, and only fallback to filtering when you give it arguments to do so.

That sounds reasonable to me.

@jhasse jhasse changed the title 'ninja -t compdb cc cxx' doesn't work? 'ninja -t compdb' should dump every rule Nov 2, 2018
@jhasse jhasse added this to the 1.10.0 milestone Nov 2, 2018
@jhasse jhasse added the feature label Nov 2, 2018
@nico
Copy link
Collaborator

nico commented Nov 15, 2018

As mentioned on #1024 (comment) , I think this would be a good change.

@onqtam
Copy link

onqtam commented Feb 10, 2019

yes please.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants