Commit Graph

82 Commits

Author SHA1 Message Date
Rob Mohr
d1a11983ec bazel: Remove license comments
Change-Id: I9900cb44251315a1c892e07a9e4a9dc38a502ecd
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/54720
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Reviewed-by: Joe Ethier <jethier@google.com>
2021-07-26 18:55:47 +00:00
Joe Ethier
6bdcc3fe33 Add Bazel support for pw_rpc/py and deps
Testing: Verified that pw_rpc bazel target builds locally
No-Docs-Update-Reason: Bazel support still considered experimental

Change-Id: I3b9e11348e4400586c4f69e1e24ba8a102619d3b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/51480
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Joe Ethier <jethier@google.com>
2021-07-26 18:02:20 +00:00
Wyatt Hepler
a352d57ebc pw_build: Prepare for Pylint update
- Fix various style issues raised by Pylint 2.9.3.
- Disable consider-using-with checks because they're overly broad.

Change-Id: I7d0c205bbff972718aa5d52238ef34e5f4fd0930
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/52860
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
2021-07-19 19:36:37 +00:00
Wyatt Hepler
8ec2cf86d5 pw_rpc: Reorganize Nanopb implementation
As with raw, replace "nanopb_" file prefixes with a directory path.

Change-Id: Id7e21069850fbfe61bcc3d644881d5f0411830e6
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/52863
Commit-Queue: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-07-12 20:40:25 +00:00
Wyatt Hepler
c0ea3f9956 pw_rpc: Reorganize raw implementation
Replace "raw_" file prefixes with a directory path. This mirrors the
directory structure of the module and is cleaner to work
with.

Change-Id: I067b7772a83f9707633828119319376324c04e10
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/52862
Commit-Queue: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-07-12 20:26:37 +00:00
Alexei Frolov
d0bda2ad49 pw_rpc: Add client and bidirectional streaming to Python
This implements client and bidirectional streaming RPCs in the
CallbackClient API.

Change-Id: I8f7768b84f03d9d539f99829f3a2b5ff9a60244e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/51680
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Alexei Frolov <frolv@google.com>
2021-07-12 18:22:27 +00:00
Wyatt Hepler
c5b59f1c34 pw_rpc: Client & bidirectional streaming codegen
- Support codegen for raw and Nanopb RPC services.
- Leave a TODO to implement client and bidirectional streaming for the
  Nanopb client.

Change-Id: Ifb69bec13a8ac912d25ddda28a4e26f392d4fed5
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/52522
Reviewed-by: Alexei Frolov <frolv@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-07-10 01:48:51 +00:00
Wyatt Hepler
5ba80646bf pw_rpc: Update protocol for server streams
Update the server-to-client RPC packet types so that the packet type
unambiguously indicates whether it is the first or last packet. This is
already the case for client-to-server RPC packet types.

- Have RESPONSE always be the last packet in the stream. For RPCs
  without a server stream, it includes a payload. Remove
  SERVER_STREAM_END.
- Introduce the SERVER_STREAM packet, to parallel the CLIENT_STREAM
  packet.
- Update the server and client code and tests. Test that old-style
  streaming RPCs still work correctly.
- Refactor the duplicate MessageOutput class into a FakeChannelOutput
  used by both Nanopb and raw RPCs.
- In C++, don't encode default-valued payload and status fields.

Change-Id: I218772dad6c2981dda5f032f298ea43ee5e08b4d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/49822
Commit-Queue: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-06-23 00:56:39 +00:00
Wyatt Hepler
a9211165ba pw_rpc: Protocol updates for client streams
- Add a CLIENT_STREAM packet for messages in client streams.
- Rename CANCEL_SERVER_STREAM to CANCEL, since it applies to all RPC
  types.
- Remove server responses to CANCEL packets from protocol description.
- Document cancellation of unary RPCs.

Change-Id: I3b15beb2de94f318fac58fc3d682aefe41056676
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/48800
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-06-15 23:39:53 +00:00
Nathaniel Brough
b4f4e7a10e pw_rpc: Adds Bazel support for RPC
Adds initial support for c++ RPC libraries. This change only
supports the raw RPC protocol.

Change-Id: Icdecc14f1b8be03120330094793315f807deb3ec
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/43921
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-06-15 00:52:31 +00:00
Alexei Frolov
bebba90c01 pw_rpc: Use pw_function callbacks in RPC client
This updates the nanopb RPC client to use pw::Function for callbacks
instead of custom virtual interfaces.

