mirror of
https://github.com/flutter/packages.git
synced 2025-08-06 08:53:11 +08:00
add a --dart-sdk option to the repo analysis command (#3959)
This commit is contained in:
@ -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));
|
||||
|
@ -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>>[
|
||||
|
Reference in New Issue
Block a user