Skip to content

[pigeon] Fix C++ Flutter API class args #3573

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 2 commits into from
Mar 28, 2023
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
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.1.2

* [cpp] Fixes class parameters to Flutter APIs.

## 9.1.1

* [swift] Removes experimental tags.
Expand Down
26 changes: 20 additions & 6 deletions packages/pigeon/lib/cpp_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ class CppSourceGenerator extends StructuredGenerator<CppOptions> {
final HostDatatype hostDatatype = getFieldHostDatatype(field,
root.classes, root.enums, _shortBaseCppTypeForBuiltinDartType);
final String encodableValue = _wrappedHostApiArgumentExpression(
root, _makeInstanceVariableName(field), field.type, hostDatatype);
root, _makeInstanceVariableName(field), field.type, hostDatatype,
preSerializeClasses: true);
indent.writeln('list.push_back($encodableValue);');
}
indent.writeln('return list;');
Expand Down Expand Up @@ -686,7 +687,8 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
indent.addScoped('EncodableValue(EncodableList{', '});', () {
for (final _HostNamedType param in hostParameters) {
final String encodedArgument = _wrappedHostApiArgumentExpression(
root, param.name, param.originalType, param.hostType);
root, param.name, param.originalType, param.hostType,
preSerializeClasses: false);
indent.writeln('$encodedArgument,');
}
});
Expand Down Expand Up @@ -994,14 +996,26 @@ ${prefix}reply(EncodableValue(std::move(wrapped)));''';

/// Returns the expression to create an EncodableValue from a host API argument
/// with the given [variableName] and types.
///
/// If [preSerializeClasses] is true, custom classes will be returned as
/// encodable lists rather than CustomEncodableValues; see
/// https://github.com/flutter/flutter/issues/119351 for why this is currently
/// needed.
String _wrappedHostApiArgumentExpression(Root root, String variableName,
TypeDeclaration dartType, HostDatatype hostType) {
TypeDeclaration dartType, HostDatatype hostType,
{required bool preSerializeClasses}) {
final String encodableValue;
if (!hostType.isBuiltin &&
root.classes.any((Class c) => c.name == dartType.baseName)) {
final String operator = hostType.isNullable ? '->' : '.';
encodableValue =
'EncodableValue($variableName${operator}ToEncodableList())';
if (preSerializeClasses) {
final String operator = hostType.isNullable ? '->' : '.';
encodableValue =
'EncodableValue($variableName${operator}ToEncodableList())';
} else {
final String nonNullValue =
hostType.isNullable ? '*$variableName' : variableName;
encodableValue = 'CustomEncodableValue($nonNullValue)';
}
} else if (!hostType.isBuiltin &&
root.enums.any((Enum e) => e.name == dartType.baseName)) {
final String nonNullValue =
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'ast.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '9.1.1';
const String pigeonVersion = '9.1.2';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
// ignore_for_file: avoid_relative_lib_imports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.alternate_language_test_plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "CoreTests.gen.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1112,10 +1112,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
expect(listEquals(echoObject.aList, genericAllTypes.aList), true);
expect(mapEquals(echoObject.aMap, genericAllTypes.aMap), true);
expect(echoObject.anEnum, genericAllTypes.anEnum);
},
// TODO(stuartmorgan): Fix and re-enable.
// See https://github.com/flutter/flutter/issues/118739
skip: targetGenerator == TargetGenerator.cpp);
});

testWidgets(
'Arguments of multiple types serialize and deserialize correctly',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.test_plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#undef _HAS_EXCEPTIONS
Expand Down Expand Up @@ -3130,7 +3130,7 @@ void FlutterIntegrationCoreApi::EchoAllTypes(
binary_messenger_,
"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllTypes", &GetCodec());
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
EncodableValue(everything_arg.ToEncodableList()),
CustomEncodableValue(everything_arg),
});
channel->Send(
encoded_api_arguments,
Expand All @@ -3153,7 +3153,7 @@ void FlutterIntegrationCoreApi::EchoAllNullableTypes(
"dev.flutter.pigeon.FlutterIntegrationCoreApi.echoAllNullableTypes",
&GetCodec());
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
EncodableValue(everything_arg.ToEncodableList()),
CustomEncodableValue(everything_arg),
});
channel->Send(
encoded_api_arguments,
Expand Down Expand Up @@ -3718,7 +3718,7 @@ void FlutterSmallApi::EchoWrappedList(
binary_messenger_, "dev.flutter.pigeon.FlutterSmallApi.echoWrappedList",
&GetCodec());
EncodableValue encoded_api_arguments = EncodableValue(EncodableList{
EncodableValue(msg_arg.ToEncodableList()),
CustomEncodableValue(msg_arg),
});
channel->Send(
encoded_api_arguments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#ifndef PIGEON_CORE_TESTS_GEN_H_
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 9.1.1 # This must match the version in lib/generator_tools.dart
version: 9.1.2 # This must match the version in lib/generator_tools.dart

environment:
sdk: ">=2.17.0 <4.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/pigeon/test/cpp_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ void main() {
expect(
code,
contains(
'an_object_arg ? EncodableValue(an_object_arg->ToEncodableList()) : EncodableValue()'));
'an_object_arg ? CustomEncodableValue(*an_object_arg) : EncodableValue()'));
}
});

Expand Down Expand Up @@ -1433,7 +1433,7 @@ void main() {
expect(code, contains('EncodableValue(a_list_arg)'));
expect(code, contains('EncodableValue(a_map_arg)'));
// Class types use ToEncodableList.
expect(code, contains('EncodableValue(an_object_arg.ToEncodableList())'));
expect(code, contains('CustomEncodableValue(an_object_arg)'));
}
});

Expand Down