|
| 1 | +# Pigeon Contributor's Guide |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +Pigeon is a code generation tool that adds type safety to Flutter’s Platform |
| 6 | +Channels. This document serves as an overview of how it functions to help |
| 7 | +people who would like to contribute to the project. |
| 8 | + |
| 9 | +## State Diagram |
| 10 | + |
| 11 | +Pigeon generates a temporary file in its _LaunchIsolate_, the isolate that is |
| 12 | +spawned to run `main()`, then launches another isolate, _PigeonIsolate_, that |
| 13 | +uses `dart:mirrors` to parse the generated file, creating an |
| 14 | +[AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree), then running code |
| 15 | +generators with that AST. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +## Source Index |
| 20 | + |
| 21 | +* [ast.dart](./lib/ast.dart) - The data structure for representing the Abstract Syntax Tree. |
| 22 | +* [dart_generator.dart](./lib/dart_generator.dart) - The Dart code generator. |
| 23 | +* [java_generator.dart](./lib/java_generator.dart) - The Java code generator. |
| 24 | +* [objc_generator.dart](./lib/objc_generator.dart) - The Objective-C code |
| 25 | + generator (header and source files). |
| 26 | +* [generator_tools.dart](./lib/generator_tools.dart) - Shared code between generators. |
| 27 | +* [pigeon_cl.dart](./lib/pigeon_cl.dart) - The top-level function executed by |
| 28 | + the command line tool in [bin/][./bin]. |
| 29 | +* [pigeon_lib.dart](./lib/pigeon_lib.dart) - The top-level function for the |
| 30 | + PigeonIsolate and the AST generation code. |
| 31 | +* [pigeon.dart](./lib/pigeon.dart) - A file of exported modules, the intended |
| 32 | + import for users of Pigeon. |
| 33 | + |
| 34 | +## Testing Overview |
| 35 | + |
| 36 | +Pigeon has 3 types of tests, you'll find them all in [run_tests.sh](./run_tests.sh). |
| 37 | + |
| 38 | +* Unit tests - These are the fastest tests that are just typical unit tests, |
| 39 | + they may be generating code and checking it against a regular expression to |
| 40 | + see if it's correct. Example: |
| 41 | + [dart_generator_test.dart](./test/dart_generator_test.dart) |
| 42 | +* Compilation tests - These tests generate code, then attempt to compile that |
| 43 | + code. These are tests are much slower than unit tests, but not as slow as |
| 44 | + integration tests. These tests are typically run against the Pigeon files in |
| 45 | + [pigeons](./pigeons). |
| 46 | +* Integration tests - These tests generate code, then compile the generated |
| 47 | + code, then execute the generated code. It can be thought of as unit-tests run |
| 48 | + against the generated code. Examples: [platform_tests](./platform_tests) |
| 49 | + |
| 50 | +## Generated Source Code Example |
| 51 | + |
| 52 | +This is what the temporary generated code that the _PigeonIsolate_ executes |
| 53 | +looks like (see [State Diagram](#state-diagram)): |
| 54 | + |
| 55 | +```dart |
| 56 | +@dart = 2.12 |
| 57 | +import 'path/to/supplied/pigeon/file.dart' |
| 58 | +import 'dart:io'; |
| 59 | +import 'dart:isolate'; |
| 60 | +import 'package:pigeon/pigeon_lib.dart'; |
| 61 | +void main(List<String> args, SendPort sendPort) async { |
| 62 | + sendPort.send(await Pigeon.run(args)); |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +This is how `dart:mirrors` gets access to the supplied Pigeon file. |
| 67 | + |
| 68 | +## Imminent Plans |
| 69 | + |
| 70 | +* Migrate to Dart Analyzer for AST generation ([issue |
| 71 | + 78818](https://github.com/flutter/flutter/issues/78818)) - We might have |
| 72 | + reached the limitations of using dart:mirrors for parsing the Dart files. |
| 73 | + That package has been deprecated and it doesn't support null-safe annotations. |
| 74 | + We should migrate to using the Dart Analyzer as the front-end parser. |
| 75 | +* Integration tests for Android - Right now we have integration tests for Dart |
| 76 | + and iOS. We should add some for Android. It is limiting the speed at which |
| 77 | + we can bring in external contributor's contributions to Android / Java. |
0 commit comments