From ceacc7493c53e67d52f34ef62ddad1ad952521dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20A=C4=9Facan?= Date: Thu, 8 May 2025 11:24:03 +0100 Subject: [PATCH] Sort input proto files before processing This makes the plugin generate identical files when command line argument orders change. Fixes #952. --- protoc_plugin/CHANGELOG.md | 3 +++ protoc_plugin/lib/src/code_generator.dart | 3 +++ protoc_plugin/pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/protoc_plugin/CHANGELOG.md b/protoc_plugin/CHANGELOG.md index 4ee43218f..ed3665388 100644 --- a/protoc_plugin/CHANGELOG.md +++ b/protoc_plugin/CHANGELOG.md @@ -1,8 +1,11 @@ ## 22.0.2-wip * Fix factory argument types for protobuf `Map` fields. ([#975]) +* Fix import order changes when files are passed in different order to `protoc`. +([#952]) [#975]: https://github.com/google/protobuf.dart/issues/975 +[#952]: https://github.com/google/protobuf.dart/issues/952 ## 22.0.1 diff --git a/protoc_plugin/lib/src/code_generator.dart b/protoc_plugin/lib/src/code_generator.dart index 9f324c6d3..1afec4587 100644 --- a/protoc_plugin/lib/src/code_generator.dart +++ b/protoc_plugin/lib/src/code_generator.dart @@ -5,6 +5,7 @@ import 'dart:io' hide BytesBuilder; import 'dart:typed_data' show BytesBuilder; +import 'package:collection/collection.dart'; import 'package:fixnum/fixnum.dart'; import 'package:protobuf/protobuf.dart'; @@ -105,6 +106,8 @@ class CodeGenerator { request.mergeFromCodedBufferReader(reader, extensions); reader.checkLastTagWas(0); + request.protoFile.sortBy((desc) => desc.name); + final response = CodeGeneratorResponse(); // Parse the options in the request. Return the errors if any. diff --git a/protoc_plugin/pubspec.yaml b/protoc_plugin/pubspec.yaml index 95c33d3b1..122eef003 100644 --- a/protoc_plugin/pubspec.yaml +++ b/protoc_plugin/pubspec.yaml @@ -7,12 +7,12 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: + collection: ^1.15.0 fixnum: ^1.0.0 path: ^1.8.0 protobuf: ^4.0.0 dev_dependencies: - collection: ^1.15.0 dart_flutter_team_lints: ^1.0.0 matcher: ^0.12.10 test: ^1.16.0