AdamNiederer / cov

An emacs extension for displaying coverage data on your code
GNU General Public License v3.0
76 stars 16 forks source link

gcov: add support for CMake-based projects and UI enhancement #53

Open abougouffa opened 1 year ago

abougouffa commented 1 year ago

For CMake projects, the .gcov files aren't stored beside the source file, instead, they are placed next to the generated object files (in CMake projects, it will be somewhere like path/to/build/dir/CMakeFiles/target.src/path/to/file/file.cpp.gcov)

Also, as CMake generates object files as file.cpp.o instead of file.o, gcov generates a file based on that file.cpp.gcov and not file.gcov.

I've added a function which leverages the information included in the compile_commands.json, it extracts the build directory and the build command for the file, and then constructs the path to the .gcov file which will be next to the .o file.

The second commit adds support for line highlighting with bright versions of cov-*-faces. This feature is configurable via cov-highlight-lines, I've set its initial value to nil.

Here are some examples:

cov-highlight-lines = t, cov-coverage-mode = t Screenshot_20221231_213417

cov-highlight-lines = t, cov-coverage-mode = nil Screenshot_20221231_213448

snogge commented 1 year ago

I think it would have made more sense to submit these as two separate PRs, but please do not close this PR if you decide to split it.

abougouffa commented 1 year ago

Hello @snogge ,

Thank you for the reviews, I've fixed some of your spotted issues, mainly for the CMake+gcov stuff. I will try to fix documentation and tests issues later when I have some free time.

I will leave this PR for CMake+gcov stuff. So reverted the highlighting commit, I will open a separate PR for that.

abougouffa commented 1 year ago

To respond to your comments, for the compile_commands.json file, it is indeed an optional output of CMake (can be enabled by passing -DCMAKE_EXPORT_COMPILE_COMMANDS=ON to cmake when configuring the project).

The file is generally generated in the build directory, so when configuring a CMake project with a command like this:

cmake -S . -B build/debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

The compile_commands.json will be generated under build/debug/compile_commands.json; however, the common workflow with CMake projects is to symlink this file in the project's root directory. This enables LSP servers to find the right build options for the project (enabled compiler features, system libraries, include paths, ...).

So I think it is Ok to assume the file is in the root directory, but if it is not, the cov--locate-gcov-cmake returns nil, so we can test other rules.

I've added a last check in the function to assure the generated .gcov file actually exists. This will help to avoid shadowing other functions in cov-coverage-file-paths with files that doesn't exist.

I will try later to add a toy example for a CMake based project to test the code, as well as mentioning this in the README file.