Skip to content

Commit c69077d

Browse files
authored
revert the change to not generate empty enum files (#1016)
1 parent 08e7410 commit c69077d

File tree

8 files changed

+80
-39
lines changed

8 files changed

+80
-39
lines changed

protoc_plugin/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Update how we calculate import prefixes ([#1010]); import prefixes are now
44
unique per-library instead of being unique across all generated libraries.
55
* Ignore `unused_import` diagnostics for `*.pbjson.dart` files.
6+
* Revert the change to not generate empty `*.pbenum.dart` files; these can be
7+
exported from other enum files.
68

79
[#1010]: https://github.com/google/protobuf.dart/issues/1010
810

protoc_plugin/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TEST_PROTO_LIST = \
1818
google/protobuf/timestamp \
1919
google/protobuf/type \
2020
google/protobuf/unittest_import \
21+
google/protobuf/unittest_import_public \
2122
google/protobuf/unittest_optimize_for \
2223
google/protobuf/unittest_well_known_types \
2324
google/protobuf/unittest \
@@ -69,7 +70,8 @@ TEST_PROTO_LIST = \
6970
using_any
7071
TEST_PROTO_DIR=$(OUTPUT_DIR)
7172
TEST_PROTO_LIBS=$(foreach f, $(TEST_PROTO_LIST), \
72-
$(TEST_PROTO_DIR)/$(f).pb.dart \
73+
$(TEST_PROTO_DIR)/$(f).pb.dart \
74+
$(TEST_PROTO_DIR)/$(f).pbenum.dart \
7375
$(TEST_PROTO_DIR)/$(f).pbjson.dart)
7476
TEST_PROTO_SRC_DIR=test/protos
7577
TEST_PROTO_SRCS=$(foreach proto, $(TEST_PROTO_LIST), \

protoc_plugin/lib/src/file_generator.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ class FileGenerator extends ProtobufContainer {
232232
}
233233

234234
final mainWriter = generateMainFile(config);
235-
final enumWriter = hasEnums ? generateEnumFile(config) : null;
235+
final enumWriter = generateEnumFile(config);
236236

237237
final files = [
238238
makeFile('.pb.dart', mainWriter.toString()),
239-
if (enumWriter != null) makeFile('.pbenum.dart', enumWriter.toString()),
239+
makeFile('.pbenum.dart', enumWriter.toString()),
240240
// TODO(devoncarew): Consider not emitting empty json files.
241241
makeFile('.pbjson.dart', generateJsonFile(config)),
242242
];
@@ -245,9 +245,8 @@ class FileGenerator extends ProtobufContainer {
245245
files.addAll([
246246
makeFile('.pb.dart.meta',
247247
mainWriter.sourceLocationInfo.writeToJson().toString()),
248-
if (enumWriter != null)
249-
makeFile('.pbenum.dart.meta',
250-
enumWriter.sourceLocationInfo.writeToJson().toString())
248+
makeFile('.pbenum.dart.meta',
249+
enumWriter.sourceLocationInfo.writeToJson().toString())
251250
]);
252251
}
253252
if (options.useGrpc) {
@@ -355,7 +354,7 @@ class FileGenerator extends ProtobufContainer {
355354
}
356355

357356
// Export enums in main file for backward compatibility.
358-
if (enumCount > 0) {
357+
if (hasEnums) {
359358
final url =
360359
config.resolveImport(protoFileUri, protoFileUri, '.pbenum.dart');
361360
importWriter.addExport(url.toString());
@@ -428,7 +427,7 @@ class FileGenerator extends ProtobufContainer {
428427

429428
final importWriter = ImportWriter();
430429

431-
if (enumCount > 0) {
430+
if (hasEnums) {
432431
// Make sure any other symbols in dart:core don't cause name conflicts
433432
// with enums that have the same name.
434433
importWriter.addImport(_coreImportUrl, prefix: coreImportPrefix);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Generated code. Do not modify.
3+
// source: dart_options.proto
4+
//
5+
// @dart = 3.3
6+
7+
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
8+
// ignore_for_file: constant_identifier_names
9+
// ignore_for_file: curly_braces_in_flow_control_structures
10+
// ignore_for_file: deprecated_member_use_from_same_package, library_prefixes
11+
// ignore_for_file: non_constant_identifier_names
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Generated code. Do not modify.
3+
// source: google/api/http.proto
4+
//
5+
// @dart = 3.3
6+
7+
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
8+
// ignore_for_file: constant_identifier_names
9+
// ignore_for_file: curly_braces_in_flow_control_structures
10+
// ignore_for_file: deprecated_member_use_from_same_package, library_prefixes
11+
// ignore_for_file: non_constant_identifier_names
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Generated code. Do not modify.
3+
// source: google/protobuf/duration.proto
4+
//
5+
// @dart = 3.3
6+
7+
// ignore_for_file: annotate_overrides, camel_case_types, comment_references
8+
// ignore_for_file: constant_identifier_names
9+
// ignore_for_file: curly_braces_in_flow_control_structures
10+
// ignore_for_file: deprecated_member_use_from_same_package, library_prefixes
11+
// ignore_for_file: non_constant_identifier_names
Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,36 @@
11
// Protocol Buffers - Google's data interchange format
22
// Copyright 2008 Google Inc. All rights reserved.
3-
// http://code.google.com/p/protobuf/
43
//
5-
// Redistribution and use in source and binary forms, with or without
6-
// modification, are permitted provided that the following conditions are
7-
// met:
8-
//
9-
// * Redistributions of source code must retain the above copyright
10-
// notice, this list of conditions and the following disclaimer.
11-
// * Redistributions in binary form must reproduce the above
12-
// copyright notice, this list of conditions and the following disclaimer
13-
// in the documentation and/or other materials provided with the
14-
// distribution.
15-
// * Neither the name of Google Inc. nor the names of its
16-
// contributors may be used to endorse or promote products derived from
17-
// this software without specific prior written permission.
18-
//
19-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file or at
6+
// https://developers.google.com/open-source/licenses/bsd
307

318
// Author: [email protected] (Kenton Varda)
329
// Based on original Protocol Buffers design by
3310
// Sanjay Ghemawat, Jeff Dean, and others.
3411
//
3512
// A proto file which is imported by unittest.proto to test importing.
36-
// We don't put this in a package within proto2 because we need to make sure
37-
// that the generated code doesn't depend on being in the proto2 namespace.
38-
// In test_util.h we do
39-
// "using namespace unittest_import = protobuf_unittest_import".
4013

4114
syntax = "proto2";
4215

16+
// We don't put this in a package within proto2 because we need to make sure
17+
// that the generated code doesn't depend on being in the proto2 namespace.
18+
// In test_util.h we do
19+
// "using namespace unittest_import = proto2_unittest_import".
4320
package protobuf_unittest_import;
4421

4522
option optimize_for = SPEED;
23+
option cc_enable_arenas = true;
4624

47-
// Excercise the java_package option.
25+
// Exercise the java_package option.
4826
option java_package = "com.google.protobuf.test";
4927

5028
// Do not set a java_outer_classname here to verify that Proto2 works without
5129
// one.
5230

31+
// Test public import
32+
import public "google/protobuf/unittest_import_public.proto";
33+
5334
message ImportMessage {
5435
optional int32 d = 1;
5536
}
@@ -60,3 +41,9 @@ enum ImportEnum {
6041
IMPORT_BAZ = 9;
6142
}
6243

44+
// To use an enum in a map, it must has the first value as 0.
45+
enum ImportEnumForMap {
46+
UNKNOWN = 0;
47+
FOO = 1;
48+
BAR = 2;
49+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Protocol Buffers - Google's data interchange format
2+
// Copyright 2008 Google Inc. All rights reserved.
3+
//
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file or at
6+
// https://developers.google.com/open-source/licenses/bsd
7+
8+
// Author: [email protected] (Pherl Liu)
9+
10+
syntax = "proto2";
11+
12+
package protobuf_unittest_import;
13+
14+
option java_package = "com.google.protobuf.test";
15+
16+
message PublicImportMessage {
17+
optional int32 e = 1;
18+
}

0 commit comments

Comments
 (0)