Change-Id: I7c548cde00223ec32e45cc831fe7f9f79577842b
Requires: pigweed-internal:13201
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/48484
Reviewed-by: Wyatt Hepler <hepler@google.com>
2021-06-11 16:30:14 +00:00
Alexei Frolov
2b54ee66f6 pw_rpc: Generate aliases for nanopb client call types
Nanopb client calls are templated and can have long type names. For
example, the client call type for the nanopb EchoService.Echo method is

  NanopbClientCall<UnaryResponseHandler<pw_rpc_EchoMessage>>

This updates the generated RPC client code to provide aliases for the
client call types of each method within the service client. The above
type can now be replaced with

  EchoServiceClient::EchoCall

which is much more legible.

Change-Id: I184e34b2b52b120b83227be82c4a411dcd4941ec
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/42929
Commit-Queue: Alexei Frolov <frolv@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
2021-05-17 19:15:46 +00:00
Wyatt Hepler
4925ba2d10 pw_rpc.console_tools: Support aliasing renamed commands
- The alias_deprecated_command function creates an alias that redirects
  from an old RPC command name to a new name.
- Move console_tools.Watchdog tests to their own file.

Change-Id: Ie7071462e5c17e5782fb549cc2f15aa19e64bbf0
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/44120
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-05-10 21:42:57 +00:00
Wyatt Hepler
faea880913 pw_rpc.console_tools: Context class; function helpers
- Rework the cumbersome multi_client_terminal_variables function into a
  pw_rpc.console_tools.Context class. The class can be extended if
  needed.
- Provide functions.help_as_repr that wraps a function so that its
  __repr__ displays help information. This is helpful for defining
  commands in an interactive console.
- Display all variables, not just RPCs, in the CommandHelper.

Requires: pigweed-internal:11382
Change-Id: I9a4dfc25473f6cf878f7855602a4f2334313de29
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/41120
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-04-15 17:52:00 +00:00
Wyatt Hepler
4ea2de8fa5 pw_rpc: RPC console helpers
The multi_client_terminal_variables function sets up local variables for
use in an RPC terminal with one or more RPC clients.

Change-Id: I6e53472af157aea3074671491528ec0e9b84bca4
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/40141
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-04-13 23:57:56 +00:00
Wyatt Hepler
e0ae9b10b8 pw_rpc: Python client support for keeping RPCs open
- Support opening an RPC without calling it in the core pw_rpc client.
- Provide a keep_open option so the client keep RPCs going even if they
  are completed.

Change-Id: Idec8247f9ee0b432c0bfb5dbcf1d08ae1e27daea
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/39823
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-04-06 18:28:49 +00:00
Wyatt Hepler
2981da2fbe pw_rpc: Remove accidental Python dependency
pw_build is only needed for tests.

Change-Id: I7d27dbfc3d22a4a055b815f147e99c3d4d52a631
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/39988
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-04-06 17:57:09 +00:00
Wyatt Hepler
c2a520cd98 pw_rpc: Make log messages more specific
Also remove unnecessary pylint: disable comment.

Change-Id: I3acd427c8ea25d695f727787c74d39bfc0926a1f
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/39641
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-04-02 18:38:08 +00:00
Wyatt Hepler
1c00790faf pw_rpc: Reorganize Python console_tools module
Split console_tools.py into a console_tools subpackage with watchdog and
console modules.

Change-Id: I0a4ee25b747a2352516ca25eba57b61a087246eb
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/39621
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2021-03-31 21:40:32 +00:00
Wyatt Hepler
df38ed1938 pw_rpc: Generate RPC definition stubs separately
- Define an interface for generating stubs.
- Generate the method implementation stubs outside the class.
- Share more code between raw and Nanopb RPC stub generation.
- Skip empty names in the C++ namespace to avoid outputting "::".

Change-Id: Ic00b81ae5af07e89408962454432fa227033b904
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/39201
Commit-Queue: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-03-30 00:13:40 +00:00
Wyatt Hepler
821d937a44 pw_rpc: Cancel streaming RPCs when aborted
Cancel server streaming RPCs if they time out or if iteration is
aborted by an exception (such as KeyboardInterrupt).

Change-Id: Ib6a29c1456e600937129830fdfa2cabeb76d2aca
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/39323
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-03-29 18:26:50 +00:00
Wyatt Hepler
ba325e410e pw_rpc: Merge pw_rpc protos into the pw_rpc package
This merges the pw_rpc_protos pw_proto_library Python package into
pw_rpc.

