Skip to content

Commit

Permalink
Travis -> Coveralls
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed Apr 14, 2020
1 parent b73c9cc commit 35dae74
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 4 deletions.
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@ before_install:
- if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -qq bison comerr-dev flex libcap-ng-dev libdb-dev libedit-dev libjson-perl libldap2-dev libncurses5-dev libperl4-corelibs-perl libsqlite3-dev libkeyutils-dev pkg-config python ss-dev texinfo unzip netbase keyutils; fi
- if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -qq ldap-utils gdb; fi
- if [ $TRAVIS_OS_NAME = linux ]; then sudo apt-get install -qq libmicrohttpd-dev; fi
- if [ $TRAVIS_OS_NAME = linux -a -n "$COVERAGE" ]; then sudo apt-get install -qq jq; fi
- if [ $TRAVIS_OS_NAME = osx ]; then brew update; fi
- if [ $TRAVIS_OS_NAME = osx ]; then brew install cpanm bison flex berkeley-db lmdb openldap openssl; fi
- if [ $TRAVIS_OS_NAME = osx ]; then sudo cpanm install JSON; fi
- if [ $TRAVIS_OS_NAME = osx -a -n "$COVERAGE" ]; then brew install jq; fi
- mkdir ci-build
- mkdir coverity-build
- ./autogen.sh

install:
- cd ci-build
- if [ -n "$COVERAGE" ]; then pip install --user cpp-coveralls; fi
- |
if [ $TRAVIS_OS_NAME = osx ]; then
LDFLAGS="-L/usr/local/opt/berkeley-db/lib -L/usr/local/opt/lmdb/lib" \
CFLAGS="-I/usr/local/opt/lmdb/include" \
../configure --prefix=/tmp/heimdal \
../configure \
--srcdir=`dirname "$PWD"` \
--prefix=/tmp/heimdal \
--enable-maintainer-mode $COVERAGE \
--enable-static=no \
--enable-pthread-support \
--disable-afs-support \
Expand All @@ -38,15 +42,20 @@ install:
--with-berkeley-db \
--with-berkeley-db-include=/usr/local/opt/berkeley-db/include
else
../configure --enable-maintainer-mode $COVERAGE
../configure --srcdir=`dirname "$PWD"` --enable-maintainer-mode $COVERAGE
fi
- ulimit -c unlimited; make -j3

script:
- if [ x${COVERITY_SCAN_BRANCH} != x1 ]; then ulimit -c unlimited; make check; fi

after_script:
- if [ -n "$COVERAGE" ]; then coveralls --gcov-options '\-lp'; fi
- |
if [ -n "$COVERAGE" ]; then
../tools/coveralls-tool -v -o cov.json -O $PWD -S ..
jq -C . cov.json|head -100
curl -X POST -d @cov.json https://coveralls.io/api/v1/jobs
fi
after_failure:
- find . -name test-suite.log -print0 | xargs -0 cat
Expand Down
163 changes: 163 additions & 0 deletions tools/coveralls-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/bin/bash

set -euo pipefail
set +o noglob

PROG=${0##*/}

job=${TRAVIS_JOB_ID:-}
out=
repo=
srcdir=$PWD
objdir=
token=${COVERALLS_REPO_TOKEN:-}
verbose=0

function usage {
cat <<EOF
Usage: $PROG [OPTIONS]
Usage: $PROG [-o FILE] [-S SRCDIR] [-O OBJDIR] [-R URI] [-t TOKEN] [-v] [-x]
Options:
-v Verbose (on stderr).
-x Trace $PROG
-o FILE Output to FILE instead of stdout.
-t TOKEN Token for Coveralls (defaults to
\$COVERALLS_REPO_TOKEN)
-J ID Job ID (e.g., Travis-CI job ID)
-S SRCDIR Path to clone (defaults to \$PWD)
-O OBJDIR Path to object directory (defaults to SRCDIR)
-R URI Repository URI (defaults to origin URI
for SRCDIR)
$PROG will look for .gcda files in OBJDIR for source files
in the clone at SRCDIR and will run gcov on them, and produce
a request body as JSON in FILE (or stdout if -o FILE not given)
for Coveralls.
Only C and C++ source files are reported on. E.g., Yacc/Bison/Flex
source files are not reported.
EOF
}

while getopts +:J:O:R:S:ho:t:vx opt; do
case "$opt" in
J) job=$OPTARG;;
O) cd "$OPTARG"; objdir=$PWD; cd "$OLDPWD";;
R) repo=$OPTARG;;
S) cd "$OPTARG"; srcdir=$PWD; cd "$OLDPWD";;
h) usage 0;;
o) out=$OPTARG;;
t) token=$OPTARG;;
v) ((verbose++)) || true;;
x) set -vx;;
*) usage 1;;
esac
done

