From b5ff80a541ee627985ed7057ee1240cc79b8c77f Mon Sep 17 00:00:00 2001 From: Guy Taylor Date: Thu, 21 Feb 2019 19:45:27 +0000 Subject: [PATCH] Rust lint and coverage on Travis --- .travis.yml | 71 +++++++++++++++++++++++++++++++++-------- .travis/install-kcov.sh | 29 +++++++++++++++++ .travis/run-kcov.sh | 15 +++++++++ 3 files changed, 102 insertions(+), 13 deletions(-) create mode 100755 .travis/install-kcov.sh create mode 100755 .travis/run-kcov.sh diff --git a/.travis.yml b/.travis.yml index f18b345..66c848f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,64 @@ -language: rust os: - linux - osx +dist: xenial +sudo: false +addons: + apt: + packages: + # necessary for kcov + - libcurl4-openssl-dev + - libelf-dev + - libdw-dev + - libiberty-dev + - binutils-dev + - cmake + - gcc + +language: rust rust: - stable - nightly -before_script: - - pip2 install 'travis-cargo<0.2' --user && export PATH=$HOME/Library/Python/2.7/bin:$HOME/.local/bin:$PATH -script: - - travis-cargo test - - travis-cargo build -- --manifest-path examples/drive_example/Cargo.toml - - travis-cargo build -- --manifest-path examples/service_account/Cargo.toml - - travis-cargo test -- --no-default-features --features no-openssl -after_success: - - "[[ $TRAVIS_OS_NAME = linux ]] && travis-cargo --only stable coveralls" -env: - global: - - TRAVIS_CARGO_NIGHTLY_FEATURE="" + +stages: + - name: test + - name: lint + - name: coverage + +install: true + +# Default script is the "test" stage +script: + - cargo build + - cargo test + - cargo build --manifest-path examples/drive_example/Cargo.toml + - cargo build --manifest-path examples/service_account/Cargo.toml + - cargo test --no-default-features --features no-openssl + +jobs: + include: + - stage: lint + if: os = linux + rust: stable + install: + - rustup component add clippy + - rustup component add rustfmt + script: + - cargo fmt --all -- --check || true + - cargo clippy --all-targets --all-features -- -D warnings || true + + - stage: coverage + if: os = linux + sudo: true + rust: stable + env: + - RUSTFLAGS="-C link-dead-code -C debuginfo=2 -C opt-level=0" + - CACHE_NAME="coverage" + install: + - ./.travis/install-kcov.sh "v36" "29ccdde3bd44f14e0d7c88d709e1e5ff9b448e735538ae45ee08b73c19a2ea0b" && export PATH="kcov/usr/bin:${PATH}"; + script: + - cargo test --no-run + - ./.travis/run-kcov.sh "yup_oauth2" + - bash <(curl -s https://codecov.io/bash) -F "${TRAVIS_RUST_VERSION}" + +cache: cargo diff --git a/.travis/install-kcov.sh b/.travis/install-kcov.sh new file mode 100755 index 0000000..eca8b0c --- /dev/null +++ b/.travis/install-kcov.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -o verbose +set -o errexit +set -o pipefail + +KCOV_VERSION="${1}" +KCOV_SHA256_HASH="${2}" + +curl -L --output "kcov.tar.gz" "https://github.com/SimonKagstrom/kcov/archive/${KCOV_VERSION}.tar.gz" +sha256sum "kcov.tar.gz" +echo "${KCOV_SHA256_HASH} kcov.tar.gz" | sha256sum -c + +mkdir kcov-src +mkdir kcov + +cd kcov-src +tar -xf ../kcov.tar.gz --strip-components=1 +rm ../kcov.tar.gz + +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr .. +make -j 2 +make install DESTDIR=../../kcov +cd ../../ +rm -r kcov-src + +echo "kcov should not be available via 'kcov/usr/bin/kcov'" diff --git a/.travis/run-kcov.sh b/.travis/run-kcov.sh new file mode 100755 index 0000000..260723c --- /dev/null +++ b/.travis/run-kcov.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -o verbose +set -o errexit +set -o pipefail + +PROGRAM_NAME="${1}" + +echo "Coverage testing of ${PROGRAM_NAME}" + +for file in target/debug/${PROGRAM_NAME}-*; do + [ -x "${file}" ] || continue + mkdir -p "target/cov/$(basename ${file})"; + kcov --exclude-pattern='/.cargo,/usr/lib' --verify "target/cov/$(basename ${file})" "${file}"; +done