From 43a70003ef8a7fbac5835a7687cb72bb9c98794c Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 17 Jan 2025 16:26:53 -0500 Subject: [PATCH] [pigeon] Update analyzer and formatter Adds compatibility with the latest major version of `analyzer` and `dart_style` (the latter being required to actually allow `analyzer` 7). The breaking change of `dart_style` does affect our usage, so this updates rather than expands the allowed version. The range for `analyzer` is updated to drop versions older thas 6 since `dart_style` doesn't allow versions older than 6 anyway. We have to pick a language version to use for formatting; this (somewhat arbitrarily) uses 3.6, to opt in to the new formatter. Fixes https://github.com/flutter/flutter/issues/161820 Fixes https://github.com/flutter/flutter/issues/161583 --- packages/pigeon/CHANGELOG.md | 4 ++++ packages/pigeon/lib/dart_generator.dart | 7 +++++-- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/pubspec.yaml | 6 +++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 676756512949..4f8c47d2b847 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 22.7.3 + +* Adds compatibility with `analyzer` 7.x.*. + ## 22.7.2 * Updates README to discuss best practices for using Pigeon-generated code. diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index abacf3dea31c..4f54839f8744 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -5,6 +5,7 @@ import 'package:code_builder/code_builder.dart' as cb; import 'package:dart_style/dart_style.dart'; import 'package:path/path.dart' as path; +import 'package:pub_semver/pub_semver.dart'; import 'ast.dart'; import 'dart/templates.dart'; @@ -779,7 +780,8 @@ final BinaryMessenger? ${varNamePrefix}binaryMessenger; final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); indent.format( - DartFormatter().format('${instanceManagerApi.accept(emitter)}'), + DartFormatter(languageVersion: Version(3, 6, 0)) + .format('${instanceManagerApi.accept(emitter)}'), ); } @@ -899,7 +901,8 @@ final BinaryMessenger? ${varNamePrefix}binaryMessenger; ); final cb.DartEmitter emitter = cb.DartEmitter(useNullSafetySyntax: true); - indent.format(DartFormatter().format('${proxyApi.accept(emitter)}')); + indent.format(DartFormatter(languageVersion: Version(3, 6, 0)) + .format('${proxyApi.accept(emitter)}')); } /// Generates Dart source code for test support libraries based on the given AST diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 295d223fada0..a64742711cbf 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -14,7 +14,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '22.7.2'; +const String pigeonVersion = '22.7.3'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index a4334a271a16..442e7194e9ba 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,17 +2,17 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22 -version: 22.7.2 # This must match the version in lib/generator_tools.dart +version: 22.7.3 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.4.0 dependencies: - analyzer: ">=5.13.0 <7.0.0" + analyzer: ">=6.0.0 <8.0.0" args: ^2.1.0 code_builder: ^4.10.0 collection: ^1.15.0 - dart_style: ^2.3.4 + dart_style: ^3.0.0 graphs: ^2.3.1 meta: ^1.9.0 path: ^1.8.0