# Note: we don't cd to $srcdir or $objdir or anywhere, so if $out is a relative
# path, we do the right thing.

: ${objdir:=${srcdir}}
: ${repo:=$(cd "$srcdir"; git remote get-url origin)}

if ((verbose > 1)); then
exec 3>&2
else
exec 3>/dev/null
fi

d=
function cleanup {
[[ -n $d ]] && rm -rf "$d"
}

trap cleanup EXIT
d=$(mktemp -d)
touch "${d}/f"

function find_and_mv_gcda {
local dir=${1%/*}
local base=${1##*/}
local best_gcda=${objdir}/${dir}/${base%.*}.gcda
local gcda
local -a gcdas=(
$best_gcda
${objdir}/${dir}/.libs/${base%.*}.gcda
)
for gcda in "${gcdas[@]}"; do
[[ -f $gcda ]] || continue
[[ $gcda = $best_gcda ]] && continue
if [[ -f $best_gcda && $gcda != $best_gcda && $gcda -nt $best_gcda ]]; then
mv "$gcda" "$best_gcda"
elif [[ ! -f $best_gcda ]]; then
mv -f "$gcda" "$best_gcda"
elif [[ $gcda -nt $best_gcda ]]; then
mv -f "$gcda" "$best_gcda"
else
rm -f "$gcda"
fi
done
[[ -f ${best_gcda} ]] || return 1
}

declare -a gcov

(cd "$srcdir" && git ls-files -- '*.c' '*.cpp') |
while read f; do
# Remember to be careful to refer to ${srcdir}/${f}
((verbose)) && printf 'Processing: %s\n' "$f" 1>&2

# If we don't have a gcda file, we don't have coverage.
find_and_mv_gcda "$f" || continue

# Run gcov, which will produce not-always-correctly-named .gcov files (see
# below).
if (cd "${objdir}/${f%/*}"; ((verbose > 1)) && set -vx; gcov "${f##*/}") 1>&3; then
true
else
printf 'Warning: gcov failed for %s\n' "$f" 1>&2
continue
fi
md5=$(md5sum "${srcdir}/${f}")

# Glob to find the gcov file. Unfortunately because of the recursive
# makefile design of Heimdal's build gcov often ends up using the wrong
# path to construct the .gcov files, so we just glob for them.
#
# We could read all gcov files we can find and extract the path to the
# source from the .gcno/.gcda files named therein, and for each file pick
# the latest.
gcov=()
for i in ${objdir}/${f}.gcov ${objdir}/${f%.*}.gcno*gcov; do
[[ -f $i ]] || continue
gcov+=($i)
break
done
if ((${#gcov[@]} == 0)); then
printf 'Warning: no gcov file found for %s\n' "$f" 1>&2
continue
fi

jq -Rn --arg sum "$md5" --arg f "$f" '
{
name: $f,
source_digest: $sum,
coverage: [
inputs
| split(":")
| (.[1] |= tonumber)
| select(.[1] > 0)
| if .[0]|endswith("#")
then 0
elif .[0]|endswith("-")
then null
else .[0]|tonumber
end
]
}
' "${gcov[0]}" >> "${d}/f"
done

[[ -n $out ]] && exec 1>"$out"
jq --arg job "$job" -s '{service_job_id: $job, service_name: "travis-ci", source_files: .}' "${d}/f"
18 changes: 18 additions & 0 deletions tools/fixgcov-source-paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

find ${1:-.} -name '*.gcov' -print | while read f; do
case "$f" in
*/.libs/*) continue;;
*) true;;
esac
echo FIX $f
f_basename=${f%%.gcno\#\#*}.c
f_basename=${f_basename##*/}
head -1 "$f" | grep 'Source:/' > /dev/null && continue
#bname=$(head -1 "$f" | grep 'Source:/' | cut -d: -f4)
dname=$(echo "$f"|cut -d'#' -f1|sed -e 's,/[^/]*$,/,')
ex "$f" <<EOF
1,1 s,:Source:.*$,:Source:${dname}${f_basename},
wq!
EOF
done

0 comments on commit 35dae74

Please sign in to comment.