pw_protobuf_compiler: Default python packages to include directory
The typical name for the pw_proto_library target in PW modules is
"protos", which creates a python package called just "protos". This is
generally not a problem for the build since the generated "protos"
packages from different modules would normally install different files.
However, when collecting all the .whl files with pw_python_wheels()
having two package files with the same name creates a conflict.
Make the python package name for the generated pw_proto_library()
".python" target include the directory name too. This only affects
pw_proto_library() targets have have neither python_module_as_package
defined, always using the name of the single source as package name, nor
python_package defined, using the provided python package instead.
Change-Id: Ib4d2e07f4959bde51ea6c27337fdbe9b7e016291
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/110650
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Alex Deymo <deymo@google.com>
diff --git a/pw_protobuf_compiler/proto.gni b/pw_protobuf_compiler/proto.gni
index 11cb828..99decc7 100644
--- a/pw_protobuf_compiler/proto.gni
+++ b/pw_protobuf_compiler/proto.gni
@@ -382,9 +382,17 @@
# Create a Python package with the generated source files.
pw_python_package(target_name) {
forward_variables_from(invoker, _forwarded_vars)
+ _target_dir =
+ get_path_info(get_label_info(":${invoker.base_target}", "dir"),
+ "abspath")
generate_setup = {
metadata = {
- name = invoker.base_target
+ # Default to a package name that include the full source path to avoid
+ # conflicts with other packages when collecting all the .whl files
+ # with pw_python_wheels().
+ name =
+ string_replace(string_replace(_target_dir, "//", ""), "/", "_") +
+ "_" + invoker.base_target
# The package name should match where the __init__.py lives. If
# module_as_package is specified use that for the Python package name.