Orgad Shaneh | 3d2fdd0 | 2018-12-19 11:23:55 +0200 | [diff] [blame] | 1 | #!/bin/bash |
Han-Wen Nienhuys | 23ed348 | 2017-05-10 10:04:24 +0200 | [diff] [blame] | 2 | # |
| 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 | |
| 10 | genhtml=$(which genhtml) |
| 11 | if [[ -z "${genhtml}" ]]; then |
| 12 | echo "Install 'genhtml' (contained in the 'lcov' package)" |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | destdir="$1" |
| 17 | if [[ -z "${destdir}" ]]; then |
| 18 | destdir=$(mktemp -d /tmp/gerritcov.XXXXXX) |
| 19 | fi |
| 20 | |
| 21 | echo "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 Kempin | e3a400e | 2019-03-28 09:42:55 +0100 | [diff] [blame] | 25 | bazel coverage -k --jobs=${COVERAGE_CPUS:-2} -- ... |
Han-Wen Nienhuys | 23ed348 | 2017-05-10 10:04:24 +0200 | [diff] [blame] | 26 | |
| 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 Kempin | 3a69e82 | 2019-03-28 12:07:41 +0100 | [diff] [blame] | 32 | mkdir -p ${destdir}/java |
| 33 | cp -r {java,javatests}/* ${destdir}/java |
| 34 | |
| 35 | mkdir -p ${destdir}/plugins |
| 36 | for plugin in `find plugins/ -type d` -maxdepth 1 |
| 37 | do |
| 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 |
| 45 | done |
Han-Wen Nienhuys | 23ed348 | 2017-05-10 10:04:24 +0200 | [diff] [blame] | 46 | |
| 47 | base=$(bazel info bazel-testlogs) |
| 48 | for f in $(find ${base} -name 'coverage.dat') ; do |
| 49 | cp $f ${destdir}/$(echo $f| sed "s|${base}/||" | sed "s|/|_|g") |
| 50 | done |
| 51 | |
| 52 | cd ${destdir} |
| 53 | find -name '*coverage.dat' -size 0 -delete |
| 54 | |
| 55 | genhtml -o . --ignore-errors source *coverage.dat |
| 56 | |
| 57 | echo "coverage report at file://${destdir}/index.html" |