Skip to content

Commit 1885219

Browse files
committed
fix(php): Remove public and weak dependencies from generated PHP.
Fixes issue #11146 caused by transitive dependencies referencing removed dependencies in the emitted PHP metadata classes.
1 parent 8385b5e commit 1885219

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/google/protobuf/compiler/php/generator_unittest.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,38 @@ TEST_F(PhpGeneratorTest, ClosedEnumError) {
105105
ExpectErrorSubstring("Can't generate PHP code for closed enum Foo");
106106
}
107107

108+
TEST_F(PhpGeneratorTest, ImportPublic) {
109+
CreateTempFile("common.proto",
110+
R"schema(
111+
syntax = "proto3";
112+
package prototest;
113+
message Common {
114+
string data = 1;
115+
})schema");
116+
117+
CreateTempFile("prototest.proto",
118+
R"schema(
119+
syntax = "proto3";
120+
package prototest;
121+
import public "common.proto";
122+
)schema");
123+
124+
CreateTempFile("usecase.proto",
125+
R"schema(
126+
syntax = "proto3";
127+
package usecasetest;
128+
import "prototest.proto";
129+
message UseCase {
130+
prototest.Common commonUse = 1;
131+
})schema");
132+
133+
RunProtoc(
134+
"protocol_compiler --proto_path=$tmpdir --php_out=$tmpdir "
135+
"common.proto prototest.proto usecase.proto");
136+
137+
ExpectNoErrors();
138+
}
139+
108140
} // namespace
109141
} // namespace php
110142
} // namespace compiler

src/google/protobuf/compiler/php/php_generator.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,12 @@ void GenerateAddFileToPool(const FileDescriptor* file, const Options& options,
10471047
}
10481048
}
10491049

1050+
// Clear public_dependency and weak_dependency since they contain indices
1051+
// into the dependency array which we just modified above. PHP handles
1052+
// dependency loading through initOnce() calls instead.
1053+
file_proto->clear_public_dependency();
1054+
file_proto->clear_weak_dependency();
1055+
10501056
// Filter out all extensions, since we do not support extension yet.
10511057
file_proto->clear_extension();
10521058
RepeatedPtrField<DescriptorProto>* message_type =
@@ -1173,6 +1179,12 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options,
11731179
}
11741180
}
11751181

1182+
// Clear public_dependency and weak_dependency since they contain indices
1183+
// into the dependency array which we just modified above. PHP handles
1184+
// dependency loading through initOnce() calls instead.
1185+
file_proto->clear_public_dependency();
1186+
file_proto->clear_weak_dependency();
1187+
11761188
// Filter out all extensions, since we do not support extension yet.
11771189
file_proto->clear_extension();
11781190
RepeatedPtrField<DescriptorProto>* message_type =

0 commit comments

Comments
 (0)