Requires: pigweed-internal:10840
Change-Id: Ib510571d75281d29d2a6719950b33ec09d0a5b9d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36505
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Joe Ethier <jethier@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-03-16 18:32:25 +00:00
Wyatt Hepler
38f8708718 pw_rpc: Check Nanopb request/response types
Ensure that Nanopb method implementations use the correct request and
response types. Using the wrong struct type will be a compilation error.

Change-Id: I9d300a108d76d014cb7699a72b7526b5b3e2d82e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/33701
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-02-26 04:27:56 +00:00
Wyatt Hepler
9e1262f189 pw_rpc: Class for a 'help' command in a console
Change-Id: I48351dd80de515398cc29f60ac2788ce60f76489
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/33127
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-02-20 00:05:46 +00:00
Wyatt Hepler
830d26d0b5 pw_rpc: Documentation update
- Add documentation for the pw_rpc Python package.
- Discuss using proto3 instead of proto2.
- Add "other_deps" to pw_doc_group for expressing arbitrary deps.

Change-Id: I3c8baf2a7986a7d06721d76278794201259815a7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/33104
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-02-18 19:40:05 +00:00
Wyatt Hepler
969f44ef3f pw_rpc: console_tools module and Watchdog class
Create a simple watchdog class that could be used to track connection
state in a pw_rpc console.

Change-Id: I943b514d7994e78ef52898e639c691e5b6c2c046
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/33100
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Jennifer Silva <jennifersilva@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-02-17 23:46:52 +00:00
Wyatt Hepler
625a232c7a pw_protobuf_compiler: Improved proto repr
- Support nested messages, enums, oneof, mappings, optional fields, and
  repeated fields in the proto_repr function.
- Display only hexadecimal for bytes when fewer than half the characters
  are ASCII.
- Add the flag for optional fields in proto3 to dynamic proto
  compilation so that optional fields can be used in tests.

Change-Id: I87dd646de1e339e80ceec729476af89548af21e5
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/32880
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-02-17 00:21:25 +00:00
Wyatt Hepler
cc9d2e9564 pw_rpc: Python client improvements
- Add separate methods for response, completion, and error to the
  ClientImpl interface. This allows explicit handling of errors by the
  client.
- In the callback_client impl, raise exceptions for server errors.
- Simplify the callback_client's invoke method.
- Add pw_rpc_timeout_s to RPC method tab completion.

Change-Id: I1a2214057147c0d1b2547973da1b775f76e36d60
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/31582
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-02-08 19:55:38 +00:00
Wyatt Hepler
6531f3e420 pw_unit_test: Handle bad first response; timeouts
- Check that the first message is a "test_case_start" message. This
  prevents undefined variable errors if the first message is dropped.
- Support providing a timeout to use for the pw.unit_test.Run RPC.

Change-Id: I3f1df140cb07097969c6d7cf79b9c30a21172458
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/32140
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-02-08 19:13:33 +00:00
Wyatt Hepler
a2970c559a pw_build: Python Mypy updates
- Pass all files to Mypy rather than the directory, in case tests
  happen to reside at different paths.
- Remove unnecessary aliases of packet_pb2 members.
- Move Python requirements that apply throughout the Python build from
  pw_presubmit to a pw_python_requirements target in pw_build.
- Update to Mypy 0.800 and mypy-protobuf 2.2.

Change-Id: I07ea07fb864ca4cd79fa5c0389e03146eca2b755
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/31600
Reviewed-by: Rob Mohr <mohrr@google.com>
2021-02-04 21:19:19 +00:00
Wyatt Hepler
9174147f71 pw_protobuf_compiler: Avoid duplicate protobuf Python packages
For compatibility with Python packaging, each pw_protobuf_library target
must have a unique root directory for its protos. If this is violated,
the setup.py for the Python package is generated multiple times,
resulting in flaky builds.

This change ensures that no two pw_proto_library targets generate the
same Python package and fixes existing conflicts in the Pigweed repo.

Change-Id: Icbc13ceeb2fd329bc4fbf1e14ec039e98dc7e483
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/31740
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-02-03 19:36:05 +00:00
Alexei Frolov
10945aaa4c pw_rpc: Remove generated Python packet proto
This removes the generated packet proto code that was checked in and
replaces it with the proto package generated by the build.

Change-Id: I640f7e55cbd759af1672702597f15fe19fd968d5
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/26702
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Alexei Frolov <frolv@google.com>
2021-02-01 20:51:22 +00:00
Wyatt Hepler
6554c14437 pw_protobuf_compiler: Support proto3 optional fields
proto3 now allows specifying optional fields. These fields behave
equivalently to proto2 optional fields and allow API users to detect
whether the field is present in the proto.

