Skip to content

Commit

Permalink
Attempt #2 to fix code coverage with kcov
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonozias committed Feb 9, 2021
1 parent 5078fc9 commit 352b69b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 23 deletions.
44 changes: 21 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
dist: trusty
language: rust

rust:
- stable
- beta
- nightly

os:
- linux
sudo: true

addons:
apt:
Expand All @@ -19,19 +13,23 @@ addons:
- binutils-dev
- libiberty-dev

script: "./scripts/run-tests.sh"
rust:
- stable
- beta
- nightly

os:
- linux

install:
- rustc -Vv
- cargo -Vv

# Install kcov.
- mkdir -p ~/.cargo/bin
- sh src/install_kcov.sh
- export PATH=$HOME/.local/bin:$HOME/.cargo/bin:$HOME/Library/Python/2.7/bin:$PATH
- export RUSTFLAGS="-C link-dead-code"
- kcov --version

after_success: |
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz &&
cd kcov-master &&
mkdir build &&
cd build &&
cmake .. &&
make &&
make install DESTDIR=../../kcov-build &&
cd ../.. &&
rm -rf kcov-master &&
for file in target/debug/build/vergen-*[^\.d]; do mkdir -p "target/cov/$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; done &&
bash <(curl -s https://codecov.io/bash) &&
echo "Uploaded code coverage"
script: "./scripts/run-tests.sh"
50 changes: 50 additions & 0 deletions scripts/install-kcov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh
set -eu

command_exists() {
command -v $1 &> /dev/null
}

CARGO_HOME=${CARGO_HOME:-${HOME}/.cargo}
KCOV_DEFAULT_VERSION="v37"
GITHUB_KCOV="https://api.github.com/repos/SimonKagstrom/kcov/releases/latest"

# Usage: download and install the latest kcov version by default.
# Fall back to ${KCOV_DEFAULT_VERSION} from the kcov archive if the latest is unavailable.
KCOV_VERSION=$(curl --silent --show-error --fail ${GITHUB_KCOV} | jq -Mr .tag_name || echo)
KCOV_VERSION=${KCOV_VERSION:-$KCOV_DEFAULT_VERSION}

KCOV_TGZ="https://github.com/SimonKagstrom/kcov/archive/${KCOV_VERSION}.tar.gz"

rm -rf kcov-${KCOV_VERSION}/
mkdir kcov-${KCOV_VERSION}
curl -L --retry 3 "${KCOV_TGZ}" | tar xzvf - -C kcov-${KCOV_VERSION} --strip-components 1

num_proc=1
# If PARALLEL_BUILD environment variable is set then parallel build is enabled
if [ "${PARALLEL_BUILD:-}" != "" ]; then
# If PARALLEL_BUILD content is a number then use it as number of parallel jobs
if [ ! -z "${PARALLEL_BUILD##*[!0-9]*}" ]; then
num_proc=${PARALLEL_BUILD}
else
# Try to determine the number of available CPUs
if command_exists nproc; then
num_proc=$(nproc)
elif command_exists sysctl; then
num_proc=$(sysctl -n hw.ncpu)
fi
fi
fi

cd kcov-${KCOV_VERSION}
mkdir build
cd build
if [ "$(uname)" = Darwin ]; then
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -GXcode ..
xcodebuild -configuration Release
cp src/Release/kcov src/Release/libkcov_system_lib.so "${CARGO_HOME}/bin"
else
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make -j ${num_proc}
cp src/kcov src/libkcov_sowrapper.so "${CARGO_HOME}/bin"
fi

0 comments on commit 352b69b

Please sign in to comment.