Skip to content

Commit 68aad18

Browse files
oquenchilcopybara-github
authored andcommitted
Rename roots in cc_shared_library to deps
The attribute 'roots' was initially called 'exports', however this generated confusion as it did not behave like 'exports' in other rules nor does the cc_shared_library rule guarantee that the symbols from targets in that attribute would be exported. From 'exports' it was renamed 'roots' to express that these are the targets at the top of the tree whose transitive closure would be linked into this shared library (dynamically or statically). However, 'roots' also departs from the standard attribute name used across all rules, 'deps'. 'roots' does not even convey that the attribute accepts other targets. Now that the attribute 'static_deps' has been removed, 'deps' again is the best attribute name we could have. It adds consistency with other rules and makes sure that the attribute assumed by tooling by default to contain the main dependencies is the same. With the --experimental_cc_shared_library flag, the attribute 'deps' will still work. Without the experimental flag, 'deps' must be used. Eventually, we will remove the experimental flag, therefore all targets should rename the attribute. RELNOTES[inc]: The attribute cc_shared_library.roots is renamed to 'deps' PiperOrigin-RevId: 505705317 Change-Id: I69a25f6a835c87626aeeef6c9c3def5c148a31f7
1 parent 6fe6a95 commit 68aad18

File tree

3 files changed

+54
-27
lines changed

3 files changed

