add a --dart-sdk option to the repo analysis command (#3959)

This commit is contained in:
Devon Carew
2021-05-24 08:44:06 -07:00
committed by GitHub
parent 04181cf38c
commit 544cab7f39
2 changed files with 39 additions and 3 deletions

View File

@ -19,12 +19,18 @@ class AnalyzeCommand extends PluginCommand {
}) : super(packagesDir, fileSystem, processRunner: processRunner) {
argParser.addMultiOption(_customAnalysisFlag,
help:
'Directories (comma seperated) that are allowed to have their own analysis options.',
'Directories (comma separated) that are allowed to have their own analysis options.',
defaultsTo: <String>[]);
argParser.addOption(_analysisSdk,
valueHelp: 'dart-sdk',
help: 'An optional path to a Dart SDK; this is used to override the '
'SDK used to provide analysis.');
}
static const String _customAnalysisFlag = 'custom-analysis';
static const String _analysisSdk = 'analysis-sdk';
@override
final String name = 'analyze';
@ -62,15 +68,20 @@ class AnalyzeCommand extends PluginCommand {
await processRunner.runAndStream('flutter', <String>['packages', 'get'],
workingDir: package, exitOnError: true);
} else {
await processRunner.runAndStream('pub', <String>['get'],
await processRunner.runAndStream('dart', <String>['pub', 'get'],
workingDir: package, exitOnError: true);
}
}
// Use the Dart SDK override if one was passed in.
final String? dartSdk = argResults![_analysisSdk] as String?;
final String dartBinary =
dartSdk == null ? 'dart' : p.join(dartSdk, 'bin', 'dart');
final List<String> failingPackages = <String>[];
await for (final Directory package in getPlugins()) {
final int exitCode = await processRunner.runAndStream(
'dart', <String>['analyze', '--fatal-infos'],
dartBinary, <String>['analyze', '--fatal-infos'],
workingDir: package);
if (exitCode != 0) {
failingPackages.add(p.basename(package.path));

View File

@ -53,6 +53,31 @@ void main() {
]));
});
test('uses a separate analysis sdk', () async {
final Directory pluginDir = createFakePlugin('a');
final MockProcess mockProcess = MockProcess();
mockProcess.exitCodeCompleter.complete(0);
processRunner.processToReturn = mockProcess;
await runner.run(<String>['analyze', '--analysis-sdk', 'foo/bar/baz']);
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
'flutter',
const <String>['packages', 'get'],
pluginDir.path,
),
ProcessCall(
'foo/bar/baz/bin/dart',
const <String>['analyze', '--fatal-infos'],
pluginDir.path,
),
]),
);
});
group('verifies analysis settings', () {
test('fails analysis_options.yaml', () async {
createFakePlugin('foo', withExtraFiles: <List<String>>[