diff --git a/.cirrus.yml b/.cirrus.yml index 5b73ffb12d6..ef93b57a96d 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -118,6 +118,18 @@ task: - else - ./script/tool_runner.sh version-check --check-for-missing-changes --pr-labels="$CIRRUS_PR_LABELS" - fi + publishable_bug_workaround_script: + # Workaround for https://github.com/dart-lang/pub/issues/3618 + # TODO(stuartmorgan): Remove this once that issue is fixed. + - cd packages/pigeon + - pushd mock_handler_tester; flutter pub get; popd + - pushd e2e_tests/test_objc; flutter pub get; popd + - pushd platform_tests/ios_swift_unit_tests; flutter pub get; popd + - pushd platform_tests/windows_unit_tests; flutter pub get; popd + - pushd platform_tests/ios_unit_tests; flutter pub get; popd + - pushd platform_tests/flutter_null_safe_unit_tests; flutter pub get; popd + - pushd platform_tests/android_kotlin_unit_tests; flutter pub get; popd + - pushd platform_tests/android_unit_tests; flutter pub get; popd publishable_script: ./script/tool_runner.sh publish-check --allow-pre-release - name: dart_unit_tests env: diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index ddf96c88e1b..cdebafe869a 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.2.5 + +* [dart] Fixes enum parameter handling in Dart test API class. + ## 4.2.4 * [kotlin] Fixes Kotlin generated sync host api error. diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 70da7caed15..f87297a91de 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -276,6 +276,8 @@ void _writeFlutterApi( bool isMockHandler = false, }) { assert(api.location == ApiLocation.flutter); + final List customEnumNames = + root.enums.map((Enum x) => x.name).toList(); String codecName = _standardMessageCodec; if (getCodecClasses(api, root).isNotEmpty) { codecName = _getCodecName(api); @@ -358,8 +360,14 @@ void _writeFlutterApi( _makeGenericTypeArguments(arg.type); final String castCall = _makeGenericCastCall(arg.type); - indent.writeln( - 'final $argType? $argName = ($argsArray[$count] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'};'); + final String leftHandSide = 'final $argType? $argName'; + if (customEnumNames.contains(arg.type.baseName)) { + indent.writeln( + '$leftHandSide = $argsArray[$count] == null ? null : $argType.values[$argsArray[$count] as int];'); + } else { + indent.writeln( + '$leftHandSide = ($argsArray[$count] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'};'); + } if (!arg.type.isNullable) { indent.writeln( "assert($argName != null, 'Argument for $channelName was null, expected non-null $argType.');"); diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index bc58a704362..7c988f85b33 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -9,7 +9,7 @@ import 'dart:mirrors'; import 'ast.dart'; /// The current version of pigeon. This must match the version in pubspec.yaml. -const String pigeonVersion = '4.2.4'; +const String pigeonVersion = '4.2.5'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 42674d61594..7d5060fc0f9 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ 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%3Apigeon -version: 4.2.4 # This must match the version in lib/generator_tools.dart +version: 4.2.5 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 582b29e1f08..1c163117324 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -1309,4 +1309,51 @@ name: foobar final String code = sink.toString(); expect(code, contains('extends StandardMessageCodec')); }); + + test('host test code handles enums', () { + final Root root = Root( + apis: [ + Api( + name: 'Api', + location: ApiLocation.host, + dartHostTestHandler: 'ApiMock', + methods: [ + Method( + name: 'doit', + returnType: const TypeDeclaration.voidDeclaration(), + arguments: [ + NamedType( + type: const TypeDeclaration( + baseName: 'Enum', + isNullable: false, + ), + name: 'anEnum') + ]) + ]) + ], + classes: [], + enums: [ + Enum( + name: 'Enum', + members: [ + 'one', + 'two', + ], + ) + ], + ); + final StringBuffer sink = StringBuffer(); + generateTestDart( + const DartOptions(), + root, + sink, + dartOutPath: 'code.dart', + testOutPath: 'test.dart', + ); + final String testCode = sink.toString(); + expect( + testCode, + contains( + 'final Enum? arg_anEnum = args[0] == null ? null : Enum.values[args[0] as int]')); + }); }