You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by ri...@apache.org on 2026/09/12 07:23:15 UTC
(iggy) 01/01: cleanup
This is an automated email from the ASF dual-hosted git repository.
slbotbm pushed a commit to branch cpp-coverage
in repository https://gitbox.apache.org/repos/asf/iggy.git
commit dfccce86c5d5ea6d28df99e8dc4d0bbd0bfb0a02
Author: Rimuksh Kansal <ni...@gmail.com>
AuthorDate: Sat Sep 12 16:22:56 2026 +0900
cleanup
---
foreign/cpp/.bazelrc | 16 +--
foreign/cpp/BUILD.bazel | 6 +-
scripts/ci/coverage-baseline-affected.sh | 2 +-
scripts/ci/cpp-coverage.sh | 185 ++++++-------------------------
4 files changed, 37 insertions(+), 172 deletions(-)
diff --git a/foreign/cpp/.bazelrc b/foreign/cpp/.bazelrc
index eaa105597..880712c20 100644
--- a/foreign/cpp/.bazelrc
+++ b/foreign/cpp/.bazelrc
@@ -48,18 +48,4 @@ build:ci --config=release
build:ci --lockfile_mode=error
test:ci --lockfile_mode=error
-test:ci --test_summary=terse
-test:ci --test_arg=--gtest_brief=1
-
-# Self-contained coverage configuration.
-common:cpp-coverage --color=no
-common:cpp-coverage --curses=no
-common:cpp-coverage --announce_rc
-
-build:cpp-coverage --compilation_mode=dbg
-build:cpp-coverage --copt=-O0
-build:cpp-coverage --strip=never
-build:cpp-coverage --lockfile_mode=error
-
-test:cpp-coverage --test_summary=terse
-test:cpp-coverage --test_arg=--gtest_brief=1
+test:ci --test_summary=detailed
diff --git a/foreign/cpp/BUILD.bazel b/foreign/cpp/BUILD.bazel
index 9e93fdad7..ea6dffedd 100644
--- a/foreign/cpp/BUILD.bazel
+++ b/foreign/cpp/BUILD.bazel
@@ -60,7 +60,7 @@ genrule(
env -u PWD \
CARGO_TARGET_DIR="$$CARGO_TARGET_DIR" \
RUSTC="$$RUSTC" \
- "$$CARGO" build --quiet $$FLAGS
+ "$$CARGO" build $$FLAGS
cp "$$CARGO_TARGET_DIR/$$PROFILE/libiggy_cpp.a" "$$OUT_LIB"
@@ -129,9 +129,9 @@ cc_import(
static_library = ":libiggy_cpp.a",
)
-cc_library(
+cc_import(
name = "profiler_rt",
- srcs = ["libprofiler_builtins.a"],
+ static_library = ":libprofiler_builtins.a",
alwayslink = True,
)
diff --git a/scripts/ci/coverage-baseline-affected.sh b/scripts/ci/coverage-baseline-affected.sh
index e33ecec9c..b3c7b8492 100755
--- a/scripts/ci/coverage-baseline-affected.sh
+++ b/scripts/ci/coverage-baseline-affected.sh
@@ -82,7 +82,7 @@ for gate in "${GATES[@]}"; do
node) paths=(foreign/node) ;;
# The go job also runs the bdd/go suite with foreign/go in -coverpkg.
go) paths=(foreign/go bdd/go) ;;
- cpp) paths=(foreign/cpp bdd/cpp) ;;
+ cpp) paths=(foreign/cpp) ;;
*)
echo "coverage-gate: no pathspecs defined for gate '$gate'" >&2
exit 1
diff --git a/scripts/ci/cpp-coverage.sh b/scripts/ci/cpp-coverage.sh
index 42cd867d5..780116ca6 100755
--- a/scripts/ci/cpp-coverage.sh
+++ b/scripts/ci/cpp-coverage.sh
@@ -18,176 +18,55 @@
set -euo pipefail
-if [[ ! -f MODULE.bazel || ! -f BUILD.bazel ]]; then
- echo "cpp-coverage: must run with CWD set to foreign/cpp" >&2
- exit 2
-fi
-
-for tool in bazel cargo; do
- if ! command -v "$tool" >/dev/null 2>&1; then
- echo "cpp-coverage: required tool '$tool' not on PATH" >&2
- exit 2
- fi
-done
-
OUTPUT="${1:-../../reports/cpp-coverage.lcov}"
-OUTPUT_TMP="${OUTPUT}.tmp"
-REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
-TMP_DIR="$(pwd)/target/cpp-coverage-tmp"
-PROFRAW_DIR="$TMP_DIR/profraw"
-BUILD_PROFRAW_DIR="$TMP_DIR/build-profraw"
-PROFDATA="$TMP_DIR/cpp-shim.profdata"
+COVERAGE_DIR="$(pwd)/target/cpp-coverage"
+BUILD_PROFRAW_DIR="$COVERAGE_DIR/build"
+PROFDATA="$COVERAGE_DIR/shim.profdata"
CPP_RAW="$(pwd)/bazel-out/_coverage/_coverage_report.dat"
-SHIM_RAW="$TMP_DIR/rust-shim-raw.lcov"
-CPP_FILTERED="$TMP_DIR/cpp-coverage.lcov"
-SHIM_FILTERED="$TMP_DIR/rust-shim.lcov"
-mkdir -p "$PROFRAW_DIR" "$BUILD_PROFRAW_DIR" "$(dirname "$OUTPUT")"
-rm -f "$PROFRAW_DIR"/*.profraw "$BUILD_PROFRAW_DIR"/*.profraw \
- "$PROFDATA" "$CPP_FILTERED" "$SHIM_RAW" "$SHIM_FILTERED" "$OUTPUT_TMP"
+mkdir -p "$COVERAGE_DIR" "$BUILD_PROFRAW_DIR" "$(dirname "$OUTPUT")"
+rm -f "$COVERAGE_DIR"/*.profraw "$BUILD_PROFRAW_DIR"/*.profraw "$PROFDATA" "$OUTPUT"
-show_env_file="$TMP_DIR/show-env.sh"
-if ! cargo llvm-cov show-env --no-rustc-wrapper --sh >"$show_env_file"; then
- echo "cpp-coverage: 'cargo llvm-cov show-env' failed (see output above)" >&2
- exit 1
-fi
# shellcheck disable=SC1090
-source "$show_env_file"
-if [[ -z "${RUSTFLAGS:-}" ]]; then
- echo "cpp-coverage: cargo llvm-cov show-env did not export RUSTFLAGS" >&2
- exit 1
-fi
-export LLVM_PROFILE_FILE="$PROFRAW_DIR/cpp-%p-%m.profraw"
-
-llvm_bin_dir="$(rustc --print sysroot)/lib/rustlib/$(rustc -vV | sed -n 's/^host: //p')/bin"
-LLVM_COV="$llvm_bin_dir/llvm-cov"
-LLVM_PROFDATA="$llvm_bin_dir/llvm-profdata"
-if [[ ! -x "$LLVM_COV" || ! -x "$LLVM_PROFDATA" ]]; then
- echo "cpp-coverage: $LLVM_COV or $LLVM_PROFDATA missing;" >&2
- echo "cpp-coverage: install with 'rustup component add llvm-tools'" >&2
- exit 1
-fi
+source <(cargo llvm-cov show-env --no-rustc-wrapper --sh)
+export LLVM_PROFILE_FILE="$COVERAGE_DIR/%p-%m.profraw"
-BAZEL_FLAGS=(--config=cpp-coverage)
-COVERAGE_DEFINE="--define=iggy_cpp_coverage=1"
-TEST_QUERY='kind("cc_test rule", //...)'
-if ! TEST_TARGET_ROWS="$(
- bazel cquery "$TEST_QUERY" \
- "${BAZEL_FLAGS[@]}" \
- "$COVERAGE_DEFINE" \
- --output=starlark \
- '--starlark:expr="//" + target.label.package + ":" + target.label.name + "\t" + providers(target)["DefaultInfo"].files_to_run.executable.path'
-)"; then
- echo "cpp-coverage: failed to discover C++ test targets" >&2
- exit 1
-fi
-if [[ -z "$TEST_TARGET_ROWS" ]]; then
- echo "cpp-coverage: no C++ test targets found" >&2
- exit 1
-fi
+LLVM_BIN="$(rustc --print target-libdir)/../bin"
+LLVM_COV="$LLVM_BIN/llvm-cov"
+LLVM_PROFDATA="$LLVM_BIN/llvm-profdata"
-TEST_TARGETS=()
-TEST_OBJECTS=()
-while IFS=$'\t' read -r test_target test_object; do
- if [[ -z "$test_target" || -z "$test_object" ]]; then
- echo "cpp-coverage: invalid C++ test target entry: $test_target $test_object" >&2
- exit 1
- fi
- TEST_TARGETS+=("$test_target")
- TEST_OBJECTS+=("$(pwd)/$test_object")
-done <<<"$TEST_TARGET_ROWS"
-
-bazel coverage "${BAZEL_FLAGS[@]}" \
+bazel coverage \
+ --config=debug \
+ --lockfile_mode=error \
--combined_report=lcov \
'--instrumentation_filter=//:iggy-cpp' \
- --nocache_test_results \
- --strategy=CoverageReport=local \
--strategy=TestRunner=standalone \
- "$COVERAGE_DEFINE" \
- "--action_env=RUSTFLAGS=$RUSTFLAGS" \
- "--action_env=LLVM_PROFILE_FILE=$BUILD_PROFRAW_DIR/build-%p-%m.profraw" \
+ --define=iggy_cpp_coverage=1 \
+ --action_env=RUSTFLAGS \
+ "--action_env=LLVM_PROFILE_FILE=$BUILD_PROFRAW_DIR/%p-%m.profraw" \
"--run_under=/usr/bin/env LLVM_PROFILE_FILE=$LLVM_PROFILE_FILE" \
- "${TEST_TARGETS[@]}"
-
-if [[ ! -s "$CPP_RAW" ]]; then
- echo "cpp-coverage: bazel coverage produced no combined report" >&2
- exit 1
-fi
+ //:unit //:e2e
-shopt -s nullglob
-profraws=("$PROFRAW_DIR"/*.profraw)
-shopt -u nullglob
-if [[ ${#profraws[@]} -eq 0 ]]; then
- echo "cpp-coverage: no profraw files in $PROFRAW_DIR; RUSTFLAGS or LLVM_PROFILE_FILE did not reach the test binaries" >&2
- exit 1
-fi
+"$LLVM_PROFDATA" merge -sparse \
+ "$COVERAGE_DIR"/*.profraw \
+ -o "$PROFDATA"
-"$LLVM_PROFDATA" merge -sparse "${profraws[@]}" -o "$PROFDATA"
+sed 's|^SF:|SF:foreign/cpp/|' "$CPP_RAW" >"$OUTPUT"
-LLVM_COV_OBJECT_ARGS=()
-for test_object in "${TEST_OBJECTS[@]}"; do
- if [[ ! -f "$test_object" ]]; then
- echo "cpp-coverage: test executable not found: $test_object" >&2
- exit 1
- fi
- LLVM_COV_OBJECT_ARGS+=(--object "$test_object")
-done
-
-"$LLVM_COV" export "${LLVM_COV_OBJECT_ARGS[@]}" \
+"$LLVM_COV" export \
+ --object bazel-bin/unit \
+ --object bazel-bin/e2e \
-instr-profile="$PROFDATA" \
-format=lcov \
- -ignore-filename-regex='(\.cargo/|/rustc/|/core/|cxxbridge|/registry/)' >"$SHIM_RAW"
-
-filter_lcov() {
- local input="$1" output="$2" mode="$3"
- awk -v mode="$mode" '
- function map_sf(raw, mapped) {
- if (mode == "rs") {
- if (match(raw, /foreign\/cpp\/src\/[^\/]+\.rs/)) {
- return substr(raw, RSTART, RLENGTH)
- }
- return ""
- }
- if (match(raw, /foreign\/cpp\/(src\/[^\/]+\.cpp|include\/[^\/]+\.hpp?)/)) {
- return substr(raw, RSTART, RLENGTH)
- }
- if (match(raw, /\/proc\/self\/cwd\/(src\/[^\/]+\.cpp|include\/[^\/]+\.hpp?)/)) {
- return "foreign/cpp/" substr(raw, RSTART + 15, RLENGTH - 15)
- }
- if (raw ~ /^(src\/[^\/]+\.cpp|include\/[^\/]+\.hpp?)$/) {
- return "foreign/cpp/" raw
- }
- return ""
- }
+ -ignore-filename-regex='(\.cargo/|/rustc/|/core/|cxxbridge|/registry/)' |
+ awk '
/^SF:/ {
- mapped = map_sf(substr($0, 4))
- if (mapped != "") {
- print "SF:" mapped
- in_block = 1
- } else {
- in_block = 0
- }
- next
- }
- /^end_of_record/ {
- if (in_block) {
- print
+ include = /foreign\/cpp\/src\/[^/]+\.rs$/
+ if (include) {
+ sub(/^SF:.*foreign\/cpp\//, "SF:foreign/cpp/")
}
- in_block = 0
- next
}
- {
- if (in_block) {
- print
- }
- }
- ' "$input" >"$output"
-}
-
-filter_lcov "$CPP_RAW" "$CPP_FILTERED" "cpp"
-filter_lcov "$SHIM_RAW" "$SHIM_FILTERED" "rs"
-
-cat "$CPP_FILTERED" "$SHIM_FILTERED" >"$OUTPUT_TMP"
+ include
+ ' >>"$OUTPUT"
-"$REPO_ROOT/scripts/ci/validate-lcov.sh" "$OUTPUT_TMP"
-mv "$OUTPUT_TMP" "$OUTPUT"
+../../scripts/ci/validate-lcov.sh "$OUTPUT"