Skip to content

Commit 2bf9345

Browse files
fix(e2e): add pigeon generation to flutter_plugin (#1587)
* fix(e2e): add pigeon generation to flutter_plugin * chore: regenerate flutter plugin bundle * chore: bump templates * Update e2e/test/commands/create/flutter_plugin/flutter_plugin_test.dart
1 parent 9f7c48e commit 2bf9345

14 files changed

Lines changed: 598 additions & 113 deletions

File tree

e2e/test/commands/create/flutter_plugin/flutter_plugin_test.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ void main() {
3333
'format',
3434
], workingDirectory: pluginDirectory);
3535

36+
// Verify pigeon generated messages.g.dart for each platform that has a
37+
// pigeon input file. The check is conditional so it passes when the
38+
// fallback bundle (without pigeon) is used.
39+
const pigeonPlatforms = ['android', 'ios', 'linux', 'macos', 'windows'];
40+
for (final platform in pigeonPlatforms) {
41+
final pigeonInput = File(
42+
path.join(
43+
pluginDirectory,
44+
'${pluginName}_$platform',
45+
'pigeons',
46+
'messages.dart',
47+
),
48+
);
49+
if (pigeonInput.existsSync()) {
50+
final messagesFile = File(
51+
path.join(
52+
pluginDirectory,
53+
'${pluginName}_$platform',
54+
'lib',
55+
'src',
56+
'messages.g.dart',
57+
),
58+
);
59+
expect(
60+
messagesFile.existsSync(),
61+
isTrue,
62+
reason: 'pigeon did not generate ${messagesFile.path}',
63+
);
64+
}
65+
}
66+
3667
final analyzeResult = await expectSuccessfulProcessResult('flutter', [
3768
'analyze',
3869
'.',
@@ -60,6 +91,24 @@ void main() {
6091
], workingDirectory: packageDirectory);
6192
expect(testResult.stdout, contains('All tests passed!'));
6293

94+
final messagesGenFile = File(
95+
path.join(packageDirectory, 'lib', 'src', 'messages.g.dart'),
96+
);
97+
if (messagesGenFile.existsSync()) {
98+
await expectSuccessfulProcessResult(
99+
'lcov',
100+
[
101+
'--remove',
102+
'coverage/lcov.info',
103+
'*/messages.g.dart',
104+
'--output-file',
105+
'coverage/lcov.info',
106+
],
107+
workingDirectory: packageDirectory,
108+
validateStderr: false,
109+
);
110+
}
111+
63112
final testCoverageResult = await expectSuccessfulProcessResult(
64113
'genhtml',
65114
['coverage/lcov.info', '-o', 'coverage'],

lib/src/cli/dart_cli.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ class Dart {
101101
await Future.wait<void>(processes);
102102
}
103103

104+
/// Run pigeon code generation (`dart run pigeon --input <input>`).
105+
static Future<void> runPigeon({
106+
required Logger logger,
107+
required String cwd,
108+
required String input,
109+
}) async {
110+
await _Cmd.run(
111+
'dart',
112+
['run', 'pigeon', '--input', input],
113+
workingDirectory: cwd,
114+
logger: logger,
115+
);
116+
}
117+
104118
/// Run tests (`dart test`).
105119
/// Returns a list of exit codes for each test process.
106120
static Future<List<int>> test({
Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:mason/mason.dart';
2+
import 'package:path/path.dart' as p;
23
import 'package:universal_io/io.dart';
34
import 'package:very_good_cli/src/cli/cli.dart';
45

@@ -11,14 +12,13 @@ Future<bool> installDartPackages(
1112
bool recursive = false,
1213
}) async {
1314
final isDartInstalled = await Dart.installed(logger: logger);
14-
if (isDartInstalled) {
15-
return Dart.pubGet(
16-
cwd: outputDir.path,
17-
recursive: recursive,
18-
logger: logger,
19-
);
20-
}
21-
return false;
15+
if (!isDartInstalled) return false;
16+
17+
return Dart.pubGet(
18+
cwd: outputDir.path,
19+
recursive: recursive,
20+
logger: logger,
21+
);
2222
}
2323

2424
/// Runs `flutter pub get` in the [outputDir].
@@ -30,14 +30,46 @@ Future<bool> installFlutterPackages(
3030
bool recursive = false,
3131
}) async {
3232
final isFlutterInstalled = await Flutter.installed(logger: logger);
33-
if (isFlutterInstalled) {
34-
return Flutter.pubGet(
35-
cwd: outputDir.path,
36-
recursive: recursive,
37-
logger: logger,
38-
);
39-
}
40-
return false;
33+
if (!isFlutterInstalled) return false;
34+
35+
return Flutter.pubGet(
36+
cwd: outputDir.path,
37+
recursive: recursive,
38+
logger: logger,
39+
);
40+
}
41+
42+
/// Runs `dart run pigeon` for each platform directory that contains
43+
/// a `pigeons/messages.dart` input file in the [outputDir].
44+
///
45+
/// This is a no-op if Dart is not installed or if no pigeon inputs are found,
46+
/// which ensures backwards compatibility with template versions that do not
47+
/// use Pigeon.
48+
Future<void> generatePigeonCode(Logger logger, Directory outputDir) async {
49+
final isDartInstalled = await Dart.installed(logger: logger);
50+
if (!isDartInstalled) return;
51+
52+
final pigeonDirs = outputDir.listSync().whereType<Directory>().where(
53+
(d) => File(p.join(d.path, 'pigeons', 'messages.dart')).existsSync(),
54+
);
55+
56+
if (pigeonDirs.isEmpty) return;
57+
58+
final progress = logger.progress(
59+
'Running "dart run pigeon" in ${outputDir.path}',
60+
);
61+
62+
await Future.wait(
63+
pigeonDirs.map(
64+
(dir) => Dart.runPigeon(
65+
cwd: dir.path,
66+
logger: logger,
67+
input: 'pigeons/messages.dart',
68+
),
69+
),
70+
);
71+
72+
progress.complete();
4173
}
4274

4375
/// Runs `dart fix --apply` in the [outputDir].
@@ -47,15 +79,17 @@ Future<void> applyDartFixes(
4779
bool recursive = false,
4880
}) async {
4981
final isDartInstalled = await Dart.installed(logger: logger);
50-
if (isDartInstalled) {
51-
final applyFixesProgress = logger.progress(
52-
'Running "dart fix --apply" in ${outputDir.path}',
53-
);
54-
await Dart.applyFixes(
55-
cwd: outputDir.path,
56-
recursive: recursive,
57-
logger: logger,
58-
);
59-
applyFixesProgress.complete();
60-
}
82+
if (!isDartInstalled) return;
83+
84+
final applyFixesProgress = logger.progress(
85+
'Running "dart fix --apply" in ${outputDir.path}',
86+
);
87+
88+
await Dart.applyFixes(
89+
cwd: outputDir.path,
90+
recursive: recursive,
91+
logger: logger,
92+
);
93+
94+
applyFixesProgress.complete();
6195
}

lib/src/commands/create/templates/very_good_app_ui/very_good_app_ui_bundle.dart

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/commands/create/templates/very_good_core/very_good_core_bundle.dart

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)