Skip to content

Commit bc33ac2

Browse files
oquenchilcopybara-github
authored andcommitted
Fix exports filter in cc_shared_library
The indirect top level targets were being ignored by exports filter. RELNOTES:none PiperOrigin-RevId: 541882070 Change-Id: I9d2751d8bf343335b0f69949b8fc7d7e7fed9e1b
1 parent 8fd5b04 commit bc33ac2

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def _filter_inputs(
370370
cc_toolchain,
371371
linker_input,
372372
)
373-
elif _check_if_target_should_be_exported_with_filter(
373+
if _check_if_target_should_be_exported_with_filter(
374374
linker_input.owner,
375375
ctx.label,
376376
ctx.attr.exports_filter,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ load(
1010
"forwarding_cc_lib",
1111
"nocode_cc_lib",
1212
"wrapped_cc_lib",
13+
"exports_test",
1314
)
1415
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
1516

@@ -117,6 +118,9 @@ cc_shared_library(
117118
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:diff_pkg_so"
118119
],
119120
features = ["windows_export_all_symbols"],
121+
exports_filter = [
122+
":indirect_dep2",
123+
],
120124
deps = [
121125
"baz",
122126
"foo",
@@ -472,3 +476,17 @@ build_failure_test(
472476
message = "Do not place libraries which only contain a precompiled dynamic library",
473477
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:failing_only_dynamic_lib",
474478
)
479+
480+
exports_test(
481+
name = "exports_foo_test",
482+
target = ":foo_so",
483+
targets_that_should_be_claimed_to_be_exported = [
484+
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:indirect_dep2",
485+
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:baz",
486+
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:foo",
487+
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:cc_lib_with_no_srcs",
488+
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:nocode_cc_lib",
489+
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:should_not_be_linked_cc_lib",
490+
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:a_suffix",
491+
],
492+
)

src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/starlark_tests.bzl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,27 @@ nocode_cc_lib = rule(
331331
},
332332
provides = [CcInfo],
333333
)
334+
335+
def _exports_test_impl(env, target):
336+
actual = list(target[CcSharedLibraryInfo].exports)
337+
338+
# Remove the @ prefix on Bazel
339+
for i in range(len(actual)):
340+
if actual[i][0] == "@":
341+
actual[i] = actual[i][1:]
342+
expected = env.ctx.attr._targets_that_should_be_claimed_to_be_exported
343+
env.expect.where(
344+
detail = "Exports lists do not match.",
345+
).that_collection(actual).contains_exactly(expected).in_order()
346+
347+
def _exports_test_macro(name, target, targets_that_should_be_claimed_to_be_exported):
348+
analysis_test(
349+
name = name,
350+
impl = _exports_test_impl,
351+
target = target,
352+
attrs = {
353+
"_targets_that_should_be_claimed_to_be_exported": attr.string_list(default = targets_that_should_be_claimed_to_be_exported),
354+
},
355+
)
356+
357+
exports_test = _exports_test_macro

0 commit comments

Comments
 (0)