Skip to content
Open
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
24 changes: 24 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## 0.2.0

* **BREAKING CHANGE** - Pigeon files must be null-safe now. That means the
fields inside of the classes must be declared nullable (non-null fields arent't
yet supported). Migration example:

```dart
// Version 0.1.x
class Foo {
int bar;
String baz;
}

// Version 0.2.x
class Foo {
int? bar;
String? baz;
}
```

* **BREAKING CHANGE** - The default output from Pigeon is now null-safe. If you
want non-null-safe code you must provide the `--no-dart_null_safety` flag.
* The Pigeon source code is now null-safe.

## 0.1.24

* Moved logic from bin/ to lib/ to help customers wrap up the behavior.
Expand Down
6 changes: 3 additions & 3 deletions packages/pigeon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public interface Api2Host {

## Null Safety (NNBD)

In order to generate null-safe code run the command line with the extra argument
`--dart_null_safety`. For example:
`flutter pub run pigeon --input ./pigeons/messages.dart --dart_null_safety`.
In order to generate non-null-safe code run with the extra argument
`--no-dart_null_safety`. For example:
`flutter pub run pigeon --input ./pigeons/messages.dart --no-dart_null_safety --dart_out stdout`.

## Feedback

Expand Down
5 changes: 4 additions & 1 deletion packages/pigeon/lib/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import 'generator_tools.dart';

/// Options that control how Dart code will be generated.
class DartOptions {
/// Constructor for DartOptions.
DartOptions({this.isNullSafe = true});

/// Determines if the generated code has null safety annotations (Dart >=2.12 required).
bool isNullSafe = false;
bool isNullSafe;
}

String _escapeForDartSingleQuotedString(String raw) {
Expand Down
3 changes: 2 additions & 1 deletion packages/pigeon/lib/pigeon_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ options:
..addOption('java_package',
help: 'The package that generated Java code will be in.')
..addFlag('dart_null_safety',
help: 'Makes generated Dart code have null safety annotations')
help: 'Makes generated Dart code have null safety annotations',
defaultsTo: true)
..addOption('objc_header_out',
help: 'Path to generated Objective-C header file (.h).')
..addOption('objc_prefix',
Expand Down
8 changes: 3 additions & 5 deletions packages/pigeon/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ test_pigeon_ios() {
temp_dir=$(mktmpdir)

pub run pigeon \
--no-dart_null_safety \
--input $1 \
--dart_out $temp_dir/pigeon.dart \
--objc_header_out $temp_dir/pigeon.h \
Expand All @@ -80,7 +81,6 @@ test_pigeon_android() {

pub run pigeon \
--input $1 \
--dart_null_safety \
--dart_out $temp_dir/pigeon.dart \
--java_out $temp_dir/Pigeon.java \
--java_package foo
Expand Down Expand Up @@ -113,7 +113,6 @@ test_null_safe_dart() {

pub run pigeon \
--input $1 \
--dart_null_safety \
--dart_out $temp_dir/pigeon.dart

dartanalyzer $temp_dir/pigeon.dart --fatal-infos --fatal-warnings --packages ./e2e_tests/test_objc/.packages
Expand Down Expand Up @@ -165,7 +164,6 @@ pub run pigeon 1> /dev/null
pushd $PWD
pub run pigeon \
--input pigeons/message.dart \
--dart_null_safety \
--dart_out platform_tests/flutter_null_safe_unit_tests/lib/null_safe_pigeon.dart
cd platform_tests/flutter_null_safe_unit_tests
flutter pub get
Expand All @@ -178,7 +176,6 @@ popd
pushd $PWD
pub run pigeon \
--input pigeons/message.dart \
--dart_null_safety \
--dart_out mock_handler_tester/test/message.dart \
--dart_test_out mock_handler_tester/test/test.dart
dartfmt -w mock_handler_tester/test/message.dart
Expand Down Expand Up @@ -221,11 +218,13 @@ test_pigeon_ios ./pigeons/all_datatypes.dart
# iOS unit tests on generated code.
###############################################################################
pub run pigeon \
--no-dart_null_safety \
--input pigeons/message.dart \
--dart_out /dev/null \
--objc_header_out platform_tests/ios_unit_tests/ios/Runner/messages.h \
--objc_source_out platform_tests/ios_unit_tests/ios/Runner/messages.m
pub run pigeon \
--no-dart_null_safety \
--input pigeons/async_handlers.dart \
--dart_out /dev/null \
--objc_header_out platform_tests/ios_unit_tests/ios/Runner/async_handlers.h \
Expand Down Expand Up @@ -255,7 +254,6 @@ DARTLE_DART="e2e_tests/test_objc/lib/dartle.dart"
PIGEON_JAVA="e2e_tests/test_objc/android/app/src/main/java/io/flutter/plugins/Pigeon.java"
pub run pigeon \
--input pigeons/message.dart \
--dart_null_safety \
--dart_out $DARTLE_DART \
--objc_header_out $DARTLE_H \
--objc_source_out $DARTLE_M \
Expand Down
10 changes: 5 additions & 5 deletions packages/pigeon/test/dart_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
generateDart(DartOptions(), root, sink);
final String code = sink.toString();
expect(code, contains('class Foobar'));
expect(code, contains(' dataType1 field1;'));
expect(code, contains(' dataType1? field1;'));
});

test('gen one host api', () {
Expand Down Expand Up @@ -71,13 +71,13 @@ void main() {
expect(
code,
contains(
'pigeonMap[\'nested\'] = nested == null ? null : nested.encode()',
'pigeonMap[\'nested\'] = nested == null ? null : nested!.encode()',
),
);
expect(
code.replaceAll('\n', ' ').replaceAll(' ', ''),
contains(
'..nested = pigeonMap[\'nested\'] != null ? Input.decode(pigeonMap[\'nested\']) : null;',
'..nested = pigeonMap[\'nested\'] != null ? Input.decode(pigeonMap[\'nested\']!) : null;',
),
);
});
Expand Down Expand Up @@ -243,7 +243,7 @@ void main() {
expect(testCode, contains('abstract class ApiMock'));
expect(testCode, isNot(contains('.ApiMock.doSomething')));
expect(testCode, contains('\'${Keys.result}\': output.encode()'));
expect(testCode, contains('return <Object, Object>{};'));
expect(testCode, contains('return <Object?, Object?>{};'));
});

test('opt out of nndb', () {
Expand All @@ -261,7 +261,7 @@ void main() {
classes: <Class>[klass],
);
final StringBuffer sink = StringBuffer();
generateDart(DartOptions(), root, sink);
generateDart(DartOptions(isNullSafe: false), root, sink);
final String code = sink.toString();
expect(code, contains('// @dart = 2.8'));
});
Expand Down