feat(ci): add a custom CMake command to run gcovr
Description
The command to run gcovr is gcovr -j${RUNNER_THREADS} -r .. --filter ../libs --filter ../modules --exclude ".*test.*" --html --html-details coverage/index.html --xml coverage/cobertura-coverage.xml --print-summary . | grep lines | sed -sE 's/.* \((.*) out of (.*)\)/\1\/\2/' | xargs -i echo 'scale=4;a={}*100;scale=2;a/1' | bc | xargs -i echo "lines: {}%"
, which is a long and ugly command. It is duplicated across multiple projects, and developers that want to use it must copy/paste it. This isn't practical. We should create a custom CMake to run it, to reduce redundancy across projects and make it simpler to use.
Functional specifications
A new custom CMake command coverage
is created, which launches gcovr. It may eventually display an error message if it is used inside a build directory which wasn't build with coverage instrumentation.
Technical specifications
Use add_custom_target
in cmake/build/flags.cmake to create the custom command coverage
, which will launch gcovr if SIGHT_ENABLE_COVERAGE
is set or display an error message if it isn't set.
Test plan
Coverage reports are still generated as usual; the custom command does display a message if used without coverage instrumentation.