diff --git a/Makefile.am b/Makefile.am index 564bff48a9..d0f033af79 100644 --- a/Makefile.am +++ b/Makefile.am @@ -656,6 +656,7 @@ php_EXTRA_DIST= \ php/tests/map_field_test.php \ php/tests/memory_leak_test.php \ php/tests/php_implementation_test.php \ + php/tests/proto/test_import_descriptor_proto.proto \ php/tests/proto/test_include.proto \ php/tests/proto/test.proto \ php/tests/proto/test_prefix.proto \ diff --git a/php/src/Google/Protobuf/Internal/MapField.php b/php/src/Google/Protobuf/Internal/MapField.php index f65bd9b864..55cc12ce85 100644 --- a/php/src/Google/Protobuf/Internal/MapField.php +++ b/php/src/Google/Protobuf/Internal/MapField.php @@ -155,7 +155,6 @@ function checkKey($key_type, &$key) GPBUtil::checkString($key, true); break; default: - var_dump($key_type); trigger_error( "Given type cannot be map key.", E_USER_ERROR); diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 0fb6cdc006..887c86ca6e 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -71,7 +71,6 @@ class Message return; } $pool = DescriptorPool::getGeneratedPool(); - var_dump(get_class($this)); $this->desc = $pool->getDescriptorByClassName(get_class($this)); foreach ($this->desc->getField() as $field) { $setter = $field->getSetter(); diff --git a/php/tests/gdb_test.sh b/php/tests/gdb_test.sh index 484e2edfbb..0809bef3b9 100755 --- a/php/tests/gdb_test.sh +++ b/php/tests/gdb_test.sh @@ -3,7 +3,7 @@ # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which # phpunit` --bootstrap autoload.php tmp_test.php # -gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php encode_decode_test.php +gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php well_known_test.php # # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php # diff --git a/php/tests/proto/test_import_descriptor_proto.proto b/php/tests/proto/test_import_descriptor_proto.proto new file mode 100644 index 0000000000..2a19940dec --- /dev/null +++ b/php/tests/proto/test_import_descriptor_proto.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +import "google/protobuf/descriptor.proto"; + +message TestImportDescriptorProto { + extend google.protobuf.MethodOptions { + int32 a = 72295727; + } +} + +extend google.protobuf.MethodOptions { + int32 a = 72295728; +} + diff --git a/php/tests/well_known_test.php b/php/tests/well_known_test.php index 40ff1c8f03..0c2aec13a9 100644 --- a/php/tests/well_known_test.php +++ b/php/tests/well_known_test.php @@ -4,8 +4,14 @@ use Google\Protobuf\GPBEmpty; class WellKnownTest extends PHPUnit_Framework_TestCase { - public function testNone() { - $msg = new GPBEmpty(); + public function testNone() + { + $msg = new GPBEmpty(); + } + + public function testImportDescriptorProto() + { + $msg = new TestImportDescriptorProto(); } } diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index d24e1e5ebf..4d475b1f54 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -674,6 +674,12 @@ void GenerateAddFileToPool(const FileDescriptor* file, bool is_descriptor, } else { for (int i = 0; i < file->dependency_count(); i++) { const std::string& name = file->dependency(i)->name(); + // Currently, descriptor.proto is not ready for external usage. Skip to + // import it for now, so that its dependencies can still work as long as + // they don't use protos defined in descriptor.proto. + if (name == kDescriptorFile) { + continue; + } std::string dependency_filename = GeneratedMetadataFileName(name, is_descriptor); printer->Print( @@ -685,6 +691,26 @@ void GenerateAddFileToPool(const FileDescriptor* file, bool is_descriptor, FileDescriptorSet files; FileDescriptorProto* file_proto = files.add_file(); file->CopyTo(file_proto); + + // Filter out descriptor.proto as it cannot be depended on for now. + RepeatedPtrField* dependency = file_proto->mutable_dependency(); + for (RepeatedPtrField::iterator it = dependency->begin(); + it != dependency->end(); ++it) { + if (*it != kDescriptorFile) { + dependency->erase(it); + break; + } + } + + // Filter out all extensions, since we do not support extension yet. + file_proto->clear_extension(); + RepeatedPtrField* message_type = + file_proto->mutable_message_type(); + for (RepeatedPtrField::iterator it = message_type->begin(); + it != message_type->end(); ++it) { + it->clear_extension(); + } + string files_data; files.SerializeToString(&files_data); diff --git a/tests.sh b/tests.sh index 8c56172dbe..edb37da7ac 100755 --- a/tests.sh +++ b/tests.sh @@ -362,6 +362,7 @@ generate_php_test_proto() { ../../src/protoc --php_out=generated proto/test.proto proto/test_include.proto proto/test_no_namespace.proto proto/test_prefix.proto pushd ../../src ./protoc --php_out=../php/tests/generated google/protobuf/empty.proto + ./protoc --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto popd popd }