Skip to content

Commit 69d43b4

Browse files
oquenchilcopybara-github
authored andcommitted
Make it an error to have a cc_shared_library with no deps
A cc_shared_library with no deps doesn't provide anything on the build graph, it would be an empty shared library file. RELNOTES:none PiperOrigin-RevId: 508597495 Change-Id: Ied80243500b804071b88a6df5c0fc9c8bbdd0f28
1 parent f29db1b commit 69d43b4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ def _get_deps(ctx):
418418
if not len(deps):
419419
deps = ctx.attr.roots
420420

421+
if len(deps) == 0:
422+
fail(
423+
"'cc_shared_library' must have at least one dependency in 'deps' (or 'roots')",
424+
attr = "deps",
425+
)
426+
421427
return deps
422428

423429
def _cc_shared_library_impl(ctx):

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,9 @@ no_exporting_static_lib_test(
492492
name = "no_exporting_static_lib_test",
493493
target_under_test = ":lib_with_no_exporting_roots",
494494
)
495+
496+
build_failure_test(
497+
name = "shared_library_without_deps",
498+
message = "'cc_shared_library' must have at least one dependency in 'deps' (or 'roots')",
499+
target_under_test = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:failing_with_no_deps_so",
500+
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ cc_shared_library(
100100
],
101101
tags = TAGS,
102102
)
103+
104+
cc_shared_library(
105+
name = "failing_with_no_deps_so",
106+
tags = TAGS,
107+
)

0 commit comments

Comments
 (0)