Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.1.8

* Started spawning pigeon_lib in an isolate instead of a subprocess. The
subprocess could have lead to errors if the dart version on $PATH didn't match
the one that comes with flutter.

## 0.1.7

* Fixed Dart compilation for later versions that support null safety, opting out
Expand Down
28 changes: 19 additions & 9 deletions packages/pigeon/bin/pigeon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
import 'package:path/path.dart' as path;
import 'package:pigeon/pigeon_lib.dart';

Future<void> main(List<String> args) async {
Expand All @@ -13,20 +15,28 @@ Future<void> main(List<String> args) async {
(opts.input != null) ? 'import \'${opts.input}\';\n' : '';
final String code = """$importLine
import 'dart:io';
import 'dart:isolate';
import 'package:pigeon/pigeon_lib.dart';

void main(List<String> args) async {
exit(await Pigeon.run(args));
void main(List<String> args, SendPort sendPort) async {
sendPort.send(await Pigeon.run(args));
}
""";
// TODO(aaclarke): Start using a system temp file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, that API isn't so helpful though because I should probably make a temp directory in there instead of placing the file directly in the system temp. It would be nice if we had something like mktemp -d. At the very least i need a GUID to make sure I don't collide. I'll get around to this later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, dang you, I did it, haha. I had to do some trickery to get relative paths for the dart imports. Now it says stuff like:

import '../../../../../../Users/aaclarke/dev/packages/packages/pigeon/pigeons/message.dart';

I didn't check to see if dart actually supports absolute path imports.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this whole problem go away once we do flutter/flutter#65071?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. There always has to be a link between the generated code that the isolate executes and the pigeon file.

const String tempFilename = '_pigeon_temp_.dart';
final String tempFilename = path.join(Directory.current.path, '_pigeon_temp_.dart');
final File tempFile = await File(tempFilename).writeAsString(code);
final Process process =
await Process.start('dart', <String>[tempFilename] + args);
process.stdout.transform(utf8.decoder).listen((String data) => print(data));
process.stderr.transform(utf8.decoder).listen((String data) => print(data));
final int exitCode = await process.exitCode;
final ReceivePort receivePort = ReceivePort();
Isolate.spawnUri(Uri.parse(tempFilename), args, receivePort.sendPort);
final Completer<int> completer = Completer<int>();
receivePort.listen((dynamic message) {
try {
// ignore: avoid_as
completer.complete(message as int);
} catch (exception) {
completer.completeError(exception);
}
});
final int exitCode = await completer.future;
tempFile.deleteSync();
exit(exitCode);
}
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dart:mirrors';
import 'ast.dart';

/// The current version of pigeon.
const String pigeonVersion = '0.1.7';
const String pigeonVersion = '0.1.8';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pigeon
version: 0.1.7
version: 0.1.8
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
homepage: https://github.com/flutter/packages/tree/master/packages/pigeon
dependencies:
Expand Down