Skip to content

Commit

Permalink
gn: Use canonical target name for perfetto_proto_library metadata export
Browse files Browse the repository at this point in the history
The perfetto_proto_library generates some metadata (used by the
gen_bazel and gen_android_bp scripts) that references some target.

In one case, it's generating something like
```
'//protos/perfetto/trace/android/:winscope_common:source_set'
```
which is not the canonical way to represent a target in GN (note the
'/:').

The problem is that we use `get_path_info`, which is for handling paths
and not GN target.

Switching to `get_label_info`, plus some string concatenation, produces
the correct target name.

This allows us to remove a workaround in gn_utils.py, that was
introduced just for this.

This is just an internal cleanup and it has no effect on the generated
build files.

Commit fe05d3a("gen_bazel: handle target names containing '/:'")
bypassed the problem by special casing '/:', but that I think '/:' it's
not a valid gn target name.

Change-Id: I319e8bb7df50cc32ad3da5cd83651fe5a99c025e
  • Loading branch information
ddiproietto committed May 7, 2024
1 parent 844f8a8 commit c8e4b77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 5 additions & 1 deletion gn/proto_library.gni
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,11 @@ template("perfetto_proto_library") {
metadata = {
proto_library_sources = invoker.sources
proto_import_dirs = import_dirs_
exports = get_path_info(public_deps_, "abspath")
exports = []
foreach (i, public_deps_) {
# Get the absolute target path
exports += [get_label_info(i, "dir") + ":" + get_label_info(i, "name")]
}
}
forward_variables_from(invoker, vars_to_forward)
}
Expand Down
1 change: 0 additions & 1 deletion tools/gn_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def label_to_target_name_with_path(label):
e.g., //src/perfetto:tests -> src_perfetto_tests
"""
name = re.sub(r'^//:?', '', label)
name = re.sub(r'/:', '/', name)
name = re.sub(r'[^a-zA-Z0-9_]', '_', name)
return name

Expand Down

0 comments on commit c8e4b77

Please sign in to comment.