Make protobufs respect pkg_path properly
Currently, python protobuf sources are generated as if pkg_path didn't exist, but then are moved into the pkg_path directory after being generated. This means they're generated with import statements in them that don't include the pkg_path. These import statements won't work at all when pkg_path is at least 2 levels deep, but currently erroneously work with a 1 level deep pkg_path because we mistakenly add the top-level modules in a soong-built python zip to the PYTHONPATH. We want to remove those modules from the PYTHONPATH, so the generated protobuf source files have to use the correct imports. Since there are existing cases of code that needs to be updated, guard this new behavior behind a flag, protos_respect_pkg_path. We will set this to true on modules individually as we update them, and then eventually change the default to true and remove this flag. Bug: 247578564 Test: m py_proto_pkg_path_test && out/host/linux-x86/nativetest64/py_proto_pkg_path_test/py_proto_pkg_path_test Change-Id: I3695cf5521837da087592f2ad5350201035b7b0e
This commit is contained in:
18
python/tests/proto_pkg_path/main.py
Normal file
18
python/tests/proto_pkg_path/main.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import sys
|
||||
|
||||
import unittest
|
||||
import mylib.subpackage.proto.test_pb2 as test_pb2
|
||||
import mylib.subpackage.proto.common_pb2 as common_pb2
|
||||
|
||||
print(sys.path)
|
||||
|
||||
class TestProtoWithPkgPath(unittest.TestCase):
|
||||
|
||||
def test_main(self):
|
||||
x = test_pb2.MyMessage(name="foo",
|
||||
common = common_pb2.MyCommonMessage(common="common"))
|
||||
self.assertEqual(x.name, "foo")
|
||||
self.assertEqual(x.common.common, "common")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user