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

Commit

Permalink
Make the srcs attribute of swift_library mandatory and non-empty.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 345120894
  • Loading branch information
allevato authored and swiple-rules-gardener committed Dec 2, 2020
1 parent d5fa2f5 commit c210804
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions swift/internal/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ indirect (transitive) dependents.
"licenses": attr.license(), # buildifier: disable=attr-license
}

def swift_compilation_attrs(additional_deps_aspects = []):
def swift_compilation_attrs(
additional_deps_aspects = [],
requires_srcs = True):
"""Returns an attribute dictionary for rules that compile Swift code.
The returned dictionary contains the subset of attributes that are shared by
Expand Down Expand Up @@ -79,6 +81,8 @@ def swift_compilation_attrs(additional_deps_aspects = []):
by the individual rules to avoid potential circular dependencies
between the API and the aspects; the API loaded the aspects
directly, then those aspects would not be able to load the API.
requires_srcs: Indicates whether the `srcs` attribute should be marked
as mandatory and non-empty. Defaults to `True`.
Returns:
A new attribute dictionary that can be added to the attributes of a
Expand All @@ -92,11 +96,13 @@ def swift_compilation_attrs(additional_deps_aspects = []):
swift_toolchain_attrs(),
{
"srcs": attr.label_list(
flags = ["DIRECT_COMPILE_TIME_INPUT"],
allow_empty = not requires_srcs,
allow_files = ["swift"],
doc = """\
A list of `.swift` source files that will be compiled into the library.
""",
flags = ["DIRECT_COMPILE_TIME_INPUT"],
mandatory = requires_srcs,
),
"copts": attr.string_list(
doc = """\
Expand Down Expand Up @@ -189,7 +195,9 @@ Linux), those dependencies will be **ignored.**
**kwargs
)

def swift_library_rule_attrs(additional_deps_aspects = []):
def swift_library_rule_attrs(
additional_deps_aspects = [],
requires_srcs = True):
"""Returns an attribute dictionary for `swift_library`-like rules.
The returned dictionary contains the same attributes that are defined by the
Expand Down Expand Up @@ -224,6 +232,8 @@ def swift_library_rule_attrs(additional_deps_aspects = []):
by the individual rules to avoid potential circular dependencies
between the API and the aspects; the API loaded the aspects
directly, then those aspects would not be able to load the API.
requires_srcs: Indicates whether the `srcs` attribute should be marked
as mandatory and non-empty. Defaults to `True`.
Returns:
A new attribute dictionary that can be added to the attributes of a
Expand All @@ -232,6 +242,7 @@ def swift_library_rule_attrs(additional_deps_aspects = []):
return dicts.add(
swift_compilation_attrs(
additional_deps_aspects = additional_deps_aspects,
requires_srcs = requires_srcs,
),
swift_config_attrs(),
{
Expand Down
1 change: 1 addition & 0 deletions swift/internal/swift_binary_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _binary_rule_attrs(stamp_default):
return dicts.add(
swift_common.compilation_attrs(
additional_deps_aspects = [swift_common.swift_clang_module_aspect],
requires_srcs = False,
),
{
"linkopts": attr.string_list(
Expand Down

0 comments on commit c210804

Please sign in to comment.