Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit c210804

Browse files
allevatoswiple-rules-gardener
authored andcommitted
Make the srcs attribute of swift_library mandatory and non-empty.
PiperOrigin-RevId: 345120894
1 parent d5fa2f5 commit c210804

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

swift/internal/attrs.bzl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ indirect (transitive) dependents.
4646
"licenses": attr.license(), # buildifier: disable=attr-license
4747
}
4848

49-
def swift_compilation_attrs(additional_deps_aspects = []):
49+
def swift_compilation_attrs(
50+
additional_deps_aspects = [],
51+
requires_srcs = True):
5052
"""Returns an attribute dictionary for rules that compile Swift code.
5153
5254
The returned dictionary contains the subset of attributes that are shared by
@@ -79,6 +81,8 @@ def swift_compilation_attrs(additional_deps_aspects = []):
7981
by the individual rules to avoid potential circular dependencies
8082
between the API and the aspects; the API loaded the aspects
8183
directly, then those aspects would not be able to load the API.
84+
requires_srcs: Indicates whether the `srcs` attribute should be marked
85+
as mandatory and non-empty. Defaults to `True`.
8286
8387
Returns:
8488
A new attribute dictionary that can be added to the attributes of a
@@ -92,11 +96,13 @@ def swift_compilation_attrs(additional_deps_aspects = []):
9296
swift_toolchain_attrs(),
9397
{
9498
"srcs": attr.label_list(
95-
flags = ["DIRECT_COMPILE_TIME_INPUT"],
99+
allow_empty = not requires_srcs,
96100
allow_files = ["swift"],
97101
doc = """\
98102
A list of `.swift` source files that will be compiled into the library.
99103
""",
104+
flags = ["DIRECT_COMPILE_TIME_INPUT"],
105+
mandatory = requires_srcs,
100106
),
101107
"copts": attr.string_list(
102108
doc = """\
@@ -189,7 +195,9 @@ Linux), those dependencies will be **ignored.**
189195
**kwargs
190196
)
191197

192-
def swift_library_rule_attrs(additional_deps_aspects = []):
198+
def swift_library_rule_attrs(
199+
additional_deps_aspects = [],
200+
requires_srcs = True):
193201
"""Returns an attribute dictionary for `swift_library`-like rules.
194202
195203
The returned dictionary contains the same attributes that are defined by the
@@ -224,6 +232,8 @@ def swift_library_rule_attrs(additional_deps_aspects = []):
224232
by the individual rules to avoid potential circular dependencies
225233
between the API and the aspects; the API loaded the aspects
226234
directly, then those aspects would not be able to load the API.
235+
requires_srcs: Indicates whether the `srcs` attribute should be marked
236+
as mandatory and non-empty. Defaults to `True`.
227237
228238
Returns:
229239
A new attribute dictionary that can be added to the attributes of a
@@ -232,6 +242,7 @@ def swift_library_rule_attrs(additional_deps_aspects = []):
232242
return dicts.add(
233243
swift_compilation_attrs(
234244
additional_deps_aspects = additional_deps_aspects,
245+
requires_srcs = requires_srcs,
235246
),
236247
swift_config_attrs(),
237248
{

swift/internal/swift_binary_test.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def _binary_rule_attrs(stamp_default):
3636
return dicts.add(
3737
swift_common.compilation_attrs(
3838
additional_deps_aspects = [swift_common.swift_clang_module_aspect],
39+
requires_srcs = False,
3940
),
4041
{
4142
"linkopts": attr.string_list(

0 commit comments

Comments
 (0)