blob: 11e50e62f93f63ee255ca5a3ab431782effe4330 [file] [log] [blame]
Orgad Shaneh3d2fdd02018-12-19 11:23:55 +02001#!/bin/bash
Han-Wen Nienhuys23ed3482017-05-10 10:04:24 +02002#
3# Usage
4#
5# COVERAGE_CPUS=32 tools/coverage.sh [/path/to/report-directory/]
6#
7# COVERAGE_CPUS defaults to 2, and the default destination is a temp
8# dir.
9
10genhtml=$(which genhtml)
11if [[ -z "${genhtml}" ]]; then
12 echo "Install 'genhtml' (contained in the 'lcov' package)"
13 exit 1
14fi
15
16destdir="$1"
17if [[ -z "${destdir}" ]]; then
18 destdir=$(mktemp -d /tmp/gerritcov.XXXXXX)
19fi
20
21echo "Running 'bazel coverage'; this may take a while"
22
23# coverage is expensive to run; use --jobs=2 to avoid overloading the
24# machine.
Edwin Kempine3a400e2019-03-28 09:42:55 +010025bazel coverage -k --jobs=${COVERAGE_CPUS:-2} -- ...
Han-Wen Nienhuys23ed3482017-05-10 10:04:24 +020026
27# The coverage data contains filenames relative to the Java root, and
28# genhtml has no logic to search these elsewhere. Workaround this
29# limitation by running genhtml in a directory with the files in the
30# right place. Also -inexplicably- genhtml wants to have the source
31# files relative to the output directory.
Edwin Kempin3a69e822019-03-28 12:07:41 +010032mkdir -p ${destdir}/java
33cp -r {java,javatests}/* ${destdir}/java
34
35mkdir -p ${destdir}/plugins
36for plugin in `find plugins/ -type d` -maxdepth 1
37do
38 mkdir -p ${destdir}/${plugin}/java
39 cp -r plugins/*/{java,javatests}/* ${destdir}/${plugin}/java
40
41 # for backwards compatibility support plugins with old file structure
42 mkdir -p ${destdir}/${plugin}/src/{main,test}/java
43 cp -r plugins/*/src/main/java/* ${destdir}/${plugin}/src/main/java
44 cp -r plugins/*/src/test/java/* ${destdir}/${plugin}/src/test/java
45done
Han-Wen Nienhuys23ed3482017-05-10 10:04:24 +020046
47base=$(bazel info bazel-testlogs)
48for f in $(find ${base} -name 'coverage.dat') ; do
49 cp $f ${destdir}/$(echo $f| sed "s|${base}/||" | sed "s|/|_|g")
50done
51
52cd ${destdir}
53find -name '*coverage.dat' -size 0 -delete
54
55genhtml -o . --ignore-errors source *coverage.dat
56
57echo "coverage report at file://${destdir}/index.html"