-
Notifications
You must be signed in to change notification settings - Fork 36
Allow calculating cpp coverage #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds C++ code coverage support using lcov and genhtml tools to generate coverage reports for the C++ codebase.
- Introduces CMake option
MLT_WITH_COVERAGEto enable coverage instrumentation - Adds two new justfile recipes:
coverage-cppfor generating raw coverage data andcoverage-cpp-htmlfor HTML reports - Configures compiler/linker flags for coverage in both the main library and test targets, with special handling for macOS static library linking
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| justfile | Adds coverage-cpp and coverage-cpp-html recipes that build with coverage flags, run tests, and generate lcov/HTML reports |
| cpp/CMakeLists.txt | Introduces MLT_WITH_COVERAGE option and applies coverage compiler/linker flags to the mlt-cpp library when enabled |
| cpp/test/CMakeLists.txt | Applies coverage flags to the test target and adds macOS-specific force_load linker option to include static library coverage symbols |
| cpp/.gitignore | Adds build-coverage directory to ignore list for coverage build artifacts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if(MLT_WITH_COVERAGE) | ||
| message(STATUS "[MLT] Enabling code coverage instrumentation") | ||
| if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") | ||
| target_compile_options(mlt-cpp PRIVATE --coverage -fprofile-arcs -ftest-coverage) |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The --coverage flag already includes -fprofile-arcs -ftest-coverage, making the explicit addition of these flags redundant. You can simplify this to just --coverage.
| target_compile_options(mlt-cpp PRIVATE --coverage -fprofile-arcs -ftest-coverage) | |
| target_compile_options(mlt-cpp PRIVATE --coverage) |
|
|
||
| if(MLT_WITH_COVERAGE) | ||
| if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") | ||
| target_compile_options(mlt-cpp-test PRIVATE --coverage -fprofile-arcs -ftest-coverage) |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The --coverage flag already includes -fprofile-arcs -ftest-coverage, making the explicit addition of these flags redundant. You can simplify this to just --coverage.
| target_compile_options(mlt-cpp-test PRIVATE --coverage -fprofile-arcs -ftest-coverage) | |
| target_compile_options(mlt-cpp-test PRIVATE --coverage) |
| cmake --build build-coverage --target mlt-cpp-test | ||
| build-coverage/test/mlt-cpp-test | ||
| lcov --directory build-coverage --capture --output-file coverage/coverage.info --ignore-errors inconsistent | ||
| lcov --extract coverage/coverage.info '*/cpp/src/mlt/*' '*/cpp/include/mlt/*' --output-file coverage/coverage.info --ignore-errors inconsistent |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the same file for both input (coverage/coverage.info) and output (--output-file coverage/coverage.info) in the lcov extract command is risky. If the extraction fails midway, you could lose the original data. Consider using a temporary file first (e.g., coverage/coverage.filtered.info) and then moving it, or at minimum using a different intermediate filename.
| lcov --extract coverage/coverage.info '*/cpp/src/mlt/*' '*/cpp/include/mlt/*' --output-file coverage/coverage.info --ignore-errors inconsistent | |
| lcov --extract coverage/coverage.info '*/cpp/src/mlt/*' '*/cpp/include/mlt/*' --output-file coverage/coverage.filtered.info --ignore-errors inconsistent | |
| mv coverage/coverage.filtered.info coverage/coverage.info |
|
I had to add additional ignores to make it work: |
@TimSylvester Could you try this with
I only tried on macOS.
You need to have
lcovinstalled