From 8776b3d9ad2504412310ce20ba14f2232f0b09a9 Mon Sep 17 00:00:00 2001 From: John Laxson Date: Mon, 25 Sep 2023 01:20:43 -0700 Subject: [PATCH] [6.4.0] cc_library: propagate data dependencies via implementation_deps. (#19590) Cherry pick 56e9020 from #18416 Commit https://github.com/bazelbuild/bazel/commit/56e9020b434e321d51d077428cd5f49bee940ee2 Co-authored-by: Yuval Kaplan --- .../builtins_bzl/common/cc/cc_library.bzl | 3 ++ .../cpp/CcLibraryConfiguredTargetTest.java | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl b/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl index d82642cd9cf3e0..304b4baac8282b 100755 --- a/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl @@ -283,6 +283,9 @@ def _cc_library_impl(ctx): for dep in ctx.attr.deps: runfiles_list.append(dep[DefaultInfo].default_runfiles) + for dep in ctx.attr.implementation_deps: + runfiles_list.append(dep[DefaultInfo].default_runfiles) + runfiles = ctx.runfiles().merge_all(runfiles_list) default_runfiles = ctx.runfiles(files = cc_helper.get_dynamic_libraries_for_runtime(linking_context_for_runfiles, True)) diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index 050f3a8e0f0ac1..1aed4e8659c122 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -2004,6 +2004,44 @@ public void testImplementationDepsLinkingContextIsPropagated() throws Exception .contains("bin foo/libimplementation_dep.a"); } + @Test + public void testImplementationDepsRunfilesArePropagated() throws Exception { + useConfiguration("--experimental_cc_implementation_deps"); + scratch.file( + "foo/BUILD", + "cc_binary(", + " name = 'bin',", + " srcs = ['bin.cc'],", + " deps = ['lib'],", + ")", + "cc_library(", + " name = 'lib',", + " srcs = ['lib.cc'],", + " deps = ['public_dep'],", + ")", + "cc_library(", + " name = 'public_dep',", + " srcs = ['public_dep.cc'],", + " hdrs = ['public_dep.h'],", + " implementation_deps = ['implementation_dep'],", + " deps = ['interface_dep'],", + ")", + "cc_library(", + " name = 'interface_dep',", + " data = ['data/interface.txt'],", + ")", + "cc_library(", + " name = 'implementation_dep',", + " data = ['data/implementation.txt'],", + ")"); + + ConfiguredTarget lib = getConfiguredTarget("//foo:bin"); + assertThat( + artifactsToStrings( + lib.get(DefaultInfo.PROVIDER).getDefaultRunfiles().getAllArtifacts())) + .containsAtLeast("src foo/data/interface.txt", "src foo/data/implementation.txt"); + } + @Test public void testImplementationDepsConfigurationHostSucceeds() throws Exception { useConfiguration("--experimental_cc_implementation_deps");