Make --flutter-repo analyze whole repo (#127990)
Fixes https://github.com/flutter/flutter/issues/127989.
This commit is contained in:
committed by
GitHub
parent
7febf62c83
commit
95cd3c0340
@@ -176,7 +176,6 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
} else if (boolArg('watch')) {
|
||||
await AnalyzeContinuously(
|
||||
argResults!,
|
||||
runner!.getRepoRoots(),
|
||||
runner!.getRepoPackages(),
|
||||
fileSystem: _fileSystem,
|
||||
logger: _logger,
|
||||
@@ -189,7 +188,6 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
} else {
|
||||
await AnalyzeOnce(
|
||||
argResults!,
|
||||
runner!.getRepoRoots(),
|
||||
runner!.getRepoPackages(),
|
||||
workingDirectory: workingDirectory,
|
||||
fileSystem: _fileSystem,
|
||||
|
||||
@@ -20,7 +20,6 @@ import '../globals.dart' as globals;
|
||||
/// Common behavior for `flutter analyze` and `flutter analyze --watch`
|
||||
abstract class AnalyzeBase {
|
||||
AnalyzeBase(this.argResults, {
|
||||
required this.repoRoots,
|
||||
required this.repoPackages,
|
||||
required this.fileSystem,
|
||||
required this.logger,
|
||||
@@ -34,8 +33,6 @@ abstract class AnalyzeBase {
|
||||
/// The parsed argument results for execution.
|
||||
final ArgResults argResults;
|
||||
@protected
|
||||
final List<String> repoRoots;
|
||||
@protected
|
||||
final List<Directory> repoPackages;
|
||||
@protected
|
||||
final FileSystem fileSystem;
|
||||
@@ -52,6 +49,9 @@ abstract class AnalyzeBase {
|
||||
@protected
|
||||
final bool suppressAnalytics;
|
||||
|
||||
@protected
|
||||
String get flutterRoot => globals.fs.path.absolute(Cache.flutterRoot!);
|
||||
|
||||
/// Called by [AnalyzeCommand] to start the analysis process.
|
||||
Future<void> analyze();
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import 'analyze_base.dart';
|
||||
class AnalyzeContinuously extends AnalyzeBase {
|
||||
AnalyzeContinuously(
|
||||
super.argResults,
|
||||
List<String> repoRoots,
|
||||
List<Directory> repoPackages, {
|
||||
required super.fileSystem,
|
||||
required super.logger,
|
||||
@@ -24,7 +23,6 @@ class AnalyzeContinuously extends AnalyzeBase {
|
||||
required super.suppressAnalytics,
|
||||
}) : super(
|
||||
repoPackages: repoPackages,
|
||||
repoRoots: repoRoots,
|
||||
);
|
||||
|
||||
String? analysisTarget;
|
||||
@@ -43,13 +41,10 @@ class AnalyzeContinuously extends AnalyzeBase {
|
||||
final PackageDependencyTracker dependencies = PackageDependencyTracker();
|
||||
dependencies.checkForConflictingDependencies(repoPackages, dependencies);
|
||||
|
||||
directories = repoRoots;
|
||||
directories = <String>[flutterRoot];
|
||||
analysisTarget = 'Flutter repository';
|
||||
|
||||
logger.printTrace('Analyzing Flutter repository:');
|
||||
for (final String projectPath in repoRoots) {
|
||||
logger.printTrace(' ${fileSystem.path.relative(projectPath)}');
|
||||
}
|
||||
} else {
|
||||
directories = <String>[fileSystem.currentDirectory.path];
|
||||
analysisTarget = fileSystem.currentDirectory.path;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
@@ -14,7 +13,6 @@ import 'analyze_base.dart';
|
||||
class AnalyzeOnce extends AnalyzeBase {
|
||||
AnalyzeOnce(
|
||||
super.argResults,
|
||||
List<String> repoRoots,
|
||||
List<Directory> repoPackages, {
|
||||
required super.fileSystem,
|
||||
required super.logger,
|
||||
@@ -25,7 +23,6 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
required super.suppressAnalytics,
|
||||
this.workingDirectory,
|
||||
}) : super(
|
||||
repoRoots: repoRoots,
|
||||
repoPackages: repoPackages,
|
||||
);
|
||||
|
||||
@@ -42,7 +39,7 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
// check for conflicting dependencies
|
||||
final PackageDependencyTracker dependencies = PackageDependencyTracker();
|
||||
dependencies.checkForConflictingDependencies(repoPackages, dependencies);
|
||||
items.addAll(repoRoots);
|
||||
items.add(flutterRoot);
|
||||
if (argResults.wasParsed('current-package') && (argResults['current-package'] as bool)) {
|
||||
items.add(currentDirectory);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
@@ -118,6 +121,40 @@ void main() {
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
});
|
||||
|
||||
testUsingContext('--flutter-repo analyzes everything in the flutterRoot', () async {
|
||||
final StreamController<List<int>> streamController = StreamController<List<int>>();
|
||||
final IOSink sink = IOSink(streamController.sink);
|
||||
processManager.addCommands(
|
||||
<FakeCommand>[
|
||||
FakeCommand(
|
||||
// artifact paths are from Artifacts.test() and stable
|
||||
command: const <String>[
|
||||
'Artifact.engineDartSdkPath/bin/dart',
|
||||
'--disable-dart-dev',
|
||||
'Artifact.engineDartSdkPath/bin/snapshots/analysis_server.dart.snapshot',
|
||||
'--disable-server-feature-completion',
|
||||
'--disable-server-feature-search',
|
||||
'--sdk',
|
||||
'Artifact.engineDartSdkPath',
|
||||
'--suppress-analytics',
|
||||
],
|
||||
stdin: sink,
|
||||
stdout: '{"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}',
|
||||
),
|
||||
],
|
||||
);
|
||||
await runner.run(<String>['analyze', '--flutter-repo']);
|
||||
final Map<String, Object?> setAnalysisRootsCommand = jsonDecode(await streamController.stream.transform(utf8.decoder).elementAt(2)) as Map<String, Object?>;
|
||||
expect(setAnalysisRootsCommand['method'], 'analysis.setAnalysisRoots');
|
||||
final Map<String, Object?> params = setAnalysisRootsCommand['params']! as Map<String, Object?>;
|
||||
expect(params['included'], <String?>[Cache.flutterRoot]);
|
||||
expect(params['excluded'], isEmpty);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext('analyze inRepo', () {
|
||||
|
||||
Reference in New Issue
Block a user