|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright Hans Dembinski 2018-2019 |
| 4 | +# Distributed under the Boost Software License, Version 1.0. |
| 5 | +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt |
| 6 | + |
| 7 | +# script must be executed in project root folder |
| 8 | + |
| 9 | +# NOTE: compute coverage with b2 toolset=gcc-8 cxxstd=latest coverage=on test//all |
| 10 | +# - computing coverage only works properly with gcc-8 right now |
| 11 | +# - gcc-9 and gcc-10 are extremely slow |
| 12 | +# - clang-10 works and is fast but misses a lot of unmissable lines |
| 13 | + |
| 14 | +from subprocess import run |
| 15 | +from pathlib import Path |
| 16 | +import os |
| 17 | +import sys |
| 18 | + |
| 19 | +LCOV_VERSION = "1.15" |
| 20 | + |
| 21 | +gcov = os.environ.get("GCOV", "gcov-8") |
| 22 | + |
| 23 | +gcov_version = gcov.split("-")[1] if "-" in gcov else None |
| 24 | +gcc_version = f"gcc-{gcov_version}" if gcov_version else "gcc" |
| 25 | + |
| 26 | +lcov_dir = Path("tools") / f"lcov-{LCOV_VERSION}" |
| 27 | + |
| 28 | +if not lcov_dir.exists(): |
| 29 | + url = ( |
| 30 | + "https://github.com/linux-test-project/lcov/releases/download/" |
| 31 | + + f"v{LCOV_VERSION}/lcov-{LCOV_VERSION}.tar.gz" |
| 32 | + ) |
| 33 | + run(f"curl -L {url} | tar zxf -", shell=True, cwd="tools") |
| 34 | + |
| 35 | +# --rc lcov_branch_coverage=1 doesn't work on travis |
| 36 | +lcov = [ |
| 37 | + f"{lcov_dir}/bin/lcov", |
| 38 | + f"--gcov-tool={gcov}", |
| 39 | + "--output-file", |
| 40 | + "coverage.info", |
| 41 | +] |
| 42 | +# get all directories with gcda files that match the gcov version |
| 43 | +cwd = Path().absolute() |
| 44 | +lcov_collect = lcov + ["--base-directory", cwd, "--capture"] |
| 45 | +for p in Path("../../bin.v2/libs/histogram/test").rglob("**/*.gcda"): |
| 46 | + if gcc_version not in str(p): |
| 47 | + continue |
| 48 | + lcov_collect.append("--directory") |
| 49 | + lcov_collect.append(p.parent) |
| 50 | +run(lcov_collect) |
| 51 | + |
| 52 | +# remove uninteresting entries |
| 53 | +run(lcov + ["--extract", "coverage.info", "*/boost/histogram/*"]) |
| 54 | + |
| 55 | +args = sys.argv[1:] |
| 56 | +if args: |
| 57 | + # upload if token is passed as argument, you need to install cpp-coveralls |
| 58 | + run(["cpp-coveralls", "-l", "coverage.info", "-r", "../..", "-n", "-t", args[0]]) |
| 59 | +else: |
| 60 | + # otherwise generate html report |
| 61 | + run( |
| 62 | + [ |
| 63 | + f"{lcov_dir}/bin/genhtml", |
| 64 | + "coverage.info", |
| 65 | + "--demangle-cpp", |
| 66 | + "-o", |
| 67 | + "coverage-report", |
| 68 | + ] |
| 69 | + ) |
0 commit comments