@@ -46,7 +46,9 @@ indirect (transitive) dependents.
46
46
"licenses" : attr .license (), # buildifier: disable=attr-license
47
47
}
48
48
49
- def swift_compilation_attrs (additional_deps_aspects = []):
49
+ def swift_compilation_attrs (
50
+ additional_deps_aspects = [],
51
+ requires_srcs = True ):
50
52
"""Returns an attribute dictionary for rules that compile Swift code.
51
53
52
54
The returned dictionary contains the subset of attributes that are shared by
@@ -79,6 +81,8 @@ def swift_compilation_attrs(additional_deps_aspects = []):
79
81
by the individual rules to avoid potential circular dependencies
80
82
between the API and the aspects; the API loaded the aspects
81
83
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`.
82
86
83
87
Returns:
84
88
A new attribute dictionary that can be added to the attributes of a
@@ -92,11 +96,13 @@ def swift_compilation_attrs(additional_deps_aspects = []):
92
96
swift_toolchain_attrs (),
93
97
{
94
98
"srcs" : attr .label_list (
95
- flags = [ "DIRECT_COMPILE_TIME_INPUT" ] ,
99
+ allow_empty = not requires_srcs ,
96
100
allow_files = ["swift" ],
97
101
doc = """\
98
102
A list of `.swift` source files that will be compiled into the library.
99
103
""" ,
104
+ flags = ["DIRECT_COMPILE_TIME_INPUT" ],
105
+ mandatory = requires_srcs ,
100
106
),
101
107
"copts" : attr .string_list (
102
108
doc = """\
@@ -189,7 +195,9 @@ Linux), those dependencies will be **ignored.**
189
195
** kwargs
190
196
)
191
197
192
- def swift_library_rule_attrs (additional_deps_aspects = []):
198
+ def swift_library_rule_attrs (
199
+ additional_deps_aspects = [],
200
+ requires_srcs = True ):
193
201
"""Returns an attribute dictionary for `swift_library`-like rules.
194
202
195
203
The returned dictionary contains the same attributes that are defined by the
@@ -224,6 +232,8 @@ def swift_library_rule_attrs(additional_deps_aspects = []):
224
232
by the individual rules to avoid potential circular dependencies
225
233
between the API and the aspects; the API loaded the aspects
226
234
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`.
227
237
228
238
Returns:
229
239
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 = []):
232
242
return dicts .add (
233
243
swift_compilation_attrs (
234
244
additional_deps_aspects = additional_deps_aspects ,
245
+ requires_srcs = requires_srcs ,
235
246
),
236
247
swift_config_attrs (),
237
248
{
0 commit comments