From 79fab52b32f498c9a3939a6a283996833cc4c897 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Fri, 7 May 2021 17:32:04 +0200 Subject: [PATCH] update to lcov-1.15 and update to less brittle python script (#325) --- .github/workflows/cov.yml | 3 +- tools/cov.py | 69 +++++++++++++++++++++++++++++++++++++++ tools/cov.sh | 46 -------------------------- 3 files changed, 70 insertions(+), 48 deletions(-) create mode 100755 tools/cov.py delete mode 100755 tools/cov.sh diff --git a/.github/workflows/cov.yml b/.github/workflows/cov.yml index cb3e27e9..3ae9d58b 100644 --- a/.github/workflows/cov.yml +++ b/.github/workflows/cov.yml @@ -8,7 +8,6 @@ on: paths-ignore: - 'doc/**' - 'examples/**' - - 'tools/**' - '*.md' env: @@ -55,7 +54,7 @@ jobs: - name: Process coverage data run: | cd libs/histogram - GCOV=gcov-8 tools/cov.sh + GCOV=gcov-8 tools/cov.py - uses: coverallsapp/github-action@v1.1.2 with: diff --git a/tools/cov.py b/tools/cov.py new file mode 100755 index 00000000..293417ae --- /dev/null +++ b/tools/cov.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +# Copyright Hans Dembinski 2018-2019 +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt + +# script must be executed in project root folder + +# NOTE: compute coverage with b2 toolset=gcc-8 cxxstd=latest coverage=on test//all +# - computing coverage only works properly with gcc-8 right now +# - gcc-9 and gcc-10 are extremely slow +# - clang-10 works and is fast but misses a lot of unmissable lines + +from subprocess import run +from pathlib import Path +import os +import sys + +LCOV_VERSION = "1.15" + +gcov = os.environ.get("GCOV", "gcov-8") + +gcov_version = gcov.split("-")[1] if "-" in gcov else None +gcc_version = f"gcc-{gcov_version}" if gcov_version else "gcc" + +lcov_dir = Path("tools") / f"lcov-{LCOV_VERSION}" + +if not lcov_dir.exists(): + url = ( + "https://github.com/linux-test-project/lcov/releases/download/" + + f"v{LCOV_VERSION}/lcov-{LCOV_VERSION}.tar.gz" + ) + run(f"curl -L {url} | tar zxf -", shell=True, cwd="tools") + +# --rc lcov_branch_coverage=1 doesn't work on travis +lcov = [ + f"{lcov_dir}/bin/lcov", + f"--gcov-tool={gcov}", + "--output-file", + "coverage.info", +] +# get all directories with gcda files that match the gcov version +cwd = Path().absolute() +lcov_collect = lcov + ["--base-directory", cwd, "--capture"] +for p in Path("../../bin.v2/libs/histogram/test").rglob("**/*.gcda"): + if gcc_version not in str(p): + continue + lcov_collect.append("--directory") + lcov_collect.append(p.parent) +run(lcov_collect) + +# remove uninteresting entries +run(lcov + ["--extract", "coverage.info", "*/boost/histogram/*"]) + +args = sys.argv[1:] +if args: + # upload if token is passed as argument, you need to install cpp-coveralls + run(["cpp-coveralls", "-l", "coverage.info", "-r", "../..", "-n", "-t", args[0]]) +else: + # otherwise generate html report + run( + [ + f"{lcov_dir}/bin/genhtml", + "coverage.info", + "--demangle-cpp", + "-o", + "coverage-report", + ] + ) diff --git a/tools/cov.sh b/tools/cov.sh deleted file mode 100755 index 4cfe591e..00000000 --- a/tools/cov.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh -# must be executed in project root folder - -# Copyright Hans Dembinski 2018-2019 -# Distributed under the Boost Software License, Version 1.0. -# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt - -if [ -z $GCOV ]; then - # gcov-10, gcov-9, gcov-7, gcov-6 do not work - for i in 8 5; do - if test $(which gcov-$i); then - GCOV=gcov-$i - break; - fi; - done -fi - -LCOV_VERSION="1.14" -LCOV_DIR="tools/lcov-${LCOV_VERSION}" - -if [ ! -e $LCOV_DIR ]; then - cd tools - curl -L https://github.com/linux-test-project/lcov/releases/download/v${LCOV_VERSION}/lcov-${LCOV_VERSION}.tar.gz | tar zxf - - cd .. -fi - -# --rc lcov_branch_coverage=1 doesn't work on travis -# LCOV="${LCOV_DIR}/bin/lcov --gcov-tool=${GCOV} --rc lcov_branch_coverage=1" -LCOV="${LCOV_DIR}/bin/lcov --gcov-tool=${GCOV}" - -# collect raw data -$LCOV --base-directory `pwd` \ - --directory `pwd`/../../bin.v2/libs/histogram/test \ - --capture --output-file coverage.info - -# remove uninteresting entries -$LCOV --extract coverage.info "*/boost/histogram/*" --output-file coverage.info - -if [ $1 ]; then - # upload if on CI or when token is passed as argument - which cpp-coveralls || echo "Error: you need to install cpp-coveralls" - cpp-coveralls -l coverage.info -r ../.. -n -t $1 -elif [ ! $CI ]; then - # otherwise generate html report - $LCOV_DIR/bin/genhtml coverage.info --demangle-cpp -o coverage-report -fi