#!/bin/sh
# must be executed in project root folder
if [ -z $GCOV ]; then
  GCOV=gcov
fi

PROJECT_DIR="$(dirname $0)/../"
LCOV_DIR="${PROJECT_DIR}/ThirdParty/lcov"

# LCOV="$LCOV_EXE --gcov-tool=${GCOV} --rc lcov_branch_coverage=1"
LCOV="${LCOV_DIR}/bin/lcov --gcov-tool=${GCOV}" # no branch coverage

# collect raw data
if [ ! -e coverage.info ]; then
  $LCOV --directory `pwd` \
    --capture --output-file coverage.info
fi

# remove uninteresting entries
$LCOV --remove coverage.info "*/usr/*" --output-file coverage2.info
$LCOV --remove coverage2.info "*/ThirdParty/*" --output-file coverage3.info

# if [ $CI ]; then
#   # upload if on CI
#   curl -s https://codecov.io/bash | bash -s - -f coverage.info -X gcov -x $GCOV
# else
#   # otherwise just print
#   $LCOV_DIR/bin/genhtml coverage.info -o coverage-report
# fi

$LCOV_DIR/bin/genhtml coverage3.info -o coverage-report
