c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

Documentation request: Add python `compiledb` as a way to generate `compile-commands.json` from a makefile

Open wildwestrom opened this issue 3 years ago • 8 comments

I was using c2rust and I was trying to translate this project called light. ~~None of the methods from the docs to generate a compile-commands.json worked.~~ Turns out the other tools are just a bit more finicky (at least for the project I was working on).

compiledb works great. All I had to do was compiledb make (after running ./autogen.sh && ./configure --with-udev of course).

Could you please add this to the docs?

wildwestrom avatar Sep 05 '22 20:09 wildwestrom

Thanks for letting us know. I'm curious though that bear or intercept build did not work for you. What versions did you try and what distro are you on (it looks like you're using Linux)? Did you get an empty compile_commands.json or an error that you can share?

As for compiledb, I've never used it. Would you be willing to open a PR with the desired changes to the docs?

thedataking avatar Sep 12 '22 00:09 thedataking

When I run any one of these on light:

# intercept-build
intercept-build sh -c "./autogen.sh && ./configure --with-udev && make"
./autogen.sh && ./configure --with-udev && intercept-build make
# bear
bear -- sh -c "./autogen.sh && ./configure --with-udev && make"
./autogen.sh && ./configure --with-udev && bear -- make

I get a compile_commands.json with:

[]

I'm running Arch GNU/Linux.

$ pip show scan-build
Name: scan-build
Version: 2.0.20
Summary: static code analyzer wrapper for Clang.
Home-page: https://github.com/rizsotto/scan-build
Author: László Nagy
Author-email: [email protected]
License: LICENSE.txt
Location: /home/main/.local/lib/python3.10/site-packages
Requires: 
Required-by: 
$ bear --version
bear 3.0.2
$ pip show compiledb
Name: compiledb
Version: 0.10.1
Summary: Tool for generating Clang JSON Compilation Database files for make-based build systems.
Home-page: https://github.com/nickdiego/compiledb
Author: Nick Yamane
Author-email: [email protected]
License: GPLv3
Location: /home/main/.local/lib/python3.10/site-packages
Requires: bashlex, click, shutilwhich
Required-by: 

wildwestrom avatar Sep 21 '22 20:09 wildwestrom

Just to make sure, is this being run on a fresh build (after make clean)?

kkysen avatar Sep 21 '22 21:09 kkysen

Just to make sure, is this being run on a fresh build (after make clean)?

That may have been the problem all along. So far the following commands work.

rm -f compile_commands.json && make clean
intercept-build sh -c "./autogen.sh && ./configure --with-udev && make"
rm -f compile_commands.json && make clean
bear -- sh -c "./autogen.sh && ./configure --with-udev && make"

These do not:

rm -f compile_commands.json && make clean
./autogen.sh && ./configure --with-udev && intercept-build make
rm -f compile_commands.json && make clean
./autogen.sh && ./configure --with-udev && bear -- make

wildwestrom avatar Sep 21 '22 21:09 wildwestrom

What about a fresh build then? Like right after git clone? bear doesn't work if the compile commands are not actually run because they're already built.

kkysen avatar Sep 21 '22 21:09 kkysen

Yes, on a fresh clone, the following produces a compile_commands.json:

./autogen.sh && ./configure --with-udev && intercept-build make
# or
./autogen.sh && ./configure --with-udev && bear -- make

So all methods do actually work, I just had the most success with compiledb, no need to clean or use a fresh clone.

wildwestrom avatar Sep 21 '22 21:09 wildwestrom

Okay, that's better. I'm curious how compiledb is able to function without running the actual compile commands.

kkysen avatar Sep 21 '22 21:09 kkysen

¯\_(ツ)_/¯

wildwestrom avatar Sep 21 '22 21:09 wildwestrom