Skip to content

no longer generate empty enum or server files #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions protoc_plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 22.3.0-wip

* No longer generate empty enum (`*.pbenum.dart`) files.
* No longer generate empty server (`*.pbserver.dart`) files.
* Ignore `implementation_imports` for some generated files.

## 22.2.0

* Bump `protobuf` constraint to `^4.1.0`
Expand Down
3 changes: 0 additions & 3 deletions protoc_plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ TEST_PROTO_LIST = \
TEST_PROTO_DIR=$(OUTPUT_DIR)/protos
TEST_PROTO_LIBS=$(foreach f, $(TEST_PROTO_LIST), \
$(TEST_PROTO_DIR)/$(f).pb.dart \
$(TEST_PROTO_DIR)/$(f).pbenum.dart \
$(TEST_PROTO_DIR)/$(f).pbserver.dart \
$(TEST_PROTO_DIR)/$(f).pbjson.dart)
TEST_PROTO_SRC_DIR=test/protos
TEST_PROTO_SRCS=$(foreach proto, $(TEST_PROTO_LIST), \
Expand Down Expand Up @@ -105,7 +103,6 @@ update-pregenerated: $(PLUGIN_PATH) $(PREGENERATED_SRCS)
-Iprotos \
--plugin=protoc-gen-dart=$(realpath $(PLUGIN_PATH)) $(PREGENERATED_SRCS)
find lib/src/gen -name '*.pbjson.dart' -delete
find lib/src/gen -name '*.pbserver.dart' -delete
dart format lib/src/gen

protos: $(PLUGIN_PATH) $(TEST_PROTO_LIBS)
Expand Down
18 changes: 13 additions & 5 deletions protoc_plugin/lib/src/file_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,31 @@ class FileGenerator extends ProtobufContainer {
}

final mainWriter = generateMainFile(config);
final enumWriter = generateEnumFile(config);
final enumWriter = hasEnums ? generateEnumFile(config) : null;

final files = [
makeFile('.pb.dart', mainWriter.toString()),
makeFile('.pbenum.dart', enumWriter.toString()),
if (enumWriter != null) makeFile('.pbenum.dart', enumWriter.toString()),
makeFile('.pbjson.dart', generateJsonFile(config)),
];

if (options.generateMetadata) {
files.addAll([
makeFile('.pb.dart.meta',
mainWriter.sourceLocationInfo.writeToJson().toString()),
makeFile('.pbenum.dart.meta',
enumWriter.sourceLocationInfo.writeToJson().toString())
if (enumWriter != null)
makeFile('.pbenum.dart.meta',
enumWriter.sourceLocationInfo.writeToJson().toString())
]);
}
if (options.useGrpc) {
if (grpcGenerators.isNotEmpty) {
files.add(makeFile('.pbgrpc.dart', generateGrpcFile(config)));
}
} else {
files.add(makeFile('.pbserver.dart', generateServerFile(config)));
if (serviceGenerators.isNotEmpty) {
files.add(makeFile('.pbserver.dart', generateServerFile(config)));
}
}
return files;
}
Expand Down Expand Up @@ -457,10 +460,15 @@ class FileGenerator extends ProtobufContainer {
return count;
}

/// Returns whether this proto file defines any enums (either top level or
/// nested within messages).
bool get hasEnums => enumCount > 0;

/// Returns the contents of the .pbserver.dart file for this .proto file.
String generateServerFile(
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw StateError('not linked');

final out = makeWriter();
_writeHeading(out,
extraIgnores: {'deprecated_member_use_from_same_package'});
Expand Down
10 changes: 0 additions & 10 deletions protoc_plugin/lib/src/gen/dart_options.pbenum.dart

This file was deleted.

10 changes: 0 additions & 10 deletions protoc_plugin/lib/src/gen/google/api/http.pbenum.dart

This file was deleted.

10 changes: 0 additions & 10 deletions protoc_plugin/lib/src/gen/google/protobuf/duration.pbenum.dart

This file was deleted.

2 changes: 1 addition & 1 deletion protoc_plugin/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: protoc_plugin
version: 22.2.0
version: 22.3.0-wip
description: A protobuf protoc compiler plugin used to generate Dart code.
repository: https://github.com/google/protobuf.dart/tree/master/protoc_plugin

Expand Down