- Have the pw_rpc protoc plugins indicate proto3 optional field support.
- Require mypy-protobuf 1.24 or later for proto3 optional field support.
- Provide the flag for proto3 optional fields to protoc.

Change-Id: I66ba3a280cfc9b5c4d1ff42109a6e1d3d691b271
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/31320
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2021-02-01 17:40:50 +00:00
Wyatt Hepler
cddc5cda87 pw_rpc: Timeouts in Python pw_rpc client
The callback_client implementation allows specifying a default timeout
for unary and server streaming RPCs. The timeout can be overridden for
an individual RPC call. If no response is received by the timeout, an
RpcTimeout exception is raised.

Change-Id: I932bb6ebbf3bf157adb40bc0536a529c8411c221
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/31140
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-01-29 16:58:43 +00:00
Wyatt Hepler
620b3e0a14 pw_build: python_test_deps for Python packages
Split python_test_deps from python_deps. This makes the true
dependencies clearer and prevents circular dependencies in some cases
(pw_protobuf_compiler's tests depend on compiled protobufs).

Change-Id: I97dcba908995ef281850105d0cecafd0d87522e8
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/30561
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-01-25 19:57:00 +00:00
Wyatt Hepler
438caa0ddb pw_build: Make GN Python installation more robust
- Since protobuf Python packages are generated and installed from the
  build directory now, add dependencies on package installs in the
  build. This ensures packages are properly installed before tests or
  linting.
- Instantiate all Python actions in the default toolchain. This prevents
  duplicate instantiations of Python actions for each toolchain, which
  causes flakiness as packages are reinstalled for each toolchain.
- Add python_deps to pw_python_action that Python actions can depend on
  Python package installations.
- Add various missing dependencies between Python packages.

Change-Id: I4ec34f06c04014b3552cc1b60aa506ac9a89b329
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/30000
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
2021-01-22 04:42:12 +00:00
Wyatt Hepler
80baa7dc44 pw_rpc: Wrapper for unary responses
- Provide function that prints protobufs in a repr-like style.
- Return a UnaryResponse named tuple instead of a plain tuple from unary
  RPCs in pw_rpc.callback_client.

Change-Id: Iaccdb1b599ab4052b63f2dec810e768dc588fcb6
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/30020
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2021-01-19 23:33:18 +00:00
Wyatt Hepler
45adfce68e Python: Restore missing local deps in setup.py
Since Python packages are installed by GN now, packages are installed in
the correct order. This allows local deps to be fully expressed.

Change-Id: I057cc0902b16da3480f73520281eb52391236a63
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/27901
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
2020-12-16 20:46:28 +00:00
Wyatt Hepler
ac357deb34 pw_rpc: Handle duplicate generated proto message types
- google.protobuf.message_factory may generate new, unique message types
  rather than reusing previously generated classes. The new types are
  essentially identical to others and share the same descriptor
  instance. When working with pw_rpc methods, accept any message type
  that shares the same descriptors.
- Move pw_rpc.descriptors.Method tests to a new file and expand them to
  cover this case.

Change-Id: I46a7823e086c0bbf26ecd5db3017bed0f7ae27e0
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/27160
Commit-Queue: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2020-12-10 03:41:04 +00:00
Wyatt Hepler
2611387f5d pw_rpc: Python callback_client improvements
- Fix the RPC help strings, which were showing the request protobuf as
  the function name.
- Use __dir__ and __getattr__ instead of actually setting members on
  nested packages. This makes it simpler to update the packages after
  they're created.

Change-Id: I4dc594c74c452a14a7da4520a90b461606751413
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/27060
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
2020-12-09 01:58:26 +00:00
Wyatt Hepler
ddbfa1c6e9 pw_rpc: Provide detailed RPC help in RPC client
Create detailed help strings for methods in pw_rpc.callback_client.

Change-Id: I257ee56c25970923c708d58a3315aeb100473197
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/26980
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2020-12-08 03:25:52 +00:00
Alexei Frolov
7085777683 pw_rpc: Support cross-module request and response types
- Load request and response protos from their own files instead of
  assuming they're defined in the same module.
- Don't invoke protoc if no proto file paths are provided.

Change-Id: I44ceedf0ddcb0751368d41d75de3316cf21c34f2
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/26740
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Alexei Frolov <frolv@google.com>
2020-12-04 18:25:51 +00:00
Wyatt Hepler
8ce9013bfd pw_build: Support specifying mypy/pylint config
- Add pylintrc and mypy_ini options to the pw_python_package template.
  These can be used to specify configuration files to use for Pylint and
  Mypy.
- Run pylint and mypy from the setup directory. This allows tools to
  find per-package configuration files (if they aren't specified by the
  pylintrc or mypy_ini arguments).
- Fix some incorrect import ordering that Pylint detects now that it
  runs from package directories. PEP8 states imports should be grouped
  by standard library, third party, and local package imports.

Change-Id: I8017341178ac5920d623ebbed4535432d69527c3
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/26700
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
2020-12-04 17:59:45 +00:00
Wyatt Hepler
97d65aa777 pw_rpc: Tab completion for message fields
Update RPC function signatures to have request proto fields as keyword
arguments. Include type annotations and default values. This allows for
tab completion of arguments in the IPython shell, as well as more
detailed and useful help messages.

Change-Id: I479a344be249a013f6325cf20b3abf0175977b9c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/26560
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
2020-12-02 23:51:06 +00:00
Wyatt Hepler
8779bcd0e7 pw_rpc: Generate service implementation stubs
- Generate a service implementation stub in the RPC proto header. This
  can be used as a reference or copied when implementing a service.
- Expand the documentation for code generation.
- Reduce code duplication in codegen.
- Remove codegen_test.py, which was not running because of a missing
  unittest.main() line. The test was intended as an end-to-end test for
  RPC codegen, but it was out of date and is no longer necessary because
  the C++ codegen tests cover it.

Change-Id: Ie63f75da523b8746a849909d00f6a66c37767f40
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/26161
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
2020-12-01 18:01:46 +00:00
Wyatt Hepler
afd2914e24 pw_rpc: Support testing services with mixed protobuf libraries
- Replace the public internal method lookup generated functions with a
  private array of method IDs. Create a MethodLookup class that is
  friended by generated services to access this array.
- Use the generated method ID array to support method lookup in services
  with multiple different protobuf implementations (Nanopb and raw).
- Ensure that the correct method implementation is selected when looking
  up a method at compile time. This prevents accidentally accessing a
  Nanopb method as a raw method or vice versa in a test method context.

Change-Id: I0ea334c02ae7c29e50099aa5bcfa975df625d15e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/25740
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
2020-11-23 22:05:07 +00:00
Wyatt Hepler
e95bd72668 pw_rpc: Check RPC method signature; improve errors
- Fix issue where an RPC method could be implemented with the signature
  of a different RPC type. Pass the expected method type when methods
  are created and check that it matches the type deduced from the method
  signature.
- Reduce code duplication to limit the number of places where
  compilation errors occur.
  - Combine variable RPC method traits classes into MethodTraits.
  - Move all Method creation functionality into the method classes.
  - Put the final method invocation logic into one function that
    supports member functions or static functions.
- Consolidate error messages for incorrect method signatures into one
  place. Expand the messages and describe the expected function
  signature.

Change-Id: Iae3c6d32df715e877e8c977ccd2232814ef590a7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/25641
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
2020-11-23 21:43:58 +00:00
Wyatt Hepler
d9336a4cad pw_protobuf_compiler: Pass plugin paths
- Rather than relying on Python entry point scripts to get paths to
  protoc plugins, pass the paths to the generate_protos.py script. This
  works in environments where the Python entry points are not available.
- Use unique paths for generated proto code in the GN build. This allows
  multiple GN targets to generate code from the same .proto files. The
  CMake build already worked like this.
- Cleanup and reduce code duplication in the CMake and GN proto
  generation code.
- Support Windows builds: generate .bat wrapper script for plugins, fix
  compilation issue that affects some older compilers.

Change-Id: Iab27a3d193d6008567b324dc1c4e5f540894b8ff
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24380
Commit-Queue: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Zoltan Szatmary-Ban <szatmz@google.com>
2020-11-12 17:28:22 +00:00
Alexei Frolov
8f553de4b6 pw_rpc: Add RawTestMethodContext
This change adds a TestMethodContext class for raw RPC methods. Its API
is identical to the nanopb one, but using byte spans for requests and
responses instead of structs.

Change-Id: Icf92f026882bcb6623478762d01bfde4e2deadc2
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/23170
Commit-Queue: Alexei Frolov <frolv@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
2020-11-03 22:00:25 +00:00
Alexei Frolov
a56482ebb8 pw_rpc: Client-side nanopb code generation
This updates the pw_rpc's nanopb codegen to output a service client
class for every service in a proto file, containing member functions to
invoke each of the service's methods.

Change-Id: I6bfbb76982e7a8be03eb2f13d50085b781e880a2
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/19260
Commit-Queue: Alexei Frolov <frolv@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
2020-10-28 17:13:31 +00:00