+54
-27
lines changed

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ def _filter_inputs(
251251
ctx,
252252
feature_configuration,
253253
cc_toolchain,
254+
deps,
254255
transitive_exports,
255256
preloaded_deps_direct_labels,
256257
link_once_static_libs_map):
@@ -260,7 +261,7 @@ def _filter_inputs(
260261
graph_structure_aspect_nodes = []
261262
dependency_linker_inputs = []
262263
direct_exports = {}
263-
for export in ctx.attr.roots:
264+
for export in deps:
264265
direct_exports[str(export.label)] = True
265266
dependency_linker_inputs.extend(export[CcInfo].linking_context.linker_inputs.to_list())
266267
graph_structure_aspect_nodes.append(export[GraphNodeInfo])
@@ -403,16 +404,40 @@ def _get_permissions(ctx):
403404
return ctx.attr.permissions
404405
return None
405406

407+
def _get_deps(ctx):
408+
if len(ctx.attr.deps) and len(ctx.attr.roots):
409+
fail(
410+
"You are using the attribute 'roots' and 'deps'. 'deps' is the " +
411+
"new name for the attribute 'roots'. The attribute 'roots' will be" +
412+
"removed in the future",
413+
attr = "roots",
414+
)
415+
416+
deps = ctx.attr.deps
417+
if not len(deps):
418+
deps = ctx.attr.roots
419+
420+
return deps
421+
406422
def _cc_shared_library_impl(ctx):
407423
semantics.check_experimental_cc_shared_library(ctx)
408424

409-
if len(ctx.attr.static_deps) and not cc_common.check_experimental_cc_shared_library():
410-
fail(
411-
"This attribute is a no-op and its usage" +
412-
" is forbidden after cc_shared_library is no longer experimental. " +
413-
"Remove it from every cc_shared_library target",
414-
attr = "static_deps",
415-
)
425+
if not cc_common.check_experimental_cc_shared_library():
426+
if len(ctx.attr.static_deps):
427+
fail(
428+
"This attribute is a no-op and its usage" +
429+
" is forbidden after cc_shared_library is no longer experimental. " +
430+
"Remove it from every cc_shared_library target",
431+
attr = "static_deps",
432+
)
433+
if len(ctx.attr.roots):
434+
fail(
435+
"This attribute has been renamed to 'deps'. Simply rename the" +
436+
" attribute on the target.",
437+
attr = "roots",
438+
)
439+
440+
deps = _get_deps(ctx)
416441

417442
cc_toolchain = cc_helper.find_cpp_toolchain(ctx)
418443
feature_configuration = cc_common.configure_features(
@@ -424,7 +449,7 @@ def _cc_shared_library_impl(ctx):
424449

425450
merged_cc_shared_library_info = _merge_cc_shared_library_infos(ctx)
426451
exports_map = _build_exports_map_from_only_dynamic_deps(merged_cc_shared_library_info)
427-
for export in ctx.attr.roots:
452+
for export in deps:
428453
# Do not check for overlap between targets matched by the current
429454
# rule's exports_filter and what is in exports_map. A library in roots
430455
# will have to be linked in statically into the current rule with 100%
@@ -457,6 +482,7 @@ def _cc_shared_library_impl(ctx):
457482
ctx,
458483
feature_configuration,
459484
cc_toolchain,
485+
deps,
460486
exports_map,
461487
preloaded_deps_direct_labels,
462488
link_once_static_libs_map,
@@ -534,7 +560,7 @@ def _cc_shared_library_impl(ctx):
534560

535561
runfiles = runfiles.merge(ctx.runfiles(files = precompiled_only_dynamic_libraries_runfiles))
536562

537-
for export in ctx.attr.roots:
563+
for export in deps:
538564
export_label = str(export.label)
539565
if GraphNodeInfo in export and export[GraphNodeInfo].no_exporting:
540566
if export_label in curr_link_once_static_libs_set:
@@ -654,6 +680,7 @@ cc_shared_library = rule(
654680
"preloaded_deps": attr.label_list(providers = [CcInfo]),
655681
"win_def_file": attr.label(allow_single_file = [".def"]),
656682
"roots": attr.label_list(providers = [CcInfo], aspects = [graph_structure_aspect]),
683+
"deps": attr.label_list(providers = [CcInfo], aspects = [graph_structure_aspect]),
657684
"static_deps": attr.string_list(),
658685
"user_link_flags": attr.string_list(),
659686
"_def_parser": semantics.get_def_parser(),

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,28 @@ cc_binary(
5252
cc_shared_library(
5353
name = "python_module",
5454
features = ["windows_export_all_symbols"],
55-
roots = [":a_suffix"],
55+
deps = [":a_suffix"],
5656
shared_lib_name = "python_module.pyd",
5757
)
5858

5959
cc_shared_library(
6060
name = "a_so",
6161
features = ["windows_export_all_symbols"],
62-
roots = [":a_suffix"],
62+
deps = [":a_suffix"],
6363
)
6464

6565
cc_shared_library(
6666
name = "diamond_so",
6767
dynamic_deps = [":a_so"],
6868
features = ["windows_export_all_symbols"],
69-
roots = [":qux"],
69+
deps = [":qux"],
7070
)
7171

7272
cc_shared_library(
7373
name = "diamond2_so",
7474
dynamic_deps = [":a_so"],
7575
features = ["windows_export_all_symbols"],
76-
roots = [":qux2"],
76+
deps = [":qux2"],
7777
)
7878

7979
cc_binary(
@@ -101,7 +101,7 @@ cc_shared_library(
101101
dynamic_deps = ["bar_so"],
102102
features = ["windows_export_all_symbols"],
103103
preloaded_deps = ["preloaded_dep"],
104-
roots = [
104+
deps = [
105105
"baz",
106106
"foo",
107107
"a_suffix",
@@ -195,7 +195,7 @@ cc_shared_library(
195195
permissions = [
196196
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:permissions",
197197
],
198-
roots = [
198+
deps = [
199199
"bar",
200200
"bar2",
201201
] + select({
@@ -346,7 +346,7 @@ filegroup(
346346
cc_shared_library(
347347
name = "direct_so_file",
348348
features = ["windows_export_all_symbols"],
349-
roots = [
349+
deps = [
350350
":direct_so_file_cc_lib",
351351
],
352352
)
@@ -367,7 +367,7 @@ filegroup(
367367
cc_shared_library(
368368
name = "renamed_so_file",
369369
features = ["windows_export_all_symbols"],
370-
roots = [
370+
deps = [
371371
":direct_so_file_cc_lib2",
372372
],
373373
shared_lib_name = "renamed_so_file.so",
@@ -417,23 +417,23 @@ cc_library(
417417

418418
cc_shared_library(
419419
name = "lib_with_no_exporting_roots_1",
420-
roots = [":static_lib_no_exporting"],
420+
deps = [":static_lib_no_exporting"],
421421
)
422422

423423
cc_shared_library(
424424
name = "lib_with_no_exporting_roots_2",
425-
roots = [":static_lib_no_exporting"],
425+
deps = [":static_lib_no_exporting"],
426426
dynamic_deps = [":lib_with_no_exporting_roots_3"],
427427
)
428428

429429
cc_shared_library(
430430
name = "lib_with_no_exporting_roots_3",
431-
roots = [":static_lib_no_exporting"],
431+
deps = [":static_lib_no_exporting"],
432432
)
433433

434434
cc_shared_library(
435435
name = "lib_with_no_exporting_roots",
436-
roots = [
436+
deps = [
437437
":static_lib_no_exporting",
438438
":static_lib_exporting",
439439
],

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cc_binary(
1919
cc_shared_library(
2020
name = "should_fail_shared_lib",
2121
dynamic_deps = ["//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:bar_so"],
22-
roots = [
22+
deps = [
2323
":intermediate",
2424
],
2525
tags = TAGS,
@@ -34,7 +34,7 @@ cc_library(
3434

3535
cc_shared_library(
3636
name = "permissions_fail_so",
37-
roots = [
37+
deps = [
3838
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:bar",
3939
],
4040
tags = TAGS,
@@ -69,7 +69,7 @@ cc_shared_library(
6969
":b_so",
7070
":b2_so",
7171
],
72-
roots = [
72+
deps = [
7373
":a",
7474
],
7575
tags = TAGS,
@@ -87,15 +87,15 @@ cc_binary(
8787

8888
cc_shared_library(
8989
name = "b_so",
90-
roots = [
90+
deps = [
9191
":b",
9292
],
9393
tags = TAGS,
9494
)
9595

9696
cc_shared_library(
9797
name = "b2_so",
98-
roots = [
98+
deps = [
9999
":b",
100100
],
101101
tags = TAGS,

0 commit comments

Comments
 (0)