pw_protobuf_compiler: Depend on Python package When pw_proto_library Python packages are nested in another package, have the .python subtarget wrap the package in which they're nested. pw_proto_library targets originally disabled the .python subtarget when the proto library was nested in another Python package. This made having one pw_proto_library target depend on another difficult, and created an error condition that didn't need to exist. Change-Id: I53fe712d21f9a3d3100b0c3c395abc60fa2c666a Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/47760 Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com> Reviewed-by: Armando Montanez <amontanez@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_protobuf_compiler/docs.rst b/pw_protobuf_compiler/docs.rst index 99e3d18..91c3310 100644 --- a/pw_protobuf_compiler/docs.rst +++ b/pw_protobuf_compiler/docs.rst
@@ -97,6 +97,7 @@ * ``strip_prefix``: Remove this prefix from the source protos. All source and input files must be nested under this path. * ``python_package``: Label of Python package to which to add the proto modules. + The .python subtarget will redirect to this package. **Example**
diff --git a/pw_protobuf_compiler/proto.gni b/pw_protobuf_compiler/proto.gni index 07f4d52..241c666 100644 --- a/pw_protobuf_compiler/proto.gni +++ b/pw_protobuf_compiler/proto.gni
@@ -308,18 +308,11 @@ } if (defined(invoker.python_package) && invoker.python_package != "") { - # If anyone attempts to depend on this Python package, print an error. - pw_error(target_name) { - _pkg = get_label_info(invoker.python_package, "label_no_toolchain") - message_lines = [ - "This proto Python package is embedded in the $_pkg Python package.", - "It cannot be used directly; instead, depend on $_pkg.", - ] - } - foreach(subtarget, pw_python_package_subtargets) { - group("$target_name.$subtarget") { - deps = [ ":${invoker.target_name}" ] - } + # This package is nested in another Python package. Depending on this + # its python subtarget is equivalent to depending on the Python package it + # is nested in. + pw_python_group(target_name) { + python_deps = [ invoker.python_package ] } # This proto library is merged into another package, but create a target to @@ -375,6 +368,7 @@ # strip_prefix: Remove this prefix from the source protos. All source and # input files must be nested under this path. # python_package: Label of Python package to which to add the proto modules. +# The .python subtarget will redirect to this package. # template("pw_proto_library") { assert(defined(invoker.sources) && invoker.sources != [],