angr
angr copied to clipboard
Protobuf Package Definitions
Describe the bug.
The protobufs packages and imports are mismatched.
For example, primitives.proto is package angr.protos but cfg.proto imports it as protos/primitives.proto. It should be imported as angr/protos/primitives.proto instead. You'd have to update your protoc includes in the build process to fix this. We've worked around it for now but this can limit the ability to share/use the CFG externally.
If the package and imports both begin with "angr" then, in theory, an external build can simply include angr's protos and the generated Python imports would be from angr.protos import cfg_pb2 rather than from protos import cfg_pb2.
Additional context.
See https://github.com/protocolbuffers/protobuf/issues/4176.
Currently, my proto does import "protos/cfg.proto" and I pass -I mydir/angr to protoc, where mydir/angr/protos/ contains all the proto from here (duplicates due to #1561). The generated Python import is from protos import cfg_pb2, which needs to be changed to from .angr.protos import cfg_pb2 (relative since we keep duplicates so the build system doesn't need angr). This is the only way to keep the messages compatible. If I fix my proto import to use the correct package with import "angr/protos/cfg.proto", the Python code is generated correctly but now the protobuf library itself fails to recognize the CFG message.
I will address this as soon as I have some time to really understand how importing external protobuf files works. I also need to apply some workaround to the .py files that protobuf generates to replace the absolute imports with relative imports (right now I'm doing that manually).
Protobuf packaging is a bit of a clown show, so I wish you the best of luck!
@ltfish It would be great if you share your understanding of protobuf import system somewhere on the web e.g Medium.
This issue has been marked as stale because it has no recent activity. Please comment or add the pinned tag to prevent this issue from being closed.
This issue has been closed due to inactivity.