Unverified Commit 95cd3c03 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Make --flutter-repo analyze whole repo (#127990)

Fixes https://github.com/flutter/flutter/issues/127989.
parent 7febf62c
...@@ -176,7 +176,6 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -176,7 +176,6 @@ class AnalyzeCommand extends FlutterCommand {
} else if (boolArg('watch')) { } else if (boolArg('watch')) {
await AnalyzeContinuously( await AnalyzeContinuously(
argResults!, argResults!,
runner!.getRepoRoots(),
runner!.getRepoPackages(), runner!.getRepoPackages(),
fileSystem: _fileSystem, fileSystem: _fileSystem,
logger: _logger, logger: _logger,
...@@ -189,7 +188,6 @@ class AnalyzeCommand extends FlutterCommand { ...@@ -189,7 +188,6 @@ class AnalyzeCommand extends FlutterCommand {
} else { } else {
await AnalyzeOnce( await AnalyzeOnce(
argResults!, argResults!,
runner!.getRepoRoots(),
runner!.getRepoPackages(), runner!.getRepoPackages(),
workingDirectory: workingDirectory, workingDirectory: workingDirectory,
fileSystem: _fileSystem, fileSystem: _fileSystem,
......
...@@ -20,7 +20,6 @@ import '../globals.dart' as globals; ...@@ -20,7 +20,6 @@ import '../globals.dart' as globals;
/// Common behavior for `flutter analyze` and `flutter analyze --watch` /// Common behavior for `flutter analyze` and `flutter analyze --watch`
abstract class AnalyzeBase { abstract class AnalyzeBase {
AnalyzeBase(this.argResults, { AnalyzeBase(this.argResults, {
required this.repoRoots,
required this.repoPackages, required this.repoPackages,
required this.fileSystem, required this.fileSystem,
required this.logger, required this.logger,
...@@ -34,8 +33,6 @@ abstract class AnalyzeBase { ...@@ -34,8 +33,6 @@ abstract class AnalyzeBase {
/// The parsed argument results for execution. /// The parsed argument results for execution.
final ArgResults argResults; final ArgResults argResults;
@protected @protected
final List<String> repoRoots;
@protected
final List<Directory> repoPackages; final List<Directory> repoPackages;
@protected @protected
final FileSystem fileSystem; final FileSystem fileSystem;
...@@ -52,6 +49,9 @@ abstract class AnalyzeBase { ...@@ -52,6 +49,9 @@ abstract class AnalyzeBase {
@protected @protected
final bool suppressAnalytics; final bool suppressAnalytics;
@protected
String get flutterRoot => globals.fs.path.absolute(Cache.flutterRoot!);
/// Called by [AnalyzeCommand] to start the analysis process. /// Called by [AnalyzeCommand] to start the analysis process.
Future<void> analyze(); Future<void> analyze();
......
...@@ -13,7 +13,6 @@ import 'analyze_base.dart'; ...@@ -13,7 +13,6 @@ import 'analyze_base.dart';
class AnalyzeContinuously extends AnalyzeBase { class AnalyzeContinuously extends AnalyzeBase {
AnalyzeContinuously( AnalyzeContinuously(
super.argResults, super.argResults,
List<String> repoRoots,
List<Directory> repoPackages, { List<Directory> repoPackages, {
required super.fileSystem, required super.fileSystem,
required super.logger, required super.logger,
...@@ -24,7 +23,6 @@ class AnalyzeContinuously extends AnalyzeBase { ...@@ -24,7 +23,6 @@ class AnalyzeContinuously extends AnalyzeBase {
required super.suppressAnalytics, required super.suppressAnalytics,
}) : super( }) : super(
repoPackages: repoPackages, repoPackages: repoPackages,
repoRoots: repoRoots,
); );
String? analysisTarget; String? analysisTarget;
...@@ -43,13 +41,10 @@ class AnalyzeContinuously extends AnalyzeBase { ...@@ -43,13 +41,10 @@ class AnalyzeContinuously extends AnalyzeBase {
final PackageDependencyTracker dependencies = PackageDependencyTracker(); final PackageDependencyTracker dependencies = PackageDependencyTracker();
dependencies.checkForConflictingDependencies(repoPackages, dependencies); dependencies.checkForConflictingDependencies(repoPackages, dependencies);
directories = repoRoots; directories = <String>[flutterRoot];
analysisTarget = 'Flutter repository'; analysisTarget = 'Flutter repository';
logger.printTrace('Analyzing Flutter repository:'); logger.printTrace('Analyzing Flutter repository:');
for (final String projectPath in repoRoots) {
logger.printTrace(' ${fileSystem.path.relative(projectPath)}');
}
} else { } else {
directories = <String>[fileSystem.currentDirectory.path]; directories = <String>[fileSystem.currentDirectory.path];
analysisTarget = fileSystem.currentDirectory.path; analysisTarget = fileSystem.currentDirectory.path;
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import 'dart:async'; import 'dart:async';
import '../base/common.dart'; import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart'; import '../base/logger.dart';
...@@ -14,7 +13,6 @@ import 'analyze_base.dart'; ...@@ -14,7 +13,6 @@ import 'analyze_base.dart';
class AnalyzeOnce extends AnalyzeBase { class AnalyzeOnce extends AnalyzeBase {
AnalyzeOnce( AnalyzeOnce(
super.argResults, super.argResults,
List<String> repoRoots,
List<Directory> repoPackages, { List<Directory> repoPackages, {
required super.fileSystem, required super.fileSystem,
required super.logger, required super.logger,
...@@ -25,7 +23,6 @@ class AnalyzeOnce extends AnalyzeBase { ...@@ -25,7 +23,6 @@ class AnalyzeOnce extends AnalyzeBase {
required super.suppressAnalytics, required super.suppressAnalytics,
this.workingDirectory, this.workingDirectory,
}) : super( }) : super(
repoRoots: repoRoots,
repoPackages: repoPackages, repoPackages: repoPackages,
); );
...@@ -42,7 +39,7 @@ class AnalyzeOnce extends AnalyzeBase { ...@@ -42,7 +39,7 @@ class AnalyzeOnce extends AnalyzeBase {
// check for conflicting dependencies // check for conflicting dependencies
final PackageDependencyTracker dependencies = PackageDependencyTracker(); final PackageDependencyTracker dependencies = PackageDependencyTracker();
dependencies.checkForConflictingDependencies(repoPackages, dependencies); dependencies.checkForConflictingDependencies(repoPackages, dependencies);
items.addAll(repoRoots); items.add(flutterRoot);
if (argResults.wasParsed('current-package') && (argResults['current-package'] as bool)) { if (argResults.wasParsed('current-package') && (argResults['current-package'] as bool)) {
items.add(currentDirectory); items.add(currentDirectory);
} }
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
...@@ -118,6 +121,40 @@ void main() { ...@@ -118,6 +121,40 @@ void main() {
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => processManager, 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', () { testWithoutContext('analyze inRepo', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment