You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3d6b6ac
Browse filesBrowse the repository at this point in the historyBrowse files
Do not retain a name string for generated module maps
Copybara Import from #789
BEGIN_PUBLIC
Do not retain a name string for generated module maps (#789)
Module maps generated for a target are named after the target's label. Since the generated module map file is declared by that very target, the name can be derived on demand from the file's owner label, which the `File` object already retains. The `name` field of the module map struct becomes optional, with `None` meaning "named after the label of the target that generated the module map file", and two central helpers (`get_module_map_name`, `get_module_map_label`) derive the string form and the `Label` form where needed.
This fixes the round-trip bug originally addressed in #633, but avoids the memory regression that caused it to be rolled back in b81b6e4 (because retaining `Label` objects increased memory usage overall). Deriving the name on demand retains nothing extra as the owner label is already retained by the `File` and all name materializations are transient only (such as in `map_each` callbacks).
Names are now the unambiguous canonical label string, except that main repository labels drop the leading `@@` (`//pkg:lib`), keeping the traditional module name format. Special module maps (the crosstool module map, ObjC internal module maps) keep their explicitly provided names.
Closes#789
END_PUBLIC
Startblock:
* // Put other blockers before this line to avoid churning.
* has lgtm
* is approved
* and then
* all comments are resolved
* and then
*[] allows unknown commit
COPYBARA_INTEGRATE_REVIEW=#789 from fmeum:module-map-label 6884865
PiperOrigin-RevId: 964972527
Change-Id: If97a7c4491d670e825b621e80541a064ffe8769f
Copy file name to clipboardExpand all lines: cc/private/cc_info.bzl
+72-4Lines changed: 72 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -152,23 +152,91 @@ _ModuleMapInfo = provider(
152
152
"ModuleMapInfo",
153
153
fields= {
154
154
"file": "The module map file.",
155
-
"name": "The name of the module.",
155
+
"name": "The name of the module or None if the module is named after the label of the target that generated the module map file (see get_module_map_name).",
156
156
},
157
157
)
158
158
159
-
defcreate_module_map(*, file, name):
159
+
defcreate_module_map(*, file, name=None):
160
160
"""
161
161
Creates a module map struct.
162
162
163
163
Args:
164
164
file: The module map file.
165
-
name: The name of the module.
165
+
name: The name of the module. If None (the default), the module is
166
+
named after the label of the target that generated the module map
167
+
file. Prefer the default: it avoids retaining a name string per
168
+
module map as the name is derived on demand from `file.owner`.
166
169
Returns:
167
170
A module map struct.
168
171
"""
169
172
check_private_api()
170
173
return_ModuleMapInfo(file=file, name=name)
171
174
175
+
defmodule_map_name_for_label(label):
176
+
"""
177
+
Returns the module name for a module map named after the given label.
178
+
179
+
The name is the label's unambiguous canonical form, except that
180
+
main-repository labels do not carry the leading double-at prefix (see
181
+
get_module_map_name).
182
+
183
+
Args:
184
+
label: The Label the module is named after.
185
+
Returns:
186
+
The name of the module as a string.
187
+
"""
188
+
label_string=str(label)
189
+
190
+
# buildifier: disable=canonical-repository
191
+
iflabel_string.startswith("@@//"):
192
+
returnlabel_string[2:]
193
+
returnlabel_string
194
+
195
+
defget_module_map_name(module_map):
196
+
"""
197
+
Returns the name of the module described by a module map struct.
198
+
199
+
Module maps generated for a target are named after the target's label,
200
+
rendered in its unambiguous canonical form, except that main-repository
201
+
labels do not carry the leading double-at prefix (for example "//pkg:lib"
202
+
for a main-repository target). Names of targets in external repositories
203
+
are thus valid label strings, while main-repository names match the
0 commit comments