From bbc51a06ba4db1c88bfce6dfa3c7b0622cb56d72 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 11 Jan 2024 08:27:28 -0800 Subject: [PATCH] Fix `cc_test` coverage broken by https://github.com/bazelbuild/bazel/commit/92cba040904c2ccbd0b5a70263de739f72c592ae PiperOrigin-RevId: 597562752 Change-Id: I799eb0a1eab433a9c6ceeaf53027570d1cd49be1 --- .../builtins_bzl/common/cc/cc_toolchain.bzl | 5 ++- .../rules/cpp/CcToolchainProviderTest.java | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/starlark/builtins_bzl/common/cc/cc_toolchain.bzl b/src/main/starlark/builtins_bzl/common/cc/cc_toolchain.bzl index ebe7851606504b..9f642eb31d6dc7 100644 --- a/src/main/starlark/builtins_bzl/common/cc/cc_toolchain.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/cc_toolchain.bzl @@ -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), @@ -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"), @@ -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), diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java index e49bef50413a77..110f2f53752751 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java @@ -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 =