Skip to content

Conversation

@goderbauer
Copy link
Member

@goderbauer goderbauer commented Mar 30, 2023

New API has been around for 2-ish years, was introduced in flutter/flutter@5e0cc4c. Old API is to be deprecated in flutter/flutter#116793.

This is changing the code that pigeon generates (see changes in dart_generator.dart). Wondering if that requires special handling (e.g. a minor or major version bump).

final String messageHandlerSetter =
isMockHandler ? 'setMockMessageHandler' : 'setMessageHandler';
final String messageHandlerSetter = isMockHandler
? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the ! here the _ambiguate equivalent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that plus typing the return type of the getter above as TestDefaultBinaryMessengerBinding? to hide the fact that TestDefaultBinaryMessengerBinding.instance may be non-nullable in certain versions of Flutter.

indent.addScoped('{', '}', () {
indent.write(
'channel.$messageHandlerSetter((Object? message) async ',
'$messageHandlerSetter(Object? message) async ',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth a comment somewhere calling out that messageHandlerSetter contains the (

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the variable name to make that clear.

}

task clean(type: Delete) {
tasks.register("clean", Delete) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 This is the diff the generator script produced when re-generating all the generated files.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it was probably a flutter migrator from running on master. It's fine if you want to leave it, but it's unrelated to anything in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert it.

Copy link
Contributor

@Hixie Hixie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gaaclarke
Copy link
Member

Was @stuartmorgan in the loop with the BinaryMessenger API change? I just wanted to make sure his team had an opportunity to consider the ramifications. I guess it means loading on old plugins won't be able to run their tests, right?

///
/// This comment also tests multiple line comments.
abstract class TestHostApi {
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being written once per class instead of at the file level?

Copy link
Member Author

@goderbauer goderbauer Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main motivation was to keep the generator script more readable by generating the _testBinaryMessengerBinding getter close to where it is used and to make sure that the public DartGenerator.writeFlutterApi always generates functioning code - no matter from what context it is called. If we want to generate this only once per file, we'd have to move the getter generation out of DartGenerator.writeFlutterApi (where it will later be used) into DartGenerator.generateTest - it's possible, but overall seems more error-prone and the generator script becomes harder to follow. However, if you prefer doing it only once per file I am happy to change this. Please let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not as familiar with the test generator; that seems reasonable, so feel free to leave it.

(Long term we want to do more to have shared utilities created in a clear, structured way, but that work may not have even started for this generator.)

}

task clean(type: Delete) {
tasks.register("clean", Delete) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it was probably a flutter migrator from running on master. It's fine if you want to leave it, but it's unrelated to anything in this PR.

@stuartmorgan-g
Copy link
Collaborator

Was @stuartmorgan in the loop with the BinaryMessenger API change? I just wanted to make sure his team had an opportunity to consider the ramifications. I guess it means loading on old plugins won't be able to run their tests, right?

I wasn't but it seems like the ramifications are minimal. Deprecation isn't removal, and a two-year grace period since the new API was introduced is quite generous. I doubt many plugins being actively maintained still actually work on Flutter 2.0. And this case it wouldn't even affect clients on 2.0.

@stuartmorgan-g
Copy link
Collaborator

This is changing the code that pigeon generates (see changes in dart_generator.dart). Wondering if that requires special handling (e.g. a minor or major version bump).

No, we try as much as possible follow the spirit of semver for Pigeon. Internal details of generated code are like internal details of a package, so can be versioned accordingly.

@goderbauer goderbauer added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 1, 2023
@auto-submit auto-submit bot merged commit c68fa09 into flutter:main Apr 1, 2023
@goderbauer goderbauer deleted the pigeonMock branch April 1, 2023 03:10
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 3, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 3, 2023
nploi pushed a commit to nploi/packages that referenced this pull request Jul 16, 2023
[pigeon] Migrates off old BinaryMessenger API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants