Skip to content

Commit dcd7e67

Browse files
committed
Address comments from rupprecht@ - better docs and names.
1 parent 2521256 commit dcd7e67

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,42 +89,37 @@ def libc_function(name, **kwargs):
8989
**kwargs
9090
)
9191

92-
# LibcLibraryInfo is used to collect all sources and textual headers required
93-
# to build a particular libc_function or libc_support_library.
9492
LibcLibraryInfo = provider(
93+
"All source files and textual headers for building a particular library.",
9594
fields = ["srcs", "textual_hdrs"],
9695
)
9796

98-
def _get_libc_info_aspect_impl(target, ctx):
97+
def _get_libc_info_aspect_impl(
98+
target, # @unused
99+
ctx):
99100
maybe_srcs = getattr(ctx.rule.attr, "srcs", [])
100101
maybe_hdrs = getattr(ctx.rule.attr, "hdrs", [])
101102
maybe_textual_hdrs = getattr(ctx.rule.attr, "textual_hdrs", [])
102103
maybe_deps = getattr(ctx.rule.attr, "deps", [])
103104
return LibcLibraryInfo(
104105
srcs = depset(
105-
[
106-
f
107-
for src in maybe_srcs + maybe_hdrs
108-
for f in src.files.to_list()
109-
if f.is_source
110-
],
111106
transitive = [
112107
dep[LibcLibraryInfo].srcs
113108
for dep in maybe_deps
114109
if LibcLibraryInfo in dep
110+
] + [
111+
src.files
112+
for src in maybe_srcs + maybe_hdrs
115113
],
116114
),
117115
textual_hdrs = depset(
118-
[
119-
f
120-
for hdr in maybe_textual_hdrs
121-
for f in hdr.files.to_list()
122-
if f.is_source
123-
],
124116
transitive = [
125117
dep[LibcLibraryInfo].textual_hdrs
126118
for dep in maybe_deps
127119
if LibcLibraryInfo in dep
120+
] + [
121+
hdr.files
122+
for hdr in maybe_textual_hdrs
128123
],
129124
),
130125
)
@@ -134,18 +129,17 @@ _get_libc_info_aspect = aspect(
134129
attr_aspects = ["deps"],
135130
)
136131

137-
def _get_libc_srcs_impl(ctx):
132+
def _libc_srcs_filegroup_impl(ctx):
138133
return DefaultInfo(
139134
files = depset(transitive = [
140135
fn[LibcLibraryInfo].srcs
141136
for fn in ctx.attr.libs
142137
]),
143138
)
144139

145-
# get_libc_srcs returns the list of sources required to build all
146-
# specified libraries.
147-
get_libc_srcs = rule(
148-
implementation = _get_libc_srcs_impl,
140+
_libc_srcs_filegroup = rule(
141+
doc = "Returns all sources for building the specified libraries.",
142+
implementation = _libc_srcs_filegroup_impl,
149143
attrs = {
150144
"libs": attr.label_list(
151145
mandatory = True,
@@ -154,18 +148,17 @@ get_libc_srcs = rule(
154148
},
155149
)
156150

157-
def _get_libc_textual_hdrs_impl(ctx):
151+
def _libc_textual_hdrs_filegroup_impl(ctx):
158152
return DefaultInfo(
159153
files = depset(transitive = [
160154
fn[LibcLibraryInfo].textual_hdrs
161155
for fn in ctx.attr.libs
162156
]),
163157
)
164158

165-
# get_libc_textual_hdrs returns the list of textual headers required to compile
166-
# all specified libraries.
167-
get_libc_textual_hdrs = rule(
168-
implementation = _get_libc_textual_hdrs_impl,
159+
_libc_textual_hdrs_filegroup = rule(
160+
doc = "Returns all textual headers for compiling the specified libraries.",
161+
implementation = _libc_textual_hdrs_filegroup_impl,
169162
attrs = {
170163
"libs": attr.label_list(
171164
mandatory = True,
@@ -189,12 +182,12 @@ def libc_release_library(
189182
**kwargs: Other arguments relevant to cc_library.
190183
"""
191184

192-
get_libc_srcs(
185+
_libc_srcs_filegroup(
193186
name = name + "_srcs",
194187
libs = libc_functions,
195188
)
196189

197-
get_libc_textual_hdrs(
190+
_libc_textual_hdrs_filegroup(
198191
name = name + "_textual_hdrs",
199192
libs = libc_functions,
200193
)
@@ -229,12 +222,12 @@ def libc_header_library(name, hdrs, deps = [], **kwargs):
229222
**kwargs: All other attributes relevant for the cc_library rule.
230223
"""
231224

232-
get_libc_srcs(
225+
_libc_srcs_filegroup(
233226
name = name + "_hdr_deps",
234227
libs = deps,
235228
)
236229

237-
get_libc_textual_hdrs(
230+
_libc_textual_hdrs_filegroup(
238231
name = name + "_textual_hdrs",
239232
libs = deps,
240233
)

0 commit comments

Comments
 (0)