Skip to content

Commit

Permalink
tooling: use lcov instead of llvm-cov as default compiler is gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
danctorres committed Jan 5, 2025
1 parent 47a4cad commit e7eac16
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on: # yamllint disable-line rule:truthy
branches: ['*']

jobs:
llvm-cov:
lcov:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand All @@ -16,5 +16,5 @@ jobs:
uses: actions/checkout@v4

- name: Run Coverage Script
run: bazelisk run //tools/coverage:llvm_cov --platforms=//bazel/platforms:x86_64_linux -- -t //examples/cpp:test -s
run: bazelisk run //tools/coverage:lcov --platforms=//bazel/platforms:x86_64_linux -- -t //examples/cpp:test
shell: bash
5 changes: 5 additions & 0 deletions tools/coverage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ sh_binary(
name = "llvm_cov",
srcs = ["llvm_cov.sh"],
)

sh_binary(
name = "lcov",
srcs = ["lcov.sh"],
)
58 changes: 58 additions & 0 deletions tools/coverage/lcov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

set -e

usage() {
echo " -t BAZEL_TESTS The test target (e.g., //path/to/test-target)"
echo " -o OUTPUT_DIR Directory for output (default is temp directory)"
echo " -h Display this help message"
}

while getopts "t:o:h" option; do
case "${option}" in
t) BAZEL_TESTS=${OPTARG} ;;
o) OUTPUT_DIR=${OPTARG} ;;
h | *)
usage
exit 1
;;
esac
done

if [[ -z "${BAZEL_TESTS}" ]]; then
echo "ERROR: Missing required arguments."
usage
exit 1
fi

OUTPUT_DIR="${OUTPUT_DIR:-"$(mktemp -d)/cov_report"}"

echo "INFO: Tests target: ${BAZEL_TESTS}"
echo "INFO: Output directory: ${OUTPUT_DIR}"

readonly WORKSPACE=$(cd "$(dirname "$(readlink -f "${0}")")" && bazel info workspace)

function run_coverage_tests() {
echo -e "\nINFO: Run test targets\n"
bazel coverage \
--nocache_test_results \
--experimental_fetch_all_coverage_outputs \
--experimental_split_coverage_postprocessing \
--strategy=CoverageReport=local \
--combined_report=lcov \
-- ${BAZEL_TESTS}
}

function calculate_coverage() {
echo -e "\nINFO: Generating HTML coverage report\n"
genhtml --branch-coverage --output genhtml "$(bazel info output_path)/_coverage/_coverage_report.dat"
}

function main() {
pushd "${WORKSPACE}" || return
run_coverage_tests
calculate_coverage
popd || return
}

main

0 comments on commit e7eac16

Please sign in to comment.