Skip to content

Commit 1d8a656

Browse files
nbeloglazovzhangskz
authored andcommitted
Disable option sub-location mapping in open-source builds.
We are considering changing the format of locations for options in SourceCodeInfo as the current format conflicts with dot-notation options format and can't be extended to cover them well. Once we update format and make sure it works well for all type of options we'll re-enable it for opensource version. PiperOrigin-RevId: 957355763
1 parent 20102e5 commit 1d8a656

3 files changed

Lines changed: 15 additions & 41 deletions

File tree

‎src/google/protobuf/descriptor.cc‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9288,19 +9288,7 @@ void internal::DescriptorBuilder::OptionInterpreter::UpdateSourceCodeInfo(
92889288
}
92899289

92909290
if (loc_matches) {
9291-
if (loc->path_size() == static_cast<int64_t>(match_src.size() + 1)) {
9292-
int uninterpreted_field = loc->path(match_src.size());
9293-
9294-
SourceCodeInfo_Location* mapped_loc = new_locs.Add();
9295-
*mapped_loc = *loc;
9296-
mapped_loc->mutable_path()->Assign(match_dest.begin(),
9297-
match_dest.end());
9298-
mapped_loc->add_path(uninterpreted_field);
9299-
9300-
// TODO: b/168903973 - recursively process options with aggregate
9301-
// values and add locations. Example: [(my_opt) = {a: 1, b: 2}]
9302-
// Locations of `a` and `b` are not added yet.
9303-
}
9291+
// TODO: b/168903973 - Remove once we update the format.
93049292
// don't copy this row since it is a sub-location that we're removing
93059293
// (or we already mapped it if it's a direct child)
93069294
continue;

‎src/google/protobuf/descriptor_unittest.cc‎

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16274,6 +16274,8 @@ TEST_F(SourceLocationTest, GetSourceLocation) {
1627416274
"rpc Method(A) returns (A.B);"));
1627516275
}
1627616276

16277+
// TODO: b/168903973 - Remove once we update the format.
16278+
1627716279
TEST_F(SourceLocationTest, ExtensionSourceLocation) {
1627816280
SourceLocation loc;
1627916281

@@ -16330,19 +16332,7 @@ TEST_F(SourceLocationTest, InterpretedOptionSourceLocation) {
1633016332

1633116333
EXPECT_FALSE(file_desc->GetSourceLocation(unint, &loc));
1633216334

16333-
SourceCodePath name_path = {FileDescriptorProto::kOptionsFieldNumber,
16334-
FileOptions::kJavaPackageFieldNumber,
16335-
UninterpretedOption::kNameFieldNumber};
16336-
EXPECT_TRUE(file_desc->GetSourceLocation(name_path, &loc));
16337-
EXPECT_THAT(loc,
16338-
MatchesSubstring(kSourceLocationTestInput, "java_package"));
16339-
16340-
SourceCodePath val_path = {FileDescriptorProto::kOptionsFieldNumber,
16341-
FileOptions::kJavaPackageFieldNumber,
16342-
UninterpretedOption::kStringValueFieldNumber};
16343-
EXPECT_TRUE(file_desc->GetSourceLocation(val_path, &loc));
16344-
EXPECT_THAT(loc,
16345-
MatchesSubstring(kSourceLocationTestInput, "\"com.foo.bar\""));
16335+
// TODO: b/168903973 - Remove once we update the format.
1634616336
}
1634716337
{
1634816338
SourceCodePath path = {FileDescriptorProto::kOptionsFieldNumber,
@@ -16355,18 +16345,7 @@ TEST_F(SourceLocationTest, InterpretedOptionSourceLocation) {
1635516345

1635616346
EXPECT_FALSE(file_desc->GetSourceLocation(unint, &loc));
1635716347

16358-
SourceCodePath name_path = {FileDescriptorProto::kOptionsFieldNumber,
16359-
kCustomOptionFieldNumber,
16360-
UninterpretedOption::kNameFieldNumber};
16361-
EXPECT_TRUE(file_desc->GetSourceLocation(name_path, &loc));
16362-
EXPECT_THAT(loc,
16363-
MatchesSubstring(kSourceLocationTestInput, "(test_file_opt)"));
16364-
16365-
SourceCodePath val_path = {FileDescriptorProto::kOptionsFieldNumber,
16366-
kCustomOptionFieldNumber,
16367-
UninterpretedOption::kStringValueFieldNumber};
16368-
EXPECT_TRUE(file_desc->GetSourceLocation(val_path, &loc));
16369-
EXPECT_THAT(loc, MatchesSubstring(kSourceLocationTestInput, "\"foobar\""));
16348+
// TODO: b/168903973 - Remove once we update the format.
1637016349
}
1637116350

1637216351
// Message option

‎src/google/protobuf/retention_test.cc‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,16 @@ TEST(RetentionTest, StripSourceRetentionOptionsWithSourceCodeInfo) {
226226
*pool.FindFileByName("retention.proto"),
227227
/*include_source_code_info=*/true);
228228

229-
// The number of locations is reduced by the number of stripped elements.
230-
EXPECT_EQ(file_descriptor.source_code_info().location_size(), 88);
231-
EXPECT_EQ(stripped_file.source_code_info().location_size(), 73);
229+
FileDescriptorProto stripped_file =
230+
compiler::StripSourceRetentionOptions(*interpreted_desc,
231+
/*include_source_code_info=*/true);
232+
233+
// TODO: b/168903973 - Remove once we update the format.
234+
EXPECT_EQ(interpreted_unstripped_file.source_code_info().location_size(), 64);
235+
236+
// Stripping removes source-retention options (including some sub-fields),
237+
// reducing the location count.
238+
EXPECT_EQ(stripped_file.source_code_info().location_size(), 63);
232239
}
233240

234241
TEST(RetentionTest, RemoveEmptyOptions) {

0 commit comments

Comments
 (0)