Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
speed up the pub get portion of the analyze command
  • Loading branch information
devoncarew committed May 27, 2021
commit 90674e4a6615064cc59f1a3c0ecdeb3e8176cf84
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 List<String> packagePaths =
packageDirectories.map((Directory dir) => dir.path).toList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toSet()? You're only using this for inclusion testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change

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);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping we could just use getPlugins instead of doing the filtering, but it looks like flutter/packages has some other nested constructions.

Copy link
Contributor Author

@devoncarew devoncarew May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would prefer something more semantic here as well. The logic for how these are computed - getPlugins() and getPackages() - seems complicated, and I wasn't comfortable modifying it.

It looks like plugins actually returns packages? And packages returns packages plus their example directories?

I would have assumed that getPlugins() would return the directory containing the n dart packages that make up a plugin - like url_launcher/, url_launcher_platform_interface/, url_launcher_macos/, ...

I'll want a call like that - the top level plugin directory - for a follow up PR, where I'm going to try and speed up the analysis portion of the analyze call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like plugins actually returns packages? And packages returns packages plus there example directories?

I suspect what happened is that this was written for flutter/plugins, then expanded for use in flutter/packages without renaming. Fixing the fact that "plugins" is used to refer to packages in general in the tool (including the --plugins argument) is on my list.

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
18 changes: 18 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,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(<String>['analyze']);

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test of a package with a sub-package that's not example, to make sure nobody makes the "simplification" that I was about to suggest before checking flutter/packages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have one like that already - the analyzes all packages test - but I can add one where the 2nd package is named 'example' but not contained by the 1st package.

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

Expand Down