Skip to content

Commit 590ee17

Browse files
oquenchilcopybara-github
authored andcommitted
Allow cc_shared_library aspect to propagate along all attributes
This is rolling forward ff927f7 which I mistakenly confused as the root cause for #16296. The implementation does have an issue with too much propagation which is fixed on this change with required_providers and required_aspect_providers restrictions on the aspect. Fixes #17091. RELNOTES:none PiperOrigin-RevId: 507457624 Change-Id: I7317c4532ef20cd7584c55aacc3eca82c50a618b
1 parent 3df262c commit 590ee17

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/main/starlark/builtins_bzl/common/cc/cc_import.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ cc_import = rule(
220220
),
221221
"_cc_toolchain": attr.label(default = "@" + semantics.get_repo() + "//tools/cpp:current_cc_toolchain"),
222222
},
223+
provides = [CcInfo],
223224
toolchains = cc_helper.use_cpp_toolchain(),
224225
fragments = ["cpp"],
225226
incompatible_use_toolchain_transition = True,

src/main/starlark/builtins_bzl/common/cc/cc_proto_library.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,5 @@ cc_proto_library = rule(
294294
allow_files = False,
295295
),
296296
},
297+
provides = [CcInfo],
297298
)

src/main/starlark/builtins_bzl/common/cc/experimental_cc_shared_library.bzl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rely on this. It requires bazel >1.2 and passing the flag
2121

2222
load(":common/cc/cc_helper.bzl", "cc_helper")
2323
load(":common/cc/semantics.bzl", "semantics")
24+
load(":common/proto/proto_info.bzl", "ProtoInfo")
2425

2526
CcInfo = _builtins.toplevel.CcInfo
2627
cc_common = _builtins.toplevel.cc_common
@@ -620,11 +621,17 @@ def _cc_shared_library_impl(ctx):
620621
def _graph_structure_aspect_impl(target, ctx):
621622
children = []
622623

623-
# For now ignore cases when deps is of type label instead of label_list.
624-
if hasattr(ctx.rule.attr, "deps") and type(ctx.rule.attr.deps) != "Target":
625-
for dep in ctx.rule.attr.deps:
626-
if GraphNodeInfo in dep:
627-
children.append(dep[GraphNodeInfo])
624+
# Collect graph structure info from any possible deplike attribute. The aspect
625+
# itself applies across every deplike attribute (attr_aspects is *), so enumerate
626+
# over all attributes and consume GraphNodeInfo if available.
627+
for fieldname in dir(ctx.rule.attr):
628+
deps = getattr(ctx.rule.attr, fieldname, None)
629+
if type(deps) == "list":
630+
for dep in deps:
631+
if type(dep) == "Target" and GraphNodeInfo in dep:
632+
children.append(dep[GraphNodeInfo])
633+
elif type(deps) == "Target" and GraphNodeInfo in deps:
634+
children.append(deps[GraphNodeInfo])
628635

629636
# TODO(bazel-team): Add flag to Bazel that can toggle the initialization of
630637
# linkable_more_than_once.
@@ -659,6 +666,8 @@ def _cc_shared_library_permissions_impl(ctx):
659666

660667
graph_structure_aspect = aspect(
661668
attr_aspects = ["*"],
669+
required_providers = [[CcInfo], [ProtoInfo]],
670+
required_aspect_providers = [[CcInfo]],
662671
implementation = _graph_structure_aspect_impl,
663672
)
664673

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/BUILD.builtin_test

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ cc_binary(
3636
name = "binary",
3737
srcs = ["main.cc"],
3838
dynamic_deps = ["foo_so"],
39-
deps = ["foo"],
39+
deps = [
40+
":foo",
41+
],
4042
)
4143

44+
# TODO(bazel-team): Add a test for proto dependencies once these tests are run
45+
# directly from a BUILD file and not from within a shell test. Right now
46+
# mocking what's needed to have a single proto dependency makes it impractical.
47+
4248
cc_binary(
4349
name = "binary_with_bar_so_twice",
4450
srcs = ["main.cc"],
@@ -331,8 +337,8 @@ build_failure_test(
331337

332338
cc_library(
333339
name = "prebuilt",
340+
hdrs = ["direct_so_file_cc_lib.h"],
334341
srcs = [
335-
"direct_so_file_cc_lib.h",
336342
":just_main_output",
337343
],
338344
)

0 commit comments

Comments
 (0)