Skip to content

Commit

Permalink
[pigeon] Add method to run pigeon with PigeonOptions (#2842)
Browse files Browse the repository at this point in the history
* [pigeon] Add runWithOptions entrypoint to allow external libraries to use the pigeon easier

* [pigeon] 4.2.7 code review fixes

* [pigeon]: Bump version 4.2.8
  • Loading branch information
rotorgames committed Nov 30, 2022
1 parent bddfe04 commit d58da50
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
@@ -1,3 +1,7 @@
## 4.2.8

* Adds the ability to use `runWithOptions` entrypoint to allow external libraries to use the pigeon easier.

## 4.2.7

* [swift] Fixes a bug when calling methods that return `void`.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Expand Up @@ -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.7';
const String pigeonVersion = '4.2.8';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
11 changes: 10 additions & 1 deletion packages/pigeon/lib/pigeon_lib.dart
Expand Up @@ -1332,9 +1332,18 @@ ${_argParser.usage}''';
/// customize the generators that pigeon will use. The optional parameter
/// [sdkPath] allows you to specify the Dart SDK path.
static Future<int> run(List<String> args,
{List<Generator>? generators, String? sdkPath}) {
final PigeonOptions options = Pigeon.parseArgs(args);
return runWithOptions(options, generators: generators, sdkPath: sdkPath);
}

/// The 'main' entrypoint used by external packages. [options] is
/// used when running the code generator. The optional parameter [generators] allows you to
/// customize the generators that pigeon will use. The optional parameter
/// [sdkPath] allows you to specify the Dart SDK path.
static Future<int> runWithOptions(PigeonOptions options,
{List<Generator>? generators, String? sdkPath}) async {
final Pigeon pigeon = Pigeon.setup();
PigeonOptions options = Pigeon.parseArgs(args);
if (options.debugGenerators ?? false) {
generator_tools.debugGenerators = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
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: 4.2.7 # This must match the version in lib/generator_tools.dart
version: 4.2.8 # This must match the version in lib/generator_tools.dart

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
14 changes: 14 additions & 0 deletions packages/pigeon/test/pigeon_lib_test.dart
Expand Up @@ -1210,4 +1210,18 @@ abstract class Api {
});
await completer.future;
});

test('run with PigeonOptions', () async {
final Completer<void> completer = Completer<void>();
withTempFile('foo.dart', (File input) async {
final _ValidatorGenerator generator = _ValidatorGenerator(null);
final int result = await Pigeon.runWithOptions(
PigeonOptions(input: input.path, dartOut: 'foo.dart'),
generators: <Generator>[generator]);
expect(generator.didCallValidate, isFalse);
expect(result, equals(0));
completer.complete();
});
await completer.future;
});
}

0 comments on commit d58da50

Please sign in to comment.