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

can you make the filed "arguments" turn to "command"? #196

Closed
zhangxiaobin2 opened this issue Dec 20, 2017 · 15 comments
Closed

can you make the filed "arguments" turn to "command"? #196

zhangxiaobin2 opened this issue Dec 20, 2017 · 15 comments
Milestone

Comments

@zhangxiaobin2
Copy link

can you make the field "arguments" turn to "command"?
Or add the field "command" to the compilation database json file?

like:
[
{
"directory": "/usr1/developer_codes/workspace/open_source/cppcheck/cppcheck-1.81/build/externals/tinyxml",
"command": "/usr/bin/c++ -DCFGDIR=\"/usr/local/share/CppCheck\" -D_GLIBCXX_DEBUG -I/usr1/developer_codes/workspace/open_source/cppcheck/cppcheck-1.81/build/externals/tinyxml -I/usr1/developer_codes/workspace/open_source/cppcheck/cppcheck-1.81/externals/tinyxml -Wabi -Wcast-qual -Wconversion -Wfloat-equal -Winline -Wmissing-declarations -Wmissing-format-attribute -Woverloaded-virtual -Wpacked -Wredundant-decls -Wshadow -Wsign-promo -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wextra -pedantic -Wno-long-long -Wall -std=c++0x -g -DDEBUG -O0 -o CMakeFiles/tinyxml_objs.dir/tinyxml2.cpp.o -c /usr1/developer_codes/workspace/open_source/cppcheck/cppcheck-1.81/externals/tinyxml/tinyxml2.cpp",
"file": "/usr1/developer_codes/workspace/open_source/cppcheck/cppcheck-1.81/externals/tinyxml/tinyxml2.cpp"
},
]

@rizsotto
Copy link
Owner

Thanks for the feature request! May I ask what is the reason to ask for this?
The compilation database is allow to use command or arguments equally. Both form is supported for more than 2 years from Clang side.
The benefits for arguments are mostly coming that it does not needs to be shell escaped inside the JSON string. (The command gives you the illusion, that you can copy-paste it to your shell, but JSON escaping still can be there, so it's very twisty.) In the past command was the only supported attribute and Bear was generating output with that. The number of bugs and the code complexity made me switch to use the arguments field instead.

@zhangxiaobin2
Copy link
Author

Thank your for your replay.
I could understand what you mean.

The reason why I need to use command is because of the Clang Cross Translation Unit project:
https://github.com/Ericsson/clang (fork from llvm/clang)

The script files under the folder can not support field "arguments":
https://github.com/Ericsson/clang/tree/ctu-clang5/tools/xtu-build-new

I have already adapt "arguments" to "command" by myself on the project:
https://github.com/Ericsson/clang/tree/ctu-clang5 (wait to be merged)

But, do you think it's a good idea to add the field "command" to the compilation database json file?

Thanks

@rizsotto
Copy link
Owner

Very nice, I agree that the CTU tool shall implement the compilation database interface if it's using it.

I would not spend time to repeat history in Bear (and implement the command field). I see other feature request more beneficial and adding more value than this. Hope it won't cause big trouble for you.

Was planing to write a separate tool which takes a compilation database (CDB), manipulate the entries and write it back to another file. The manipulations can be: filtering entries, change paths to relative to a directory, etc... To convert arguments to command could be another of those.

@zhangxiaobin2
Copy link
Author

Thank you!
I can do it by mysel.
Like escape "command" to BASE64 text. When I use the BASE64 text , I can translate it to orignal.
That would be no trouble with JSON escaping :) haha...

@jefftrull
Copy link

I wish this would be reopened as an enhancement... I am using the static analyzer cppcheck and it (silently) assumes the "command" form. It looks like it would probably be easier to update this generator than to change the cppcheck parser. Thank you!

@rizsotto
Copy link
Owner

Sure we can reopen this. The solution will be another tool which helps to transform compilation database from one form to another. (Will not be part of bear.) At the same time I suggest you to open a ticket on cppcheck to adapt their tool to the spec.

@rizsotto rizsotto reopened this Jan 17, 2018
@jefftrull
Copy link

Thank you, and I agree.

@Sarcasm
Copy link
Contributor

Sarcasm commented Jan 21, 2018

Not sure if self-promotion is welcomed here, but writing different output formats is what I'd like to have in https://github.com/Sarcasm/compdb one day, I had in mind something like:

compdb -p build/ list --output-format=[json-v1|json-v2]

This can be added fairly easily I believe.

@rizsotto
Copy link
Owner

Hey Guillaume, thanks for the head up! Was not know about your tool. And from its small description looks you are targeting this scenario. (Which I'm glad not to code if that exists elsewhere.)

If you could dump a bit more doc around compdb, I would be happy to insert a link in Bear's README to your repo.

I got a couple of candidate what kind of conversion were asked beside this. Shall I create a ticket on your repo about them?

@Sarcasm
Copy link
Contributor

Sarcasm commented Jan 22, 2018

I got a couple of candidate what kind of conversion were asked beside this. Shall I create a ticket on your repo about them?

Yes please, I would be curious to hear about them.

@Shreeasish
Copy link

I stumbled onto this while trying to generate compilation databases for the CTU and for others like me I'd like to point out that the compilation database expected by the XTU scripts can be generated by using intercept-build.

@rizsotto
Copy link
Owner

@Shreeasish I don't recommend the Clang version of scan-build. Mainly because it's not released, neither really maintained. (I wrote it, but don't update it anymore.)

@Sarcasm created an issue on your compdb repo with the feature ideas. We can continue there. :)

@smhc
Copy link
Contributor

smhc commented Sep 2, 2018

ale is another tool which assumes compile_commands.json uses 'command' rather than 'arguments':

https://github.com/w0rp/ale/blob/9d7c48038cbbc696fe2d1e9c4b2d9eff2dd726c3/autoload/ale/c.vim#L175

@WallStProg
Copy link

WallStProg commented Apr 23, 2019

FWIW, I've been bitten by this also -- in order to support the "arguments" format I would need to rewrite the tools at https://github.com/btorpey/static to read JSON format, and frankly I have no appetite (nor time) for that. Some of us still prefer plain old text formats ...

Hope you'll reconsider.

@rizsotto rizsotto added this to To do in 2.4.3 Aug 29, 2019
@rizsotto rizsotto removed this from To do in 2.4.3 Jan 16, 2020
@rizsotto rizsotto added this to the 3.0 milestone Sep 13, 2020
@rizsotto
Copy link
Owner

There is a release candidate on master branch now, which suppose to fix this issue. To have the command field in the output you need to do a little extra work now. (The default configuration in bear still makes the output with arguments.) You might need to create a config file for citnames which is a tool that takes the execution process list and creates the compilation database.

So instead of just say bear -- make you need to do this...

$ intercept --output commands.json -- make
$ citnames --input commands.json --output compile_commands.json --config config.json

where the content of the config.json should be something like this:

{
  "compilation": {
  },
  "output": {
    "content": {
      "include_only_existing_source": true
    },
    "format": {
      "command_as_array": false,
      "drop_output_field": false
    }
  }
}

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

No branches or pull requests

7 participants