Skip to content

Commit

Permalink
Fix cc_test coverage broken by 92cba04
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 597562752
Change-Id: I799eb0a1eab433a9c6ceeaf53027570d1cd49be1
  • Loading branch information
hvadehra authored and copybara-github committed Jan 11, 2024
1 parent 68e2eb5 commit bbc51a0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/starlark/builtins_bzl/common/cc/cc_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def _attributes(ctx, is_apple):
latebound_libc = _latebound_libc(ctx, "libc_top", "_libc_top")
latebound_target_libc = _latebound_libc(ctx, "libc_top", "_target_libc_top")

all_files = _files(ctx, "all_files")
return struct(
supports_param_files = ctx.attr.supports_param_files,
runtime_solib_dir_base = "_solib__" + cc_internal.escape_label(label = ctx.label),
Expand All @@ -103,7 +104,7 @@ def _attributes(ctx, is_apple):
static_runtime_lib = ctx.attr.static_runtime_lib,
dynamic_runtime_lib = ctx.attr.dynamic_runtime_lib,
supports_header_parsing = ctx.attr.supports_header_parsing,
all_files = _files(ctx, "all_files"),
all_files = all_files,
compiler_files = _files(ctx, "compiler_files"),
strip_files = _files(ctx, "strip_files"),
objcopy_files = _files(ctx, "objcopy_files"),
Expand All @@ -128,7 +129,7 @@ def _attributes(ctx, is_apple):
is_apple,
),
cc_toolchain_label = ctx.label,
coverage_files = _files(ctx, "coverage_files"),
coverage_files = _files(ctx, "coverage_files") or all_files,
compiler_files_without_includes = _files(ctx, "compiler_files_without_includes"),
libc = _files(ctx, latebound_libc),
target_libc = _files(ctx, latebound_target_libc),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,45 @@ public void testGcovNotDefined() throws Exception {
assertThat(gcovPath).isEmpty();
}

// regression test for b/319501294
@Test
public void testEmptyCoverageFilesDefaultsToAllFiles() throws Exception {
CcToolchainConfig.Builder ccToolchainConfigBuilder = CcToolchainConfig.builder();
scratch.file(
"a/BUILD",
"load(':cc_toolchain_config.bzl', 'cc_toolchain_config')",
"filegroup(name='empty')",
"filegroup(name='my_files', srcs = ['file1', 'file2'])",
"cc_toolchain(",
" name = 'b',",
" all_files = ':my_files',",
" ar_files = ':empty',",
" as_files = ':empty',",
" compiler_files = ':empty',",
" dwp_files = ':empty',",
" linker_files = ':empty',",
" strip_files = ':empty',",
" objcopy_files = ':empty',",
" toolchain_identifier = 'banana',",
" toolchain_config = ':k8-compiler_config',",
")",
ccToolchainConfigBuilder.build().getCcToolchainConfigRule(),
"cc_library(",
" name = 'lib',",
" toolchains = [':b'],",
")");
analysisMock.ccSupport().setupCcToolchainConfig(mockToolsConfig, ccToolchainConfigBuilder);
mockToolsConfig.create(
"a/cc_toolchain_config.bzl",
ResourceLoader.readFromResources(
"com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl"));

CcToolchainProvider provider = getConfiguredTarget("//a:b").get(CcToolchainProvider.PROVIDER);

assertThat(artifactsToStrings(provider.getCoverageFiles()))
.containsExactly("src a/file1", "src a/file2");
}

@Test
public void testLlvmCoverageToolsDefined() throws Exception {
CcToolchainConfig.Builder ccToolchainConfigBuilder =
Expand Down

0 comments on commit bbc51a0

Please sign in to comment.