Sarcasm / compdb

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

documentation #2

Closed Miaoou closed 7 years ago

Miaoou commented 7 years ago

Hello,

Could there be some examples of usage somewhere, starting from an already generated compile_commands.json ? (especially since headerdb doesn't exist anymore).

Thanks !

Sarcasm commented 7 years ago

The absence of documentation is on purpose for now, as things move and will continue to move, sorry about that.

If you want a header database, at the moment the solution, I will demonstrate the use with irony-server, a simple CMake-project.

pip install --user compdb
compdb version
git clone git@github.com:Sarcasm/irony-mode.git
cd irony-mode/server
mkdir build
cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
cd ..
cat <<'EOF' > .compdb                                                                                                                                                 (master)
[compdb]
build-dir = build/
complementers = headerdb
EOF
compdb update
compdb list >compile_commands.json
Miaoou commented 7 years ago

Thanks a lot, this is working well, even on a big project. Still can't make YCM work with headers added anyway, I'll investigate further.

Sarcasm commented 7 years ago

What do you mean by "header added"?

Miaoou commented 7 years ago

I mean the compile_commands.json that now includes every header of my project. YCM still can't do completion on code inside headers, but this is another issue I guess.

Sarcasm commented 7 years ago

Ok, don't hesitate to tell me about this issue if you understand it, this is something headerdb is trying to solve, any edge cases interest me.

Miaoou commented 7 years ago

No problem, I'll post the solution if I find it :)

Sarcasm commented 7 years ago

For starter, you can do something like:

$ compdb list path/to/my/header.h
[
      { "directory": ....
....
]

Copy-paste the compile command, change the compiler to Clang if that's not already the case see if that compiles.

rwols commented 6 years ago

Why is there not something extremely simple like doing

$ compdb path/to/compile_commands.json > path/to/compile_commands_with_headers.json

I think the raison d'être for many users will be generation of header compile commands, so why not make that the default "complementer", and then forget about the "build-dir" property, and accept a single positional argument that points to the compilation database?

Sarcasm commented 6 years ago

Because there is an explicit "index" step right now, and because auto-detection of the main compilation database is not yet implemented.

However, I agree this should the be goal.

rwols commented 6 years ago

Apologies for my ignorance, but when you talk about the "main" compilation database, are you suggesting one can have a hierarchy of databases? All I've seen in practice is a single JSON file being generated by pretty much every build tool out there. Also, nice job on this project!

Sarcasm commented 6 years ago

I meant the initial database generated by the build tool.

However, I refrained talking about this, but one of the goal of compdb may also to aggregate compilation databases. For example, in the ROS community. they have one build directory per CMake project, but a workspace is composed of multiple CMake projects. It is sometime convenient to see the workspace as one thing, and compdb can represent the compilation databases as one.

Sarcasm commented 6 years ago

Just FYI, in the latest commit I have reworked/simplified a few things, hopefully it will be a saner base for futur development.

I will now try to maintain a section in the README to explain how to generate a compilation database for headers:

@rwols:

I have implemented a simple usage as you recommended, here is how you can generate a compilation database with headers:

compdb list -p build/ > path/to/compile_commands_with_headers.json