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

Commit 2807531

Browse files
authored
[script/tool] speed up the pub get portion of the analyze command (#3982)
1 parent 4ef31b6 commit 2807531

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

script/tool/lib/src/analyze_command.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class AnalyzeCommand extends PluginCommand {
4141
@override
4242
Future<void> run() async {
4343
print('Verifying analysis settings...');
44+
4445
final List<FileSystemEntity> files = packagesDir.listSync(recursive: true);
4546
for (final FileSystemEntity file in files) {
4647
if (file.basename != 'analysis_options.yaml' &&
@@ -64,6 +65,14 @@ class AnalyzeCommand extends PluginCommand {
6465
}
6566

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

8897
print('\n\n');
98+
8999
if (failingPackages.isNotEmpty) {
90100
print('The following packages have analyzer errors (see above):');
91101
for (final String package in failingPackages) {

script/tool/test/analyze_command_test.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,47 @@ void main() {
5353
]));
5454
});
5555

56+
test('skips flutter pub get for examples', () async {
57+
final Directory plugin1Dir = createFakePlugin('a', withSingleExample: true);
58+
59+
final MockProcess mockProcess = MockProcess();
60+
mockProcess.exitCodeCompleter.complete(0);
61+
processRunner.processToReturn = mockProcess;
62+
await runner.run(<String>['analyze']);
63+
64+
expect(
65+
processRunner.recordedCalls,
66+
orderedEquals(<ProcessCall>[
67+
ProcessCall(
68+
'flutter', const <String>['packages', 'get'], plugin1Dir.path),
69+
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
70+
plugin1Dir.path),
71+
]));
72+
});
73+
74+
test('don\'t elide a non-contained example package', () async {
75+
final Directory plugin1Dir = createFakePlugin('a');
76+
final Directory plugin2Dir = createFakePlugin('example');
77+
78+
final MockProcess mockProcess = MockProcess();
79+
mockProcess.exitCodeCompleter.complete(0);
80+
processRunner.processToReturn = mockProcess;
81+
await runner.run(<String>['analyze']);
82+
83+
expect(
84+
processRunner.recordedCalls,
85+
orderedEquals(<ProcessCall>[
86+
ProcessCall(
87+
'flutter', const <String>['packages', 'get'], plugin1Dir.path),
88+
ProcessCall(
89+
'flutter', const <String>['packages', 'get'], plugin2Dir.path),
90+
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
91+
plugin1Dir.path),
92+
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
93+
plugin2Dir.path),
94+
]));
95+
});
96+
5697
test('uses a separate analysis sdk', () async {
5798
final Directory pluginDir = createFakePlugin('a');
5899

0 commit comments

Comments
 (0)