Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 87d2c84

Browse files
committed
Merge branch 'master' of https://github.com/flutter/plugins into video_player_android_rotation
2 parents 3033209 + fb66220 commit 87d2c84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+637
-525
lines changed

script/tool/lib/src/analyze_command.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import 'dart:async';
66

77
import 'package:file/file.dart';
8-
import 'package:flutter_plugin_tools/src/common/plugin_command.dart';
98
import 'package:platform/platform.dart';
109
import 'package:yaml/yaml.dart';
1110

1211
import 'common/core.dart';
1312
import 'common/package_looping_command.dart';
13+
import 'common/plugin_command.dart';
1414
import 'common/process_runner.dart';
15+
import 'common/repository_package.dart';
1516

1617
const int _exitPackagesGetFailed = 3;
1718

@@ -55,8 +56,9 @@ class AnalyzeCommand extends PackageLoopingCommand {
5556
final bool hasLongOutput = false;
5657

5758
/// Checks that there are no unexpected analysis_options.yaml files.
58-
bool _hasUnexpecetdAnalysisOptions(Directory package) {
59-
final List<FileSystemEntity> files = package.listSync(recursive: true);
59+
bool _hasUnexpecetdAnalysisOptions(RepositoryPackage package) {
60+
final List<FileSystemEntity> files =
61+
package.directory.listSync(recursive: true);
6062
for (final FileSystemEntity file in files) {
6163
if (file.basename != 'analysis_options.yaml' &&
6264
file.basename != '.analysis_options') {
@@ -87,7 +89,7 @@ class AnalyzeCommand extends PackageLoopingCommand {
8789
Future<bool> _runPackagesGetOnTargetPackages() async {
8890
final List<Directory> packageDirectories =
8991
await getTargetPackagesAndSubpackages()
90-
.map((PackageEnumerationEntry package) => package.directory)
92+
.map((PackageEnumerationEntry entry) => entry.package.directory)
9193
.toList();
9294
final Set<String> packagePaths =
9395
packageDirectories.map((Directory dir) => dir.path).toSet();
@@ -135,13 +137,13 @@ class AnalyzeCommand extends PackageLoopingCommand {
135137
}
136138

137139
@override
138-
Future<PackageResult> runForPackage(Directory package) async {
140+
Future<PackageResult> runForPackage(RepositoryPackage package) async {
139141
if (_hasUnexpecetdAnalysisOptions(package)) {
140142
return PackageResult.fail(<String>['Unexpected local analysis options']);
141143
}
142144
final int exitCode = await processRunner.runAndStream(
143145
_dartBinaryPath, <String>['analyze', '--fatal-infos'],
144-
workingDir: package);
146+
workingDir: package.directory);
145147
if (exitCode != 0) {
146148
return PackageResult.fail();
147149
}

script/tool/lib/src/build_examples_command.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'common/core.dart';
1111
import 'common/package_looping_command.dart';
1212
import 'common/plugin_utils.dart';
1313
import 'common/process_runner.dart';
14+
import 'common/repository_package.dart';
1415

1516
/// Key for APK.
1617
const String _platformFlagApk = 'apk';
@@ -96,7 +97,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
9697
}
9798

9899
@override
99-
Future<PackageResult> runForPackage(Directory package) async {
100+
Future<PackageResult> runForPackage(RepositoryPackage package) async {
100101
final List<String> errors = <String>[];
101102

102103
final Iterable<_PlatformDetails> requestedPlatforms = _platforms.entries
@@ -126,9 +127,9 @@ class BuildExamplesCommand extends PackageLoopingCommand {
126127
}
127128
print('');
128129

129-
for (final Directory example in getExamplesForPlugin(package)) {
130+
for (final RepositoryPackage example in package.getExamples()) {
130131
final String packageName =
131-
getRelativePosixPath(example, from: packagesDir);
132+
getRelativePosixPath(example.directory, from: packagesDir);
132133

133134
for (final _PlatformDetails platform in buildPlatforms) {
134135
String buildPlatform = platform.label;
@@ -149,7 +150,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
149150
}
150151

151152
Future<bool> _buildExample(
152-
Directory example,
153+
RepositoryPackage example,
153154
String flutterBuildType, {
154155
List<String> extraBuildFlags = const <String>[],
155156
}) async {
@@ -164,7 +165,7 @@ class BuildExamplesCommand extends PackageLoopingCommand {
164165
if (enableExperiment.isNotEmpty)
165166
'--enable-experiment=$enableExperiment',
166167
],
167-
workingDir: example,
168+
workingDir: example.directory,
168169
);
169170
return exitCode == 0;
170171
}

script/tool/lib/src/common/package_looping_command.dart

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:platform/platform.dart';
1313
import 'core.dart';
1414
import 'plugin_command.dart';
1515
import 'process_runner.dart';
16+
import 'repository_package.dart';
1617

1718
/// Possible outcomes of a command run for a package.
1819
enum RunState {
@@ -84,7 +85,7 @@ abstract class PackageLoopingCommand extends PluginCommand {
8485
int _otherWarningCount = 0;
8586

8687
/// The package currently being run by [runForPackage].
87-
PackageEnumerationEntry? _currentPackage;
88+
PackageEnumerationEntry? _currentPackageEntry;
8889

8990
/// Called during [run] before any calls to [runForPackage]. This provides an
9091
/// opportunity to fail early if the command can't be run (e.g., because the
@@ -97,7 +98,7 @@ abstract class PackageLoopingCommand extends PluginCommand {
9798
/// be included in the final error summary (e.g., a command that only has a
9899
/// single failure mode), or strings that should be listed for that package
99100
/// in the final summary. An empty list indicates success.
100-
Future<PackageResult> runForPackage(Directory package);
101+
Future<PackageResult> runForPackage(RepositoryPackage package);
101102

102103
/// Called during [run] after all calls to [runForPackage]. This provides an
103104
/// opportunity to do any cleanup of run-level state.
@@ -155,31 +156,13 @@ abstract class PackageLoopingCommand extends PluginCommand {
155156
/// things that might be useful to someone debugging an unexpected result.
156157
void logWarning(String warningMessage) {
157158
print(Colorize(warningMessage)..yellow());
158-
if (_currentPackage != null) {
159-
_packagesWithWarnings.add(_currentPackage!);
159+
if (_currentPackageEntry != null) {
160+
_packagesWithWarnings.add(_currentPackageEntry!);
160161
} else {
161162
++_otherWarningCount;
162163
}
163164
}
164165

165-
/// Returns the identifying name to use for [package].
166-
///
167-
/// Implementations should not expect a specific format for this string, since
168-
/// it uses heuristics to try to be precise without being overly verbose. If
169-
/// an exact format (e.g., published name, or basename) is required, that
170-
/// should be used instead.
171-
String getPackageDescription(Directory package) {
172-
String packageName = getRelativePosixPath(package, from: packagesDir);
173-
final List<String> components = p.posix.split(packageName);
174-
// For the common federated plugin pattern of `foo/foo_subpackage`, drop
175-
// the first part since it's not useful.
176-
if (components.length >= 2 &&
177-
components[1].startsWith('${components[0]}_')) {
178-
packageName = p.posix.joinAll(components.sublist(1));
179-
}
180-
return packageName;
181-
}
182-
183166
/// Returns the relative path from [from] to [entity] in Posix style.
184167
///
185168
/// This should be used when, for example, printing package-relative paths in
@@ -219,50 +202,50 @@ abstract class PackageLoopingCommand extends PluginCommand {
219202
Future<bool> _runInternal() async {
220203
_packagesWithWarnings.clear();
221204
_otherWarningCount = 0;
222-
_currentPackage = null;
205+
_currentPackageEntry = null;
223206

224207
await initializeRun();
225208

226-
final List<PackageEnumerationEntry> packages = includeSubpackages
209+
final List<PackageEnumerationEntry> targetPackages = includeSubpackages
227210
? await getTargetPackagesAndSubpackages(filterExcluded: false).toList()
228211
: await getTargetPackages(filterExcluded: false).toList();
229212

230213
final Map<PackageEnumerationEntry, PackageResult> results =
231214
<PackageEnumerationEntry, PackageResult>{};
232-
for (final PackageEnumerationEntry package in packages) {
233-
_currentPackage = package;
234-
_printPackageHeading(package);
215+
for (final PackageEnumerationEntry entry in targetPackages) {
216+
_currentPackageEntry = entry;
217+
_printPackageHeading(entry);
235218

236219
// Command implementations should never see excluded packages; they are
237220
// included at this level only for logging.
238-
if (package.excluded) {
239-
results[package] = PackageResult.exclude();
221+
if (entry.excluded) {
222+
results[entry] = PackageResult.exclude();
240223
continue;
241224
}
242225

243-
final PackageResult result = await runForPackage(package.directory);
226+
final PackageResult result = await runForPackage(entry.package);
244227
if (result.state == RunState.skipped) {
245228
final String message =
246229
'${indentation}SKIPPING: ${result.details.first}';
247230
captureOutput ? print(message) : print(Colorize(message)..darkGray());
248231
}
249-
results[package] = result;
232+
results[entry] = result;
250233
}
251-
_currentPackage = null;
234+
_currentPackageEntry = null;
252235

253236
completeRun();
254237

255238
print('\n');
256239
// If there were any errors reported, summarize them and exit.
257240
if (results.values
258241
.any((PackageResult result) => result.state == RunState.failed)) {
259-
_printFailureSummary(packages, results);
242+
_printFailureSummary(targetPackages, results);
260243
return false;
261244
}
262245

263246
// Otherwise, print a summary of what ran for ease of auditing that all the
264247
// expected tests ran.
265-
_printRunSummary(packages, results);
248+
_printRunSummary(targetPackages, results);
266249

267250
print('\n');
268251
_printSuccess('No issues found!');
@@ -283,9 +266,9 @@ abstract class PackageLoopingCommand extends PluginCommand {
283266
/// Something is always printed to make it easier to distinguish between
284267
/// a command running for a package and producing no output, and a command
285268
/// not having been run for a package.
286-
void _printPackageHeading(PackageEnumerationEntry package) {
287-
final String packageDisplayName = getPackageDescription(package.directory);
288-
String heading = package.excluded
269+
void _printPackageHeading(PackageEnumerationEntry entry) {
270+
final String packageDisplayName = entry.package.displayName;
271+
String heading = entry.excluded
289272
? 'Not running for $packageDisplayName; excluded'
290273
: 'Running for $packageDisplayName';
291274
if (hasLongOutput) {
@@ -295,16 +278,15 @@ abstract class PackageLoopingCommand extends PluginCommand {
295278
|| $heading
296279
============================================================
297280
''';
298-
} else if (!package.excluded) {
281+
} else if (!entry.excluded) {
299282
heading = '$heading...';
300283
}
301284
if (captureOutput) {
302285
print(heading);
303286
} else {
304287
final Colorize colorizeHeading = Colorize(heading);
305-
print(package.excluded
306-
? colorizeHeading.darkGray()
307-
: colorizeHeading.cyan());
288+
print(
289+
entry.excluded ? colorizeHeading.darkGray() : colorizeHeading.cyan());
308290
}
309291
}
310292

@@ -349,17 +331,18 @@ abstract class PackageLoopingCommand extends PluginCommand {
349331

350332
/// Prints a one-line-per-package overview of the run results for each
351333
/// package.
352-
void _printPerPackageRunOverview(List<PackageEnumerationEntry> packages,
334+
void _printPerPackageRunOverview(
335+
List<PackageEnumerationEntry> packageEnumeration,
353336
{required Set<PackageEnumerationEntry> skipped}) {
354337
print('Run overview:');
355-
for (final PackageEnumerationEntry package in packages) {
356-
final bool hadWarning = _packagesWithWarnings.contains(package);
338+
for (final PackageEnumerationEntry entry in packageEnumeration) {
339+
final bool hadWarning = _packagesWithWarnings.contains(entry);
357340
Styles style;
358341
String summary;
359-
if (package.excluded) {
342+
if (entry.excluded) {
360343
summary = 'excluded';
361344
style = Styles.DARK_GRAY;
362-
} else if (skipped.contains(package)) {
345+
} else if (skipped.contains(entry)) {
363346
summary = 'skipped';
364347
style = hadWarning ? Styles.LIGHT_YELLOW : Styles.DARK_GRAY;
365348
} else {
@@ -373,27 +356,26 @@ abstract class PackageLoopingCommand extends PluginCommand {
373356
if (!captureOutput) {
374357
summary = (Colorize(summary)..apply(style)).toString();
375358
}
376-
print(' ${getPackageDescription(package.directory)} - $summary');
359+
print(' ${entry.package.displayName} - $summary');
377360
}
378361
print('');
379362
}
380363

381364
/// Prints a summary of all of the failures from [results].
382-
void _printFailureSummary(List<PackageEnumerationEntry> packages,
365+
void _printFailureSummary(List<PackageEnumerationEntry> packageEnumeration,
383366
Map<PackageEnumerationEntry, PackageResult> results) {
384367
const String indentation = ' ';
385368
_printError(failureListHeader);
386-
for (final PackageEnumerationEntry package in packages) {
387-
final PackageResult result = results[package]!;
369+
for (final PackageEnumerationEntry entry in packageEnumeration) {
370+
final PackageResult result = results[entry]!;
388371
if (result.state == RunState.failed) {
389372
final String errorIndentation = indentation * 2;
390373
String errorDetails = '';
391374
if (result.details.isNotEmpty) {
392375
errorDetails =
393376
':\n$errorIndentation${result.details.join('\n$errorIndentation')}';
394377
}
395-
_printError(
396-
'$indentation${getPackageDescription(package.directory)}$errorDetails');
378+
_printError('$indentation${entry.package.displayName}$errorDetails');
397379
}
398380
}
399381
_printError(failureListFooter);

0 commit comments

Comments
 (0)