Skip to content

Latest commit

 

History

History
75 lines (59 loc) · 3.14 KB

CONTRIBUTING.md

File metadata and controls

75 lines (59 loc) · 3.14 KB

Pigeon Contributor's Guide

Description

Pigeon is a code generation tool that adds type safety to Flutter’s Platform Channels. This document serves as an overview of how it functions to help people who would like to contribute to the project.

State Diagram

Pigeon generates a temporary file in its LaunchIsolate, the isolate that is spawned to run main(), then launches another isolate, PigeonIsolate, that uses dart:mirrors to parse the generated file, creating an AST, then running code generators with that AST.

State Diagram

Source Index

Testing Overview

Pigeon has 3 types of tests, you'll find them all in test.dart.

  • Unit tests - These are the fastest tests that are just typical unit tests, they may be generating code and checking it against a regular expression to see if it's correct. Example: dart_generator_test.dart
  • Compilation tests - These tests generate code, then attempt to compile that code. These are tests are much slower than unit tests, but not as slow as integration tests. These tests are typically run against the Pigeon files in pigeons.
  • Integration tests - These tests generate code, then compile the generated code, then execute the generated code. It can be thought of as unit-tests run against the generated code. Examples: platform_tests

Generated Source Code Example

This is what the temporary generated code that the PigeonIsolate executes looks like (see State Diagram):

import 'path/to/supplied/pigeon/file.dart'
import 'dart:io';
import 'dart:isolate';
import 'package:pigeon/pigeon_lib.dart';
void main(List<String> args, SendPort sendPort) async {
  sendPort.send(await Pigeon.run(args));
}

This is how dart:mirrors gets access to the supplied Pigeon file.

Imminent Plans

  • Migrate to Dart Analyzer for AST generation (issue 78818) - We might have reached the limitations of using dart:mirrors for parsing the Dart files. That package has been deprecated and it doesn't support null-safe annotations. We should migrate to using the Dart Analyzer as the front-end parser.