Skip to content

Commit

Permalink
getcov: Pull body of script into main function
Browse files Browse the repository at this point in the history
  • Loading branch information
jonreid committed Mar 21, 2015
1 parent 05e309b commit bcb2d66
Showing 1 changed file with 85 additions and 66 deletions.
151 changes: 85 additions & 66 deletions getcov
Expand Up @@ -6,6 +6,71 @@ usage() {
echo "usage: getcov [[[-o output_directory] [-i info_file] [-v]] | [-h]]"
}

main() {
scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${scripts}/envcov.sh"

LCOV_INFO=Coverage.info
OUT_DIR="${BUILT_PRODUCTS_DIR}"
while [ "$1" != "" ]; do
case $1 in
-o)
shift
OUT_DIR=$1
echo "OUT_DIR = ${OUT_DIR}"
;;
-i)
shift
LCOV_INFO=$1
echo "LCOV_INFO = ${LCOV_INFO}"
;;
-v)
verbose=1
echo "Verbose"
;;
-s|--show)
show_report=1
echo "Show Report"
;;
-h|--help)
usage
echo "Show Help"
exit
;;
*)
usage
exit 1
esac
shift
done

if [ "$verbose" = "1" ]; then
report_values
fi

remove_old_report
enter_lcov_dir
gather_coverage
exclude_data
generate_cobertura_xml
generate_html_report

if [ "$show_report" = "1" ]; then
show_html_report
fi
}

report_values() {
echo "XcodeCoverage: Environment"
echo "scripts : ${scripts}"
echo "LCOV_INFO : ${LCOV_INFO}"
echo "BUILD_DIR : ${BUILT_PRODUCTS_DIR}"
echo "SRCROOT : ${SRCROOT}"
echo "OBJ_DIR : ${OBJ_DIR}"
echo "LCOV_PATH : ${LCOV_PATH}"
echo "OUT_DIR : ${OUT_DIR}"
}

remove_old_report() {
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Removing old report"
Expand All @@ -25,91 +90,45 @@ enter_lcov_dir() {
}

gather_coverage() {
if [ "$verbose" = "1" ]; then
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Gathering coverage"
fi

LCOV --capture --derive-func-data -b "${SRCROOT}" -d "${OBJ_DIR}" -o "${LCOV_INFO}"
}

exclude_data() {
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Excluding data"
fi

LCOV --remove "${LCOV_INFO}" "Developer/SDKs/*" -d "${OBJ_DIR}" -o "${LCOV_INFO}"
LCOV --remove "${LCOV_INFO}" "main.m" -d "${OBJ_DIR}" -o "${LCOV_INFO}"
# Remove other patterns here...
LCOV --remove "${LCOV_INFO}" "include/*" -d "${OBJ_DIR}" -o "${LCOV_INFO}"
LCOV --remove "${LCOV_INFO}" "Classes/External/*" -d "${OBJ_DIR}" -o "${LCOV_INFO}"
}

generate_cobertura_xml() {
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Generating Cobertura XML"
fi

python "${scripts}/lcov_cobertura.py" ${LCOV_INFO} --base-dir "${SRCROOT}" --output "coverage.xml"
}

generate_report() {
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Generating report"
generate_html_report() {
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Generating HTML report"
fi

"${LCOV_PATH}/genhtml" --output-directory . "${LCOV_INFO}"

if [ "$show_report" = "1" ]; then
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Opening report"
fi
open index.html
}

show_html_report() {
if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Opening HTML report"
fi

open index.html
}

scripts="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${scripts}/envcov.sh"

LCOV_INFO=Coverage.info
OUT_DIR="${BUILT_PRODUCTS_DIR}"
while [ "$1" != "" ]; do
case $1 in
-o)
shift
OUT_DIR=$1
echo "OUT_DIR = ${OUT_DIR}"
;;
-i)
shift
LCOV_INFO=$1
echo "LCOV_INFO = ${LCOV_INFO}"
;;
-v)
verbose=1
echo "Verbose"
;;
-s | --show )
show_report=1
echo "Show Report"
;;
-h | --help )
usage
echo "Show Help"
exit
;;
*)
usage
exit 1
esac
shift
done

if [ "$verbose" = "1" ]; then
echo "XcodeCoverage: Environment"
echo "scripts : ${scripts}"
echo "LCOV_INFO : ${LCOV_INFO}"
echo "BUILD_DIR : ${BUILT_PRODUCTS_DIR}"
echo "SRCROOT : ${SRCROOT}"
echo "OBJ_DIR : ${OBJ_DIR}"
echo "LCOV_PATH : ${LCOV_PATH}"
echo "OUT_DIR : ${OUT_DIR}"
fi

remove_old_report
enter_lcov_dir
gather_coverage
exclude_data
generate_cobertura_xml
generate_report
main "$@"

0 comments on commit bcb2d66

Please sign in to comment.