Sarcasm / compdb

The compilation database Swiss army knife
MIT License
292 stars 23 forks source link

compdb fails when using 'arguments' instead of 'command' in compile database #3

Closed richleigh closed 7 years ago

richleigh commented 7 years ago

When using a tool such as bear (https://github.com/rizsotto/Bear) to build the compilation database for a Makefile based project, the generated compilation database uses the 'arguments' key instead of the 'command' key.

To reproduce:

git clone https://github.com/mbcrawfo/GenericMakefile.git
cd GenericMakefile/cpp
bear make
compdb -p . list

Result:

[
]
Traceback (most recent call last):
  File "/home/rich/bin/compdb", line 9, in <module>
    load_entry_point('compdb==0.1.1', 'console_scripts', 'compdb')()
  File "/home/rich/.local/lib/python2.7/site-packages/compdb-0.1.1-py2.7.egg/compdb/cli.py", line 559, in main
    command.execute()
  File "/home/rich/.local/lib/python2.7/site-packages/compdb-0.1.1-py2.7.egg/compdb/cli.py", line 239, in execute
    for compile_command in compile_commands:
  File "/home/rich/.local/lib/python2.7/site-packages/compdb-0.1.1-py2.7.egg/compdb/core.py", line 50, in <genexpr>
    for db in databases))
  File "/home/rich/.local/lib/python2.7/site-packages/compdb-0.1.1-py2.7.egg/compdb/db/json.py", line 38, in get_all_compile_commands
    return map(self._dict_to_compile_command, self._data)
  File "/home/rich/.local/lib/python2.7/site-packages/compdb-0.1.1-py2.7.egg/compdb/db/json.py", line 43, in _dict_to_compile_command
    shlex.split(d['command']))
KeyError: u'command'

Things that use libclang, such as YCM seem fine with both cmake and bear derived compilation databases, so it would be great if compdb supported both.

This was using compdb 0.1.1

Sarcasm commented 7 years ago

Indeed, it's on my todo list, thanks for reporting.

Sarcasm commented 7 years ago

Bear compatibility should be fixed by 53ae9eeee5db59893788f395de0ebe79112fbfb4. Thanks for reporting the issue.

LKlemens commented 6 years ago

Is there way to generate same output scheme like in bear? For instance:

{
        "arguments": [
            "c++",
            "-c",
            "TestMain.hpp"
        ],
        "directory": "/home/user/test",
        "file": "TestMain.hpp"
 }

Newer clang versions do not support scheme with "command" ;/

Sarcasm commented 6 years ago

It's on the TODO list to print the database in various format. But it would be better to create a new issue to track this.

However, I don't think the reason for this is correct. The Clang parser should support both arguments and command:

  • command: The compile command executed. ...
  • arguments: The compile command executed as list of strings. Either arguments or command is required.

-- https://clang.llvm.org/docs/JSONCompilationDatabase.html

LKlemens commented 6 years ago

Okej I will create new issue. When I tried to use rtags with older compile_command.json scheme that error is appeared: LIBCLANG TOOLING ERROR: json-compilation-database: Expected array.