mirror of
https://gitlab.com/spaceti-app/integrations/common/server-sdk.git
synced 2026-07-12 14:50:48 +02:00
107 lines
2.8 KiB
Bash
Executable File
107 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
source $CURRENT_DIR/common.sh
|
|
|
|
SOURCE_DIR=$PWD
|
|
|
|
BUILDPATH=$SOURCE_DIR"/build/testcc"
|
|
COVERAGE_DIR=$SOURCE_DIR"/build/testcc-info"
|
|
HTML_RESULTS_DIR=$SOURCE_DIR"/build/testcc-html"
|
|
COVERAGE_FILTER="*Qt*.framework* *Xcode.app* *.moc *moc_*.cpp */test/* *qrc_* ui_* *qt.headers */build/* *main*.* *c++*"
|
|
|
|
info "Getting .pro file"
|
|
PRO_FILE=$(ls *.pro)
|
|
|
|
# Ensuring server-sdk wont be filtered out for server-sdk
|
|
NAME=$( basename $PWD )
|
|
if [ "$NAME" != "serversdk" ]; then
|
|
COVERAGE_FILTER+=" *serversdk*"
|
|
fi
|
|
|
|
# Ensuring 'src' dir exists
|
|
if [ ! -d src ]; then
|
|
fail "'src' dir does not exists. ${BLUE}Expecting 'src' dir with c++ source code${NC}"
|
|
else
|
|
pass "src dir exits"
|
|
fi
|
|
|
|
# Ensuring PRO_FILE exists
|
|
if [ ! -f $PRO_FILE ]; then
|
|
fail ".pro file does not exists: " $PRO_FILE
|
|
else
|
|
pass ".pro file: " $PRO_FILE
|
|
fi
|
|
|
|
|
|
|
|
if [ -d $BUILDPATH ]; then info "Removing build path: $BUILDPATH"; rm -rf $BUILDPATH; fi
|
|
info "Creating: $BUILDPATH"
|
|
mkdir -p $BUILDPATH
|
|
cd $BUILDPATH
|
|
|
|
info "Generate makefile with coverage option"
|
|
qmake $SOURCE_DIR/$PRO_FILE "QMAKE_CXXFLAGS += --coverage" "QMAKE_LFLAGS += --coverage"
|
|
|
|
info "Remove previous *.gcda files"
|
|
find $BUILDPATH -name *.gcda -exec rm "{}" \;
|
|
|
|
info "Build"
|
|
make -j4 # build
|
|
|
|
info "Run unittests"
|
|
make check
|
|
|
|
|
|
echo "--------------------"
|
|
echo "Source : $SRCDIR"
|
|
echo "Build : $BUILDPATH"
|
|
echo "Makeflags : $MAKEFLAGS"
|
|
echo "COVERAGE_DIR : $COVERAGE_DIR"
|
|
echo "SOURCE_DIR : $SOURCE_DIR"
|
|
echo "HTML_RESULTS_DIR : $HTML_RESULTS_DIR"
|
|
echo "COVERAGE_FILTER : $COVERAGE_FILTER"
|
|
echo "--------------------"
|
|
|
|
#exit 0
|
|
|
|
info "Create dummy files to ensure not tested class are acounted"
|
|
find $BUILDPATH -name "*.gcno" -exec sh -c 'touch -a "${1%.gcno}.gcda"' _ {} \;
|
|
mkdir -p $COVERAGE_DIR
|
|
|
|
info "Make dir 'codecoverage' clean"
|
|
rm -f $COVERAGE_DIR/*.*
|
|
rm -rf $HTML_RESULTS_DIR
|
|
|
|
|
|
info "Copy .gc?? file from $BUILDPATH into 'codecoverage' dir"
|
|
find $BUILDPATH -name *.gc?? -exec cp "{}" $COVERAGE_DIR \;
|
|
|
|
|
|
##########################
|
|
# RUN LCOV
|
|
##########################
|
|
|
|
# ${1} is the directory containing the .gcno files (%{PROJBUILD} in Qt Creator)
|
|
LCOV=lcov
|
|
GENHTML=genhtml
|
|
BROWSER="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
|
|
info "Generating initial code coverage info report"
|
|
cd $BUILDPATH
|
|
${LCOV} -d ${BUILDPATH} -c -o ${COVERAGE_DIR}/coverage.info
|
|
|
|
info "Filtering code coverage info report"
|
|
${LCOV} -r ${COVERAGE_DIR}/coverage.info $COVERAGE_FILTER -o ${COVERAGE_DIR}/coverage-filtered.info
|
|
|
|
info "Creating html output"
|
|
mkdir -p ${HTML_RESULTS_DIR}
|
|
cd $BUILDPATH
|
|
"${GENHTML}" -o "${HTML_RESULTS_DIR}" "${COVERAGE_DIR}/coverage-filtered.info"
|
|
|
|
info "Reseting coverage counts"
|
|
"${LCOV}" -d "${COVERAGE_DIR}" -z
|
|
|
|
if [ "$1" == "open" ]; then
|
|
open "${HTML_RESULTS_DIR}/index.html" &
|
|
fi
|