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

Allow 'ninja -t compdb' accept one target #1546

Closed
wants to merge 1 commit into from

Conversation

lk-chen
Copy link

@lk-chen lk-chen commented Mar 24, 2019

Fix #1544

Test:
./ninja -t compdb -a wrong_target (fail)
./ninja -t compdb -a test_target (empty due to lack of rules)
./ninja -t compdb -a test_target cc cxx (ok)
./ninja -t compdb cxx (ok, regression test)
./ninja ninja_test && ./ninja_test (passed)

Test:
./ninja -t compdb -a wrong_target (fail)
./ninja -t compdb -a test_target (empty due to lack of rules)
./ninja -t compdb -a test_target cc cxx (ok)
./ninja -t compdb cxx (ok, regression test)
./ninja ninja_test && ./ninja_test (passed)
@@ -710,26 +743,51 @@ int NinjaMain::ToolCompilationDatabase(const Options* options, int argc,

optind = 1;
int opt;
while ((opt = getopt(argc, argv, const_cast<char*>("hx"))) != -1) {
string err;
Node* user_given_target = NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a scope in for case 'a' and move those two variable declarations there.

See http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-introduce

case 'h':
default:
printf(
"usage: ninja -t compdb [options] [rules]\n"
"usage: ninja -t compdb [options] [target] [rules]\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't [target] only useful when passing -a?

);
return 1;
}
}
argv += optind;
argc -= optind;

std::vector<Edge*> user_interested_edges;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also move this variable into the if (user_given_target) {.

}
if (visited_nodes->count(node)) {
return true;
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for else after return.

// Leaf node
if (!edge || visited_edges->count(edge)) {
return true;
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

}
if (node == NULL || depend_edges == NULL) {
Error("Internal error");
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use assert for this instead.

@jhasse
Copy link
Collaborator

jhasse commented Mar 24, 2019

Before you continue working on this, I think we need to discuss if

  1. only one target should be accepted,
  2. -a is a good name for the flag,
  3. this feature should be added at all.

@lk-chen
Copy link
Author

lk-chen commented Mar 25, 2019

  1. Technically, I don't see a way to pass multiple targets
  2. I am surely open to suggestions. I chose 'a' from 'tArget' since 't' is used for 'tools'.
  3. I am working on chromecast, and using cquery+compilation database. The compilation database is too big to work well on my laptop (~17G memory). Per my test, the size of compilatoin database JSON file decreased by ~50% if given '-a cast_shell'. I can even specify a smaller sub-target to improve performance. Thus I believe it is useful.

@lk-chen
Copy link
Author

lk-chen commented Mar 27, 2019

ping?

@jhasse
Copy link
Collaborator

jhasse commented Apr 18, 2019

ping?

Please don't do this, I'm getting enough emails as it is.

Technically, I don't see a way to pass multiple targets

Maybe separating them with ,s?

I am surely open to suggestions. I chose 'a' from 'tArget' since 't' is used for 'tools'.

--targets would be my suggestion.

I am working on chromecast, and using cquery+compilation database. The compilation database is too big to work well on my laptop (~17G memory).

I see. Why does cquery load the whole file into memory though?

@mg94c18
Copy link

mg94c18 commented Mar 5, 2023

I faced the same problem recently, and looking at the code I think it actually makes more sense to add a feature to 'targets' tool which would output all the rules that are used by given target. Then, you could use 'compdb' tool easily by giving it all those rules as arguments. In my case I could deduce the rules used by my targets from 'rules' tool with -d flag, so I didn't need the changes but here are my two cents: "-t targets rule X" gives you targets that use the rule X (existing feature, though not documented) and "-t targets rules X" could give you rules that are used by target X (possible new feature).

Alternatively, to solve the problem with parameters ([options] [target] [rules] mess), and having in mind that most people would try to put target name instead of rule name in "-t compdb [rules]", I think it would be elegant to just specify a new flag like -t with semantics "treat rules parameter as targets", leading to "-t compdb -t [rules]" which would then interpret the rules arguments differently.

Again, even without all these changes you may be able to discover rules used by your target from "-t rules -d" and then you could use existing compdb feature.

@jhasse
Copy link
Collaborator

jhasse commented Sep 4, 2023

closing in favor of #2319

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

Successfully merging this pull request may close these issues.

[Feature Request] Allow 'ninja -t compdb' accept one target
3 participants