rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.64k stars 306 forks source link

Bear produces empty compile_commands.json #544

Closed FaiqueAli closed 10 months ago

FaiqueAli commented 10 months ago

Describe the bug I am trying to create a compile_commands.json file for my project which has a Makefile in order to execute clang-tidy. The project is being compiled using 'make -j8 all' command with and without bear. but with Bear, I am getting an empty compile_commands.json

I tried different options but had no luck.

bear -vvvv -l /usr/lib/x86_64-linux-gnu/bear/libear.so make -j8 all bear -vvvv make -j8 all

To Reproduce Steps to reproduce the behavior:

bear -vvvv make -j8 all

Expected behavior Successful generation of compile_commands.json file.

Environment:

Additional context

Before you send...

rizsotto commented 10 months ago

Hey @FaiqueAli , two things I would say...

FaiqueAli commented 10 months ago

Thanks for the reply,

So I updated my OS and the Bear package now the current version of Bear is bear 3.0.18 with linux 22.04 and the compiler path is qcc: /home/sayedf/qnx710/host/linux/x86_64/usr/bin/qcc

Similarly the libexec.so path

image

and bear --help shows

image

other information: file which make is /home/sayedf/qnx710/host/linux/x86_64/usr/bin/make: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 4.4.162, with debug_info, not stripped

so the output of the command bear --verbose -- make -j8 all is here compile-op.txt

Meanwhile I was able to generate compile_commands.json file, with this command make clean bear --verbose --config config.json -- make -j8 all When I was trying multiple options. But when I applied the same process a second time it generated an empty compile_commands.json file.

rizsotto commented 10 months ago

Good to hear that you managed to install a newer version.

For the empty output on the second time, could it be that the second run was not call the compiler? (Bear builds the output from the intercepted compiler calls. You either use the --append flag to keep the existing entries, or do a make clean before you run it again.)

From the logs, I see that it does not recognize the qcc compiler. This you can fix by the configuration file. (Read more about it on the man bear-citnames page.)

FaiqueAli commented 10 months ago

Unfortunately, I forgot what other commands I executed at first time that generated the proper file, I only remember make clean and bear -- make -j8 all . Using these commands I am now not able to get the desired file.

Sadly I am not able to learn about configuration files as the output of the command man bear-citnames shows

image

rizsotto commented 10 months ago

https://github.com/rizsotto/Bear/blob/master/source/citnames/man/bear-citnames.1.md is the man page in markdown.

FaiqueAli commented 10 months ago

Hi, So I created a config.json file and still getting an empty compile_command.json file, Below is the snapshot of confog.json file

image

Please have a look at the attached log of the command below

make clean bear --verbose --config config.json -- make -j8 all

bear-result.txt

rizsotto commented 10 months ago

Just quickly looking at the config file, what stands up to me is that you put only the directory and not the compiler at compilation.compilers_to_recognize[0].executable.

arif-desu commented 10 months ago

Hey, having the same issue where bear generates empty compilation database. I am on macOS (apple silicon) and installed bear through homebrew.

Works fine on my Linux VM(Fedora), just issue with macos

rizsotto commented 10 months ago

@parasaito , he is using Linux... the problem is he wrote /home/sayedf/qnx710/host/linux/x86_64/usr/bin and not /home/sayedf/qnx710/host/linux/x86_64/usr/bin/qcc. In the logs you can see lines like this, when the compilation was captured, but not recognized.

[18:21:54.073392, cs, 8712] [pid: 8682] execution: {"executable":"/home/sayedf/qnx710/host/linux/x86_64/usr/bin/qcc","arguments":["qcc","-lang-c++","-Vgcc_ntoaarch64le","-std=gnu++17", ...
[18:21:54.076061, cs, 8712] [pid: 8682] recognition failed: No tools recognize this execution.
FaiqueAli commented 10 months ago

Hi, Finally, the file is created with the required entries but the message at the end shows it is still failed bear-result.txt

[08:55:35.134201, cs, 24296] [pid: 24289] recognition failed: No tools recognize this execution. [08:55:35.134591, cs, 24296] compilation entries created. [size: 39] [08:55:35.134623, cs, 24296] compilation entries to output. [size: 39] [08:55:35.437564, cs, 24296] compilation entries written. [size: 39] [08:55:35.439112, cs, 24296] succeeded with: 0 [08:55:35.440143, br, 23160] Process wait request: done. [pid: 24296] [08:55:35.440202, br, 23160] Running citnames finished. [Exited with 0] [08:55:35.443252, br, 23160] succeeded with: 0 so is this a normal behaviour?

Secondly, I am getting some errors with clang-tidy as it does not recognize or exclude non-user header files(system headers) using compile_commands.json file.

is this the correct forum to discuss?

rizsotto commented 10 months ago
[08:55:35.132175, cs, 24296] [pid: 24289] execution: {"executable":"/home/sayedf/qnx710/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld","arguments":["/home/sayedf/qnx710/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld", ...

It was not recognize the linking step as compilation. I think that's correct.

rizsotto commented 10 months ago

Sorry @FaiqueAli , can't help with the clang-tidy problem.

Better to look into their doc.

FaiqueAli commented 10 months ago

Thank you for your support :)