Skip to content

[pigeon] adds generate option for example pigeons #4370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon

import android.util.Log;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon


Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/example/app/ios/Runner/Messages.g.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/example/app/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/example/app/macos/Runner/messages.g.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/example/app/macos/Runner/messages.g.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "messages.g.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon

#undef _HAS_EXCEPTIONS
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/example/app/windows/runner/messages.g.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.1.2), do not edit directly.
// Autogenerated from Pigeon, do not edit directly.
// See also: https://pub.dev/packages/pigeon

#ifndef PIGEON_MESSAGES_G_H_
Expand Down
41 changes: 33 additions & 8 deletions packages/pigeon/tool/generate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ import 'shared/generation.dart';

const String _helpFlag = 'help';
const String _formatFlag = 'format';
const String _files = 'files';
const String _test = 'test';
const String _example = 'example';

const List<String> _fileGroups = <String>[_test, _example];

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

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

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

print('Generating platform_test/ output...');
final int generateExitCode = await generateTestPigeons(baseDir: baseDir);
if (generateExitCode == 0) {
print('Generation complete!');
} else {
print('Generation failed; see above for errors.');
exit(generateExitCode);
final List<String>? toGenerate =
argResults.wasParsed(_files) ? argResults[_files] as List<String> : null;

if (toGenerate == null || toGenerate.contains(_test)) {
print('Generating platform_test/ output...');
final int generateExitCode = await generateTestPigeons(baseDir: baseDir);
if (generateExitCode == 0) {
print('Generation complete!');
} else {
print('Generation failed; see above for errors.');
exit(generateExitCode);
}
}

if (toGenerate == null || toGenerate.contains(_example)) {
print('Generating example/ output...');
final int generateExitCode = await generateExamplePigeons();
if (generateExitCode == 0) {
print('Generation complete!');
} else {
print('Generation failed; see above for errors.');
exit(generateExitCode);
}
}

if (argResults.wasParsed(_formatFlag)) {
Expand Down
5 changes: 1 addition & 4 deletions packages/pigeon/tool/run_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ Future<void> _validateGeneratedExampleFiles() async {
print('Validating generated files:');
print(' Generating example output...');

final int generateExitCode = await runPigeon(
input: './example/app/pigeons/messages.dart',
basePath: './example/app',
);
final int generateExitCode = await generateExamplePigeons();

if (generateExitCode != 0) {
print('Generation failed; see above for errors.');
Expand Down
8 changes: 8 additions & 0 deletions packages/pigeon/tool/shared/generation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ String _javaFilenameForName(String inputName) {
return specialCases[inputName] ?? _snakeToPascalCase(inputName);
}

Future<int> generateExamplePigeons() async {
return runPigeon(
input: './example/app/pigeons/messages.dart',
basePath: './example/app',
suppressVersion: true,
);
}

Future<int> generateTestPigeons({required String baseDir}) async {
// TODO(stuartmorgan): Make this dynamic rather than hard-coded. Or eliminate
// it entirely; see https://github.com/flutter/flutter/issues/115169.
Expand Down