@@ -30,12 +30,13 @@ get_num_processors() {
3030 esac
3131}
3232
33- CURRENT_DIR=" $( dirname -- " $( realpath -- " $0 " ) " ) "
33+ CURRENT_DIR=" $( dirname $( realpath $0 ) ) "
3434PARENT_DIR=" $( dirname " $CURRENT_DIR " ) "
3535
3636CC=" ${CC:- $(which gcc || echo ' ' )} "
3737CXX=" ${CXX:- $(which g++ || echo ' ' )} "
3838GCOV=" ${GCOV:- $(which gcov || echo ' ' )} "
39+ COV_REPORT_GENERATOR=" ${COV_REPORT_GENERATOR:- $(which lcov || which gcovr || echo ' ' )} "
3940FOO_SRC_DIR=" ${FOO_SRC_DIR:- $CURRENT_DIR } "
4041FOO_BUILD_DIR=" ${FOO_BUILD_DIR:- $CURRENT_DIR / build} "
4142FOO_OUTPUT_DIR=" ${FOO_OUTPUT_DIR:- $CURRENT_DIR / output} "
@@ -75,7 +76,7 @@ help() {
7576 -z --coverage-report=[str] Target path to generate coverage HTML report files (FOO_COVERAGE_REPORT=$FOO_COVERAGE_REPORT ). Empty for no report.
7677
7778 -j --jobs=[int] Number of processors to build (FOO_CMAKE_JOBS=$FOO_CMAKE_JOBS )
78- -o --output-dir=[str] Output directory. Used to host lcov .info files. Also default to host junit report (FOO_OUTPUT_DIR=$FOO_OUTPUT_DIR ).
79+ -o --output-dir=[str] Output directory. Used to host coverage report and junit report (FOO_OUTPUT_DIR=$FOO_OUTPUT_DIR ).
7980
8081 -t --tests=[bool] Build foo tests (FOO_TESTS_ENABLED=$FOO_TESTS_ENABLED )
8182 -a --tests-report[str] Unit tests Junit report path (FOO_TEST_REPORT=$FOO_TEST_REPORT ). Empty for no report.
@@ -120,11 +121,11 @@ while getopts btch-: OPT; do # allow -b -t -c -h, and --long_attr=value"
120121 x | cxx) CXX=" $OPTARG " ;;
121122 y | clean) FOO_CLEAN=$( on_off $OPTARG ) ;;
122123 g | coverage) FOO_COVERAGE_ENABLED=$( on_off $OPTARG ) ;;
123- z | coverage-report) FOO_COVERAGE_REPORT=$( realpath -q " $OPTARG " ) ;;
124+ z | coverage-report) FOO_COVERAGE_REPORT=$( realpath " $OPTARG " ) ;;
124125 j | jobs) FOO_CMAKE_JOBS=$OPTARG ;;
125126 o | output-dir ) FOO_OUTPUT_DIR=$( realpath " $OPTARG " ) ;;
126127 t | tests) FOO_TESTS_ENABLED=$( on_off $OPTARG ) ;;
127- a | tests-report) FOO_TEST_REPORT=$( realpath -q " $OPTARG " ) ;;
128+ a | tests-report) FOO_TEST_REPORT=$( realpath " $OPTARG " ) ;;
128129 r | tests-run ) FOO_RUN_TESTS=$( on_off $OPTARG ) ;;
129130 f | tests-run-filter) FOO_RUN_TESTS_FILTER=" $OPTARG " ;;
130131 h | help ) help ;;
221222if [ " $FOO_COVERAGE_ENABLED " == " ON" ]; then
222223 mkdir -p " $FOO_OUTPUT_DIR "
223224 pushd $FOO_OUTPUT_DIR
224- # base coverage files
225- echo " lcov capture:"
226- lcov --capture --directory $FOO_BUILD_DIR --output-file lcov_foo_test.info --gcov-tool $GCOV
227- lcov --remove lcov_foo_test.info -o lcov_foo_test_no_deps.info ' */lib/*'
228- lcov --list lcov_foo_test_no_deps.info
229- # optional coverage html report
230- if [ " $FOO_COVERAGE_REPORT " != " " ]; then
231- genhtml --prefix ./src --ignore-errors source lcov_foo_test_no_deps.info --legend --title " $( git rev-parse HEAD) " --output-directory=" $FOO_COVERAGE_REPORT "
225+
226+ if [[ " $COV_REPORT_GENERATOR " == * " gcovr" * ]]; then
227+ pushd $FOO_BUILD_DIR
228+ gcovr -r $CURRENT_DIR --html-details $FOO_OUTPUT_DIR /coverage.html
229+ popd
230+ else
231+ if [[ " $COV_REPORT_GENERATOR " == * " lcov" * ]]; then
232+ # base coverage files
233+ echo " lcov capture:"
234+ lcov --capture --directory $FOO_BUILD_DIR --output-file lcov_foo_test.info --gcov-tool $GCOV
235+ lcov --remove lcov_foo_test.info -o lcov_foo_test_no_deps.info ' */lib/*'
236+ lcov --list lcov_foo_test_no_deps.info
237+ # optional coverage html report
238+ if [ " $FOO_COVERAGE_REPORT " != " " ]; then
239+ genhtml --prefix ./src --ignore-errors source lcov_foo_test_no_deps.info --legend --title " $( git rev-parse HEAD) " --output-directory=" $FOO_COVERAGE_REPORT "
240+ fi
241+ else
242+ echo Cannot determine the coverage report generator tool path. Please set COV_REPORT_GENERATOR variable !
243+ exit 1;
244+ fi
232245 fi
233246 popd
234- fi
247+ fi
0 commit comments