Skip to content

Commit

Permalink
Fix exports filter in cc_shared_library
Browse files Browse the repository at this point in the history
The indirect top level targets were being ignored by exports filter.

RELNOTES:none
PiperOrigin-RevId: 541882070
Change-Id: I9d2751d8bf343335b0f69949b8fc7d7e7fed9e1b
  • Loading branch information
oquenchil authored and copybara-github committed Jun 20, 2023
1 parent 8fd5b04 commit bc33ac2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def _filter_inputs(
cc_toolchain,
linker_input,
)
elif _check_if_target_should_be_exported_with_filter(
if _check_if_target_should_be_exported_with_filter(
linker_input.owner,
ctx.label,
ctx.attr.exports_filter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ load(
"forwarding_cc_lib",
"nocode_cc_lib",
"wrapped_cc_lib",
"exports_test",
)
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")

Expand Down Expand Up @@ -117,6 +118,9 @@ cc_shared_library(
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:diff_pkg_so"
],
features = ["windows_export_all_symbols"],
exports_filter = [
":indirect_dep2",
],
deps = [
"baz",
"foo",
Expand Down Expand Up @@ -472,3 +476,17 @@ build_failure_test(
message = "Do not place libraries which only contain a precompiled dynamic library",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:failing_only_dynamic_lib",
)

exports_test(
name = "exports_foo_test",
target = ":foo_so",
targets_that_should_be_claimed_to_be_exported = [
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:indirect_dep2",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:baz",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:foo",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:cc_lib_with_no_srcs",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:nocode_cc_lib",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:should_not_be_linked_cc_lib",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:a_suffix",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,27 @@ nocode_cc_lib = rule(
},
provides = [CcInfo],
)

def _exports_test_impl(env, target):
actual = list(target[CcSharedLibraryInfo].exports)

# Remove the @ prefix on Bazel
for i in range(len(actual)):
if actual[i][0] == "@":
actual[i] = actual[i][1:]
expected = env.ctx.attr._targets_that_should_be_claimed_to_be_exported
env.expect.where(
detail = "Exports lists do not match.",
).that_collection(actual).contains_exactly(expected).in_order()

def _exports_test_macro(name, target, targets_that_should_be_claimed_to_be_exported):
analysis_test(
name = name,
impl = _exports_test_impl,
target = target,
attrs = {
"_targets_that_should_be_claimed_to_be_exported": attr.string_list(default = targets_that_should_be_claimed_to_be_exported),
},
)

exports_test = _exports_test_macro

0 comments on commit bc33ac2

Please sign in to comment.