From 90674e4a6615064cc59f1a3c0ecdeb3e8176cf84 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 27 May 2021 09:22:54 -0700 Subject: [PATCH 1/2] speed up the pub get portion of the analyze command --- script/tool/lib/src/analyze_command.dart | 10 ++++++++++ script/tool/test/analyze_command_test.dart | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/script/tool/lib/src/analyze_command.dart b/script/tool/lib/src/analyze_command.dart index b36c43e6b968..79ce07e19709 100644 --- a/script/tool/lib/src/analyze_command.dart +++ b/script/tool/lib/src/analyze_command.dart @@ -41,6 +41,7 @@ class AnalyzeCommand extends PluginCommand { @override Future run() async { print('Verifying analysis settings...'); + final List files = packagesDir.listSync(recursive: true); for (final FileSystemEntity file in files) { if (file.basename != 'analysis_options.yaml' && @@ -64,6 +65,14 @@ class AnalyzeCommand extends PluginCommand { } final List packageDirectories = await getPackages().toList(); + final List packagePaths = + packageDirectories.map((Directory dir) => dir.path).toList(); + 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', ['packages', 'get'], workingDir: package, exitOnError: true); @@ -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) { diff --git a/script/tool/test/analyze_command_test.dart b/script/tool/test/analyze_command_test.dart index 5e548cb27a99..0bf5809b938e 100644 --- a/script/tool/test/analyze_command_test.dart +++ b/script/tool/test/analyze_command_test.dart @@ -53,6 +53,24 @@ 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(['analyze']); + + expect( + processRunner.recordedCalls, + orderedEquals([ + ProcessCall( + 'flutter', const ['packages', 'get'], plugin1Dir.path), + ProcessCall('dart', const ['analyze', '--fatal-infos'], + plugin1Dir.path), + ])); + }); + test('uses a separate analysis sdk', () async { final Directory pluginDir = createFakePlugin('a'); From 8364bf0bbd03f124c9dca57ab3a2b501b116922f Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 27 May 2021 10:40:30 -0700 Subject: [PATCH 2/2] review comments; add additional test --- script/tool/lib/src/analyze_command.dart | 4 ++-- script/tool/test/analyze_command_test.dart | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/script/tool/lib/src/analyze_command.dart b/script/tool/lib/src/analyze_command.dart index 79ce07e19709..872645ec16cb 100644 --- a/script/tool/lib/src/analyze_command.dart +++ b/script/tool/lib/src/analyze_command.dart @@ -65,8 +65,8 @@ class AnalyzeCommand extends PluginCommand { } final List packageDirectories = await getPackages().toList(); - final List packagePaths = - packageDirectories.map((Directory dir) => dir.path).toList(); + final Set 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. diff --git a/script/tool/test/analyze_command_test.dart b/script/tool/test/analyze_command_test.dart index 0bf5809b938e..b536c2bb989c 100644 --- a/script/tool/test/analyze_command_test.dart +++ b/script/tool/test/analyze_command_test.dart @@ -71,6 +71,29 @@ void main() { ])); }); + 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(['analyze']); + + expect( + processRunner.recordedCalls, + orderedEquals([ + ProcessCall( + 'flutter', const ['packages', 'get'], plugin1Dir.path), + ProcessCall( + 'flutter', const ['packages', 'get'], plugin2Dir.path), + ProcessCall('dart', const ['analyze', '--fatal-infos'], + plugin1Dir.path), + ProcessCall('dart', const ['analyze', '--fatal-infos'], + plugin2Dir.path), + ])); + }); + test('uses a separate analysis sdk', () async { final Directory pluginDir = createFakePlugin('a');