add a --use-cfe option to flutter analyze (#20742)
* add a --use-cfe option to flutter analyze * useCFE ==> useCfe
This commit is contained in:
@@ -34,6 +34,10 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
valueHelp: 'path-to-sdk',
|
||||
help: 'The path to the Dart SDK.',
|
||||
hide: !verboseHelp);
|
||||
argParser.addFlag('use-cfe',
|
||||
help: 'Run the analysis server with the --use-cfe option. This is a '
|
||||
'temporary flag for use while the analyzer migrates to the CFE.',
|
||||
hide: !verboseHelp);
|
||||
|
||||
// Hidden option to enable a benchmarking mode.
|
||||
argParser.addFlag('benchmark',
|
||||
|
||||
@@ -73,7 +73,11 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
|
||||
final String sdkPath = argResults['dart-sdk'] ?? sdk.dartSdkPath;
|
||||
|
||||
final AnalysisServer server = new AnalysisServer(sdkPath, directories.toList());
|
||||
final AnalysisServer server = new AnalysisServer(
|
||||
sdkPath,
|
||||
directories.toList(),
|
||||
useCfe: argResults.wasParsed('use-cfe') ? argResults['use-cfe'] : null,
|
||||
);
|
||||
|
||||
StreamSubscription<bool> subscription;
|
||||
subscription = server.onAnalyzing.listen((bool isAnalyzing) {
|
||||
|
||||
@@ -14,10 +14,11 @@ import '../base/utils.dart';
|
||||
import '../globals.dart';
|
||||
|
||||
class AnalysisServer {
|
||||
AnalysisServer(this.sdkPath, this.directories);
|
||||
AnalysisServer(this.sdkPath, this.directories, { this.useCfe });
|
||||
|
||||
final String sdkPath;
|
||||
final List<String> directories;
|
||||
final bool useCfe;
|
||||
|
||||
Process _process;
|
||||
final StreamController<bool> _analyzingController =
|
||||
@@ -37,6 +38,10 @@ class AnalysisServer {
|
||||
sdkPath,
|
||||
];
|
||||
|
||||
if (useCfe != null) {
|
||||
command.add(useCfe ? '--use-cfe' : '--no-use-cfe');
|
||||
}
|
||||
|
||||
printTrace('dart ${command.skip(1).join(' ')}');
|
||||
_process = await processManager.start(command);
|
||||
// This callback hookup can't throw.
|
||||
|
||||
@@ -178,6 +178,23 @@ StringBuffer bar = StringBuffer('baz');
|
||||
tryToDelete(tempDir);
|
||||
}
|
||||
});
|
||||
|
||||
testUsingContext('use-cfe flag is recognized', () async {
|
||||
const String contents = '''
|
||||
StringBuffer bar = StringBuffer('baz');
|
||||
''';
|
||||
final Directory tempDir = fs.systemTempDirectory.createTempSync();
|
||||
tempDir.childFile('main.dart').writeAsStringSync(contents);
|
||||
try {
|
||||
await runCommand(
|
||||
command: new AnalyzeCommand(workingDirectory: fs.directory(tempDir)),
|
||||
arguments: <String>['analyze', '--no-use-cfe'],
|
||||
statusTextContains: <String>['No issues found!'],
|
||||
);
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user