Skip to content

Commit f145bd6

Browse files
authored
[pigeon] adds generate option for example pigeons (flutter#4370)
Adds simple command for generating example files. Also adds arguments to choose what files to generate when running the generate function (test or example) runs both by default. - [] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style]. - [] I added new tests to check the change I am making, or this PR is [test-exempt].
1 parent 38f1715 commit f145bd6

File tree

11 files changed

+50
-20
lines changed

11 files changed

+50
-20
lines changed

packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
4+
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
import android.util.Log;

packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
4+
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77

packages/pigeon/example/app/ios/Runner/Messages.g.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
4+
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
import Foundation

packages/pigeon/example/app/lib/src/messages.g.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
4+
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
77

packages/pigeon/example/app/macos/Runner/messages.g.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
4+
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
#import <Foundation/Foundation.h>

packages/pigeon/example/app/macos/Runner/messages.g.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
4+
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
#import "messages.g.h"

packages/pigeon/example/app/windows/runner/messages.g.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
4+
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
#undef _HAS_EXCEPTIONS

packages/pigeon/example/app/windows/runner/messages.g.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
4+
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
66

77
#ifndef PIGEON_MESSAGES_G_H_

packages/pigeon/tool/generate.dart

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ import 'shared/generation.dart';
1919

2020
const String _helpFlag = 'help';
2121
const String _formatFlag = 'format';
22+
const String _files = 'files';
23+
const String _test = 'test';
24+
const String _example = 'example';
25+
26+
const List<String> _fileGroups = <String>[_test, _example];
2227

2328
Future<void> main(List<String> args) async {
2429
final ArgParser parser = ArgParser()
2530
..addFlag(_formatFlag, abbr: 'f', help: 'Autoformats after generation.')
2631
..addFlag(_helpFlag,
27-
negatable: false, abbr: 'h', help: 'Print this reference.');
32+
negatable: false, abbr: 'h', help: 'Print this reference.')
33+
..addMultiOption(_files,
34+
help:
35+
'Select specific groups of files to generate; $_test or $_example. Defaults to both.',
36+
allowed: _fileGroups);
2837

2938
final ArgResults argResults = parser.parse(args);
3039
if (argResults.wasParsed(_helpFlag)) {
@@ -37,13 +46,29 @@ ${parser.usage}''');
3746

3847
final String baseDir = p.dirname(p.dirname(Platform.script.toFilePath()));
3948

40-
print('Generating platform_test/ output...');
41-
final int generateExitCode = await generateTestPigeons(baseDir: baseDir);
42-
if (generateExitCode == 0) {
43-
print('Generation complete!');
44-
} else {
45-
print('Generation failed; see above for errors.');
46-
exit(generateExitCode);
49+
final List<String>? toGenerate =
50+
argResults.wasParsed(_files) ? argResults[_files] as List<String> : null;
51+
52+
if (toGenerate == null || toGenerate.contains(_test)) {
53+
print('Generating platform_test/ output...');
54+
final int generateExitCode = await generateTestPigeons(baseDir: baseDir);
55+
if (generateExitCode == 0) {
56+
print('Generation complete!');
57+
} else {
58+
print('Generation failed; see above for errors.');
59+
exit(generateExitCode);
60+
}
61+
}
62+
63+
if (toGenerate == null || toGenerate.contains(_example)) {
64+
print('Generating example/ output...');
65+
final int generateExitCode = await generateExamplePigeons();
66+
if (generateExitCode == 0) {
67+
print('Generation complete!');
68+
} else {
69+
print('Generation failed; see above for errors.');
70+
exit(generateExitCode);
71+
}
4772
}
4873

4974
if (argResults.wasParsed(_formatFlag)) {

packages/pigeon/tool/run_tests.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ Future<void> _validateGeneratedExampleFiles() async {
9090
print('Validating generated files:');
9191
print(' Generating example output...');
9292

93-
final int generateExitCode = await runPigeon(
94-
input: './example/app/pigeons/messages.dart',
95-
basePath: './example/app',
96-
);
93+
final int generateExitCode = await generateExamplePigeons();
9794

9895
if (generateExitCode != 0) {
9996
print('Generation failed; see above for errors.');

0 commit comments

Comments
 (0)