[tools] Remove single-example RepositoryPackage method (#5600)

This commit is contained in:
stuartmorgan
2022-05-03 13:59:11 -04:00
committed by GitHub
parent 1186d6831f
commit 5a06b47e51
6 changed files with 186 additions and 54 deletions

View File

@ -112,13 +112,4 @@ class RepositoryPackage {
.map((FileSystemEntity entity) =>
RepositoryPackage(entity as Directory));
}
/// Returns the example directory, assuming there is only one.
///
/// DO NOT USE THIS METHOD. It exists only to easily find code that was
/// written to use a single example and needs to be restructured to handle
/// multiple examples. New code should always use [getExamples].
// TODO(stuartmorgan): Eliminate all uses of this.
RepositoryPackage getSingleExampleDeprecated() =>
RepositoryPackage(directory.childDirectory('example'));
}

View File

@ -125,8 +125,7 @@ class DriveExamplesCommand extends PackageLoopingCommand {
Future<PackageResult> runForPackage(RepositoryPackage package) async {
final bool isPlugin = isFlutterPlugin(package);
if (package.isPlatformInterface &&
!package.getSingleExampleDeprecated().directory.existsSync()) {
if (package.isPlatformInterface && package.getExamples().isEmpty) {
// Platform interface packages generally aren't intended to have
// examples, and don't need integration tests, so skip rather than fail.
return PackageResult.skip(

View File

@ -119,7 +119,32 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
@override
Future<PackageResult> runForPackage(RepositoryPackage package) async {
final RepositoryPackage example = package.getSingleExampleDeprecated();
final List<PackageResult> results = <PackageResult>[];
for (final RepositoryPackage example in package.getExamples()) {
results.add(await _runForExample(example, package: package));
}
// If all results skipped, report skip overall.
if (results
.every((PackageResult result) => result.state == RunState.skipped)) {
return PackageResult.skip('No examples support Android.');
}
// Otherwise, report failure if there were any failures.
final List<String> allErrors = results
.map((PackageResult result) =>
result.state == RunState.failed ? result.details : <String>[])
.expand((List<String> list) => list)
.toList();
return allErrors.isEmpty
? PackageResult.success()
: PackageResult.fail(allErrors);
}
/// Runs the test for the given example of [package].
Future<PackageResult> _runForExample(
RepositoryPackage example, {
required RepositoryPackage package,
}) async {
final Directory androidDirectory =
example.directory.childDirectory('android');
if (!androidDirectory.existsSync()) {
@ -163,7 +188,7 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
// Used within the loop to ensure a unique GCS output location for each
// test file's run.
int resultsCounter = 0;
for (final File test in _findIntegrationTestFiles(package)) {
for (final File test in _findIntegrationTestFiles(example)) {
final String testName =
getRelativePosixPath(test, from: package.directory);
print('Testing $testName...');
@ -175,7 +200,8 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
final String buildId = getStringArg('build-id');
final String testRunId = getStringArg('test-run-id');
final String resultsDir =
'plugins_android_test/${package.displayName}/$buildId/$testRunId/${resultsCounter++}/';
'plugins_android_test/${package.displayName}/$buildId/$testRunId/'
'${example.directory.basename}/${resultsCounter++}/';
// Automatically retry failures; there is significant flake with these
// tests whose cause isn't yet understood, and having to re-run the
@ -299,12 +325,10 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
return true;
}
/// Finds and returns all integration test files for [package].
Iterable<File> _findIntegrationTestFiles(RepositoryPackage package) sync* {
final Directory integrationTestDir = package
.getSingleExampleDeprecated()
.directory
.childDirectory('integration_test');
/// Finds and returns all integration test files for [example].
Iterable<File> _findIntegrationTestFiles(RepositoryPackage example) sync* {
final Directory integrationTestDir =
example.directory.childDirectory('integration_test');
if (!integrationTestDir.existsSync()) {
return;

View File

@ -28,7 +28,7 @@ class LintAndroidCommand extends PackageLoopingCommand {
@override
final String description = 'Runs "gradlew lint" on Android plugins.\n\n'
'Requires the example to have been build at least once before running.';
'Requires the examples to have been build at least once before running.';
@override
Future<PackageResult> runForPackage(RepositoryPackage package) async {
@ -38,25 +38,30 @@ class LintAndroidCommand extends PackageLoopingCommand {
'Plugin does not have an Android implemenatation.');
}
final RepositoryPackage example = package.getSingleExampleDeprecated();
final GradleProject project = GradleProject(example.directory,
processRunner: processRunner, platform: platform);
bool failed = false;
for (final RepositoryPackage example in package.getExamples()) {
final GradleProject project = GradleProject(example.directory,
processRunner: processRunner, platform: platform);
if (!project.isConfigured()) {
return PackageResult.fail(<String>['Build example before linting']);
if (!project.isConfigured()) {
return PackageResult.fail(<String>['Build examples before linting']);
}
final String packageName = package.directory.basename;
// Only lint one build mode to avoid extra work.
// Only lint the plugin project itself, to avoid failing due to errors in
// dependencies.
//
// TODO(stuartmorgan): Consider adding an XML parser to read and summarize
// all results. Currently, only the first three errors will be shown
// inline, and the rest have to be checked via the CI-uploaded artifact.
final int exitCode = await project.runCommand('$packageName:lintDebug');
if (exitCode != 0) {
failed = true;
}
}
final String packageName = package.directory.basename;
// Only lint one build mode to avoid extra work.
// Only lint the plugin project itself, to avoid failing due to errors in
// dependencies.
//
// TODO(stuartmorgan): Consider adding an XML parser to read and summarize
// all results. Currently, only the first three errors will be shown inline,
// and the rest have to be checked via the CI-uploaded artifact.
final int exitCode = await project.runCommand('$packageName:lintDebug');
return exitCode == 0 ? PackageResult.success() : PackageResult.fail();
return failed ? PackageResult.fail() : PackageResult.success();
}
}