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

Commit

Permalink
[script/tool] speed up the pub get portion of the analyze command (#3982
Browse files Browse the repository at this point in the history
)
  • Loading branch information
devoncarew authored May 27, 2021
1 parent 4ef31b6 commit 2807531
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions script/tool/lib/src/analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AnalyzeCommand extends PluginCommand {
@override
Future<void> run() async {
print('Verifying analysis settings...');

final List<FileSystemEntity> files = packagesDir.listSync(recursive: true);
for (final FileSystemEntity file in files) {
if (file.basename != 'analysis_options.yaml' &&
Expand All @@ -64,6 +65,14 @@ class AnalyzeCommand extends PluginCommand {
}

final List<Directory> packageDirectories = await getPackages().toList();
final Set<String> packagePaths =
packageDirectories.map((Directory dir) => dir.path).toSet();
packageDirectories.removeWhere((Directory directory) {
// We remove the 'example' subdirectories - 'flutter pub get' automatically
// runs 'pub get' there as part of handling the parent directory.
return directory.basename == 'example' &&
packagePaths.contains(directory.parent.path);
});
for (final Directory package in packageDirectories) {
await processRunner.runAndStream('flutter', <String>['packages', 'get'],
workingDir: package, exitOnError: true);
Expand All @@ -86,6 +95,7 @@ class AnalyzeCommand extends PluginCommand {
}

print('\n\n');

if (failingPackages.isNotEmpty) {
print('The following packages have analyzer errors (see above):');
for (final String package in failingPackages) {
Expand Down
41 changes: 41 additions & 0 deletions script/tool/test/analyze_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,47 @@ void main() {
]));
});

test('skips flutter pub get for examples', () async {
final Directory plugin1Dir = createFakePlugin('a', withSingleExample: true);

final MockProcess mockProcess = MockProcess();
mockProcess.exitCodeCompleter.complete(0);
processRunner.processToReturn = mockProcess;
await runner.run(<String>['analyze']);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
'flutter', const <String>['packages', 'get'], plugin1Dir.path),
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
plugin1Dir.path),
]));
});

test('don\'t elide a non-contained example package', () async {
final Directory plugin1Dir = createFakePlugin('a');
final Directory plugin2Dir = createFakePlugin('example');

final MockProcess mockProcess = MockProcess();
mockProcess.exitCodeCompleter.complete(0);
processRunner.processToReturn = mockProcess;
await runner.run(<String>['analyze']);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
'flutter', const <String>['packages', 'get'], plugin1Dir.path),
ProcessCall(
'flutter', const <String>['packages', 'get'], plugin2Dir.path),
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
plugin1Dir.path),
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
plugin2Dir.path),
]));
});

test('uses a separate analysis sdk', () async {
final Directory pluginDir = createFakePlugin('a');

Expand Down

0 comments on commit 2807531

Please sign in to comment.