Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LCOV merger dependency of cc_test without coverage #16994

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/starlark/builtins_bzl/common/cc/cc_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def make_cc_test(with_linkstatic = False, with_aspects = False):
"stripped_binary": "%{name}.stripped",
"dwp_file": "%{name}.dwp",
},
fragments = ["google_cpp", "cpp"],
fragments = ["google_cpp", "cpp", "coverage"],
exec_groups = {
"cpp_link": exec_group(copy_from_rule = True),
},
Expand Down
6 changes: 3 additions & 3 deletions src/main/starlark/builtins_bzl/common/cc/semantics.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ def _get_test_malloc_attr():
def _get_coverage_attrs():
return {
"_lcov_merger": attr.label(
default = "@bazel_tools//tools/test:lcov_merger",
default = configuration_field(fragment = "coverage", name = "output_generator"),
executable = True,
cfg = "target",
cfg = "exec",
),
"_collect_cc_coverage": attr.label(
default = "@bazel_tools//tools/test:collect_cc_coverage",
executable = True,
cfg = "target",
cfg = "exec",
),
}

Expand Down
42 changes: 42 additions & 0 deletions src/test/shell/bazel/cc_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1816,4 +1816,46 @@ EOF
--repo_env=BAZEL_CONLYOPTS=-DEXIT_CODE=0 || fail "Expected C compilation to pass"
}

function test_cc_test_no_target_coverage_dep() {
# Regression test for https:/bazelbuild/bazel/issues/16961
local package="${FUNCNAME[0]}"
mkdir -p "${package}"

cat > "${package}"/BUILD.bazel <<'EOF'
cc_test(
name = "test",
srcs = ["test.cc"],
)
EOF
touch "${package}"/test.cc

out=$(bazel cquery --collect_code_coverage \
"deps(//${package}:test) intersect config(@remote_coverage_tools//:all, target)")
if [[ -n "$out" ]]; then
fail "Expected no dependency on lcov_merger in the target configuration, but got: $out"
fi
}

function test_cc_test_no_lcov_merger_dep_without_coverage() {
# Regression test for https:/bazelbuild/bazel/issues/16961
local package="${FUNCNAME[0]}"
mkdir -p "${package}"

cat > "${package}"/BUILD.bazel <<'EOF'
cc_test(
name = "test",
srcs = ["test.cc"],
)
EOF
touch "${package}"/test.cc

# FIXME: cc_test still unconditionally depends on the LCOV merger binary through
# @remote_coverage_tools//:coverage_output_generator, which is also unnecessary:
# https:/bazelbuild/bazel/issues/15088
out=$(bazel cquery "somepath(//${package}:test,@remote_coverage_tools//:lcov_merger)")
if [[ -n "$out" ]]; then
fail "Expected no dependency on lcov_merger, but got: $out"
fi
}

run_suite "cc_integration_test"