Inject options in nanopb .options files into the protobuf files used for code generation#922
Conversation
…for code generation
There was a problem hiding this comment.
Pull request overview
Adds tooling to inject nanopb .options constraints (e.g. max_size, int_size, max_count) directly into the temporary .proto files used by the Python protobuf code generator, so that the generated *_pb2.py descriptors carry those nanopb annotations and can be inspected at runtime via field.GetOptions().Extensions[nanopb_pb2.nanopb]. The bulk of the diff is regenerated *_pb2.py files reflecting the new embedded options.
Changes:
- New
bin/inject_nanopb_options.pyscript that parses a nanopb.optionsfile and rewrites field declarations in a.protofile to include inline(nanopb).*field options, adding ananopb.protoimport as needed. bin/regen-protobufs.shnow invokes the injector for every.options/.protopair before running protoc.- Regenerated
_pb2.pydescriptors across the protobuf package now contain serialized nanopb field options, along with the correspondingnanopb_pb2imports and updated_serialized_start/_serialized_endoffsets.
Reviewed changes
Copilot reviewed 1 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| bin/inject_nanopb_options.py | New script that injects nanopb .options into proto field declarations. |
| bin/regen-protobufs.sh | Calls the injector for each .options file before generating Python code. |
| meshtastic/protobuf/admin_pb2.py | Regenerated with embedded nanopb field options and updated offsets. |
| meshtastic/protobuf/apponly_pb2.py | Regenerated to embed nanopb settings option. |
| meshtastic/protobuf/atak_pb2.pyi | Regenerated stub; lost the epw trailing comment docstring. |
| meshtastic/protobuf/cannedmessages_pb2.py | Regenerated with messages max_size option. |
| meshtastic/protobuf/channel_pb2.py | Regenerated with PSK/name/index nanopb options. |
| meshtastic/protobuf/clientonly_pb2.py | Regenerated with DeviceProfile string size options. |
| meshtastic/protobuf/config_pb2.py | Regenerated with many size/int_size options across configs. |
| meshtastic/protobuf/connection_status_pb2.py | Regenerated with WiFi SSID size option. |
| meshtastic/protobuf/device_ui_pb2.py | Regenerated with UI int_size and string size options. |
| meshtastic/protobuf/deviceonly_pb2.py | Regenerated with UserLite/NodeInfoLite size options. |
| meshtastic/protobuf/interdevice_pb2.py | Regenerated with NMEA max size option. |
| meshtastic/protobuf/module_config_pb2.py | Regenerated with module config size/int_size options. |
| meshtastic/protobuf/mqtt_pb2.py | Regenerated with MapReport string size options. |
| meshtastic/protobuf/rtttl_pb2.py | Regenerated with ringtone max size. |
| meshtastic/protobuf/serial_hal_pb2.py | Regenerated with serial HAL data/error size options. |
| meshtastic/protobuf/storeforward_pb2.py | Regenerated with text max size option. |
| meshtastic/protobuf/telemetry_pb2.py | Regenerated with int_size/repeated count options. |
| meshtastic/protobuf/xmodem_pb2.py | Regenerated with seq/crc/buffer nanopb options. |
Files not reviewed (19)
- meshtastic/protobuf/admin_pb2.py: Language not supported
- meshtastic/protobuf/apponly_pb2.py: Language not supported
- meshtastic/protobuf/atak_pb2.py: Language not supported
- meshtastic/protobuf/cannedmessages_pb2.py: Language not supported
- meshtastic/protobuf/channel_pb2.py: Language not supported
- meshtastic/protobuf/clientonly_pb2.py: Language not supported
- meshtastic/protobuf/config_pb2.py: Language not supported
- meshtastic/protobuf/connection_status_pb2.py: Language not supported
- meshtastic/protobuf/device_ui_pb2.py: Language not supported
- meshtastic/protobuf/deviceonly_pb2.py: Language not supported
- meshtastic/protobuf/interdevice_pb2.py: Language not supported
- meshtastic/protobuf/mesh_pb2.py: Language not supported
- meshtastic/protobuf/module_config_pb2.py: Language not supported
- meshtastic/protobuf/mqtt_pb2.py: Language not supported
- meshtastic/protobuf/rtttl_pb2.py: Language not supported
- meshtastic/protobuf/serial_hal_pb2.py: Language not supported
- meshtastic/protobuf/storeforward_pb2.py: Language not supported
- meshtastic/protobuf/telemetry_pb2.py: Language not supported
- meshtastic/protobuf/xmodem_pb2.py: Language not supported
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #922 +/- ##
=======================================
Coverage 61.57% 61.57%
=======================================
Files 25 25
Lines 4448 4448
=======================================
Hits 2739 2739
Misses 1709 1709
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This will let us look at things like max lengths, ostensible int sizes, and things like that if we want to, or library consumers want to.