-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[pigeon] Support other hosts in generated file CI checks #5944
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
auto-submit
merged 16 commits into
flutter:main
from
stuartmorgan-g:pigeon-format-check
Jan 20, 2024
Merged
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bb14fc7
Temp hack for local testing
stuartmorgan-g cb16cfd
Include swift for testing
stuartmorgan-g f2ad42a
Add explicit language selection for formatting
stuartmorgan-g 3872d99
Per-platform language split
stuartmorgan-g cbdf3e9
Fully wire up
stuartmorgan-g 28c2e4a
Disable for now
stuartmorgan-g 262da18
Remove local hack
stuartmorgan-g b501fc7
Enable Swift check
stuartmorgan-g 8d6bcb3
Merge branch 'main' into pigeon-format-check
stuartmorgan-g e136357
Remove unconditional --no-swift
stuartmorgan-g aa1158a
Add .h for ObjC
stuartmorgan-g ae2c565
Merge remote-tracking branch 'upstream/main' into pigeon-format-check
stuartmorgan-g c505762
Remove generated code filter from Swift formatting
stuartmorgan-g f875c84
Autoformat generated output
stuartmorgan-g afaaf0d
Autoformat quick_actions
stuartmorgan-g ecce48d
Merge remote-tracking branch 'upstream/main' into pigeon-format-check
stuartmorgan-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ library; | |
|
|
||
| import 'dart:io'; | ||
|
|
||
| import 'package:collection/collection.dart'; | ||
| import 'package:path/path.dart' as p; | ||
|
|
||
| import 'shared/generation.dart'; | ||
|
|
@@ -35,62 +36,56 @@ void _validateTestCoverage(List<List<String>> shards) { | |
| } | ||
|
|
||
| Future<void> _validateGeneratedTestFiles() async { | ||
| final String baseDir = p.dirname(p.dirname(Platform.script.toFilePath())); | ||
| final String repositoryRoot = p.dirname(p.dirname(baseDir)); | ||
| final String relativePigeonPath = p.relative(baseDir, from: repositoryRoot); | ||
|
|
||
| print('Validating generated files:'); | ||
| print(' Generating test output...'); | ||
| final int generateExitCode = await generateTestPigeons(baseDir: baseDir); | ||
| if (generateExitCode != 0) { | ||
| print('Generation failed; see above for errors.'); | ||
| exit(generateExitCode); | ||
| } | ||
|
|
||
| print(' Formatting output...'); | ||
| final int formatExitCode = | ||
| await formatAllFiles(repositoryRoot: repositoryRoot); | ||
| if (formatExitCode != 0) { | ||
| print('Formatting failed; see above for errors.'); | ||
| exit(formatExitCode); | ||
| } | ||
| await _validateGeneratedFiles( | ||
| (String baseDir) => generateTestPigeons(baseDir: baseDir), | ||
| generationMessage: 'Generating test output', | ||
| incorrectFilesMessage: | ||
| 'The following files are not updated, or not formatted correctly:', | ||
| ); | ||
| } | ||
|
|
||
| print(' Checking for changes...'); | ||
| final List<String> modifiedFiles = await _modifiedFiles( | ||
| repositoryRoot: repositoryRoot, relativePigeonPath: relativePigeonPath); | ||
| Future<void> _validateGeneratedExampleFiles() async { | ||
| await _validateGeneratedFiles( | ||
| (String _) => generateExamplePigeons(), | ||
| generationMessage: 'Generating example output', | ||
| incorrectFilesMessage: | ||
| 'Either messages.dart and messages_test.dart have non-matching definitions or\n' | ||
| 'the following files are not updated, or not formatted correctly:', | ||
| ); | ||
| } | ||
|
|
||
| if (modifiedFiles.isEmpty) { | ||
| Future<void> _validateGeneratedFiles( | ||
| Future<int> Function(String baseDirectory) generator, { | ||
| required String generationMessage, | ||
| required String incorrectFilesMessage, | ||
| }) async { | ||
| // Generated file validation is split by platform, both to avoid duplication | ||
| // of work, and to avoid issues if different CI configurations have different | ||
| // setups (e.g., different clang-format versions or no clang-format at all). | ||
| final Set<GeneratorLanguage> languagesToValidate; | ||
| if (Platform.isLinux) { | ||
| languagesToValidate = <GeneratorLanguage>{ | ||
| GeneratorLanguage.cpp, | ||
| GeneratorLanguage.dart, | ||
| GeneratorLanguage.java, | ||
| GeneratorLanguage.kotlin, | ||
| GeneratorLanguage.objc, | ||
| }; | ||
| } else if (Platform.isMacOS) { | ||
| languagesToValidate = <GeneratorLanguage>{ | ||
| // TODO(stuartmorgan): Enable this in or after https://github.com/flutter/packages/pull/5928 | ||
| // GeneratorLanguage.swift, | ||
| }; | ||
| } else { | ||
| return; | ||
| } | ||
|
|
||
| print('The following files are not updated, or not formatted correctly:'); | ||
| modifiedFiles.map((String line) => ' $line').forEach(print); | ||
|
|
||
| print('\nTo fix run "dart run tool/generate.dart --format" from the pigeon/ ' | ||
| 'directory, or apply the diff with the command below.\n'); | ||
|
|
||
| final ProcessResult diffResult = await Process.run( | ||
| 'git', | ||
| <String>['diff', relativePigeonPath], | ||
| workingDirectory: repositoryRoot, | ||
| ); | ||
| if (diffResult.exitCode != 0) { | ||
| print('Unable to determine diff.'); | ||
| exit(1); | ||
| } | ||
| print('patch -p1 <<DONE'); | ||
| print(diffResult.stdout); | ||
| print('DONE'); | ||
| exit(1); | ||
| } | ||
|
|
||
| Future<void> _validateGeneratedExampleFiles() async { | ||
| final String baseDir = p.dirname(p.dirname(Platform.script.toFilePath())); | ||
| final String repositoryRoot = p.dirname(p.dirname(baseDir)); | ||
| final String relativePigeonPath = p.relative(baseDir, from: repositoryRoot); | ||
|
|
||
| print('Validating generated files:'); | ||
| print(' Generating example output...'); | ||
| print(' $generationMessage...'); | ||
|
|
||
| final int generateExitCode = await generateExamplePigeons(); | ||
|
|
||
|
|
@@ -100,8 +95,8 @@ Future<void> _validateGeneratedExampleFiles() async { | |
| } | ||
|
|
||
| print(' Formatting output...'); | ||
| final int formatExitCode = | ||
| await formatAllFiles(repositoryRoot: repositoryRoot); | ||
| final int formatExitCode = await formatAllFiles( | ||
| repositoryRoot: repositoryRoot, languages: languagesToValidate); | ||
| if (formatExitCode != 0) { | ||
| print('Formatting failed; see above for errors.'); | ||
| exit(formatExitCode); | ||
|
|
@@ -110,22 +105,26 @@ Future<void> _validateGeneratedExampleFiles() async { | |
| print(' Checking for changes...'); | ||
| final List<String> modifiedFiles = await _modifiedFiles( | ||
| repositoryRoot: repositoryRoot, relativePigeonPath: relativePigeonPath); | ||
|
|
||
| if (modifiedFiles.isEmpty) { | ||
| final Set<String> extensions = languagesToValidate | ||
| .map((GeneratorLanguage lang) => _extensionsForLanguage(lang)) | ||
| .flattened | ||
| .toSet(); | ||
| final Iterable<String> filteredFiles = modifiedFiles.where((String path) => | ||
| extensions.contains(p.extension(path).replaceFirst('.', ''))); | ||
|
|
||
| if (filteredFiles.isEmpty) { | ||
| return; | ||
| } | ||
|
|
||
| print( | ||
| 'Either messages.dart and messages_test.dart have non-matching definitions or'); | ||
| print('the following files are not updated, or not formatted correctly:'); | ||
| modifiedFiles.map((String line) => ' $line').forEach(print); | ||
| print(incorrectFilesMessage); | ||
| filteredFiles.map((String line) => ' $line').forEach(print); | ||
|
|
||
| print('\nTo fix run "dart run tool/generate.dart --format" from the pigeon/ ' | ||
| 'directory, or apply the diff with the command below.\n'); | ||
|
|
||
| final ProcessResult diffResult = await Process.run( | ||
| 'git', | ||
| <String>['diff', relativePigeonPath], | ||
| <String>['diff', ...filteredFiles], | ||
| workingDirectory: repositoryRoot, | ||
| ); | ||
| if (diffResult.exitCode != 0) { | ||
|
|
@@ -138,6 +137,17 @@ Future<void> _validateGeneratedExampleFiles() async { | |
| exit(1); | ||
| } | ||
|
|
||
| Set<String> _extensionsForLanguage(GeneratorLanguage language) { | ||
| return switch (language) { | ||
| GeneratorLanguage.cpp => <String>{'cc', 'cpp', 'h'}, | ||
| GeneratorLanguage.dart => <String>{'dart'}, | ||
| GeneratorLanguage.java => <String>{'java'}, | ||
| GeneratorLanguage.kotlin => <String>{'kt'}, | ||
| GeneratorLanguage.swift => <String>{'swift'}, | ||
| GeneratorLanguage.objc => <String>{'m', 'mm'}, | ||
|
||
| }; | ||
| } | ||
|
|
||
| Future<List<String>> _modifiedFiles( | ||
| {required String repositoryRoot, | ||
| required String relativePigeonPath}) async { | ||
|
|
@@ -204,20 +214,13 @@ Future<void> main(List<String> args) async { | |
| ], | ||
| ]); | ||
|
|
||
| // Ensure that all generated files are up to date. This is run only on Linux | ||
| // both to avoid duplication of work, and to avoid issues if different CI | ||
| // configurations have different setups (e.g., different clang-format versions | ||
| // or no clang-format at all). | ||
| if (Platform.isLinux) { | ||
| // Only run on master, since Dart format can change between versions. | ||
| // TODO(stuartmorgan): Make a more generic way to run this check only on | ||
| // master; this currently won't work for anything but Cirrus. | ||
| if (Platform.environment['CHANNEL'] == 'stable') { | ||
| print('Skipping generated file validation on stable.'); | ||
| } else { | ||
| await _validateGeneratedTestFiles(); | ||
| await _validateGeneratedExampleFiles(); | ||
| } | ||
| // Ensure that all generated files are up to date. | ||
| // Only run on master, since Dart format can change between versions. | ||
| if (Platform.environment['CHANNEL'] == 'stable') { | ||
| print('Skipping generated file validation on stable.'); | ||
| } else { | ||
| await _validateGeneratedTestFiles(); | ||
| await _validateGeneratedExampleFiles(); | ||
| } | ||
|
|
||
| final List<String> testsToRun; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged! #5928 (comment)