Train the dartanalyzer tool on generating summaries.
Change-Id: Ic887eb2135161b5795a2456d38677f016bbe3643 Reviewed-on: https://dart-review.googlesource.com/75561 Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Devon Carew <devoncarew@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
80c1b88626
commit
7df4900a94
@@ -4,7 +4,7 @@ import 'package:analyzer/file_system/physical_file_system.dart';
|
||||
import 'package:analyzer/src/dart/sdk/sdk.dart';
|
||||
import 'package:analyzer/src/summary/summary_file_builder.dart';
|
||||
|
||||
main(List<String> args) {
|
||||
void main(List<String> args) {
|
||||
String command;
|
||||
String outFilePath;
|
||||
String sdkPath;
|
||||
|
||||
@@ -28,6 +28,7 @@ import 'package:analyzer/src/source/path_filter.dart';
|
||||
import 'package:analyzer/src/source/sdk_ext.dart';
|
||||
import 'package:analyzer/src/summary/idl.dart';
|
||||
import 'package:analyzer/src/summary/package_bundle_reader.dart';
|
||||
import 'package:analyzer/src/summary/summary_file_builder.dart';
|
||||
import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
|
||||
import 'package:analyzer/src/task/options.dart';
|
||||
import 'package:analyzer/src/util/yaml.dart';
|
||||
@@ -210,6 +211,22 @@ class Driver extends Object with HasContextMixin implements CommandLineStarter {
|
||||
}
|
||||
}
|
||||
|
||||
// When training a snapshot, in addition to training regular analysis
|
||||
// (above), we train build mode as well.
|
||||
if (options.trainSnapshot) {
|
||||
// TODO(devoncarew): Iterate on this training to make it more
|
||||
// representative of what we see internally; call into _buildModeAnalyze()
|
||||
// with some appropriate options.
|
||||
print('\nGenerating strong mode summary...');
|
||||
final Stopwatch stopwatch = new Stopwatch()..start();
|
||||
|
||||
new SummaryBuilder.forSdk(options.dartSdkPath).build();
|
||||
new SummaryBuilder.forSdk(options.dartSdkPath).build();
|
||||
new SummaryBuilder.forSdk(options.dartSdkPath).build();
|
||||
|
||||
print('Done in ${stopwatch.elapsedMilliseconds} ms.');
|
||||
}
|
||||
|
||||
if (analysisDriver != null) {
|
||||
_analyzedFileCount += analysisDriver.knownFiles.length;
|
||||
}
|
||||
|
||||
@@ -157,6 +157,10 @@ class CommandLineOptions {
|
||||
/// Use ANSI color codes for output.
|
||||
final bool color;
|
||||
|
||||
/// Whether we should analyze the given source for the purposes of training a
|
||||
/// Dart analyzer snapshot.
|
||||
final bool trainSnapshot;
|
||||
|
||||
/// Initialize options from the given parsed [args].
|
||||
CommandLineOptions._fromArgs(ArgResults args)
|
||||
: buildAnalysisOutput = cast(args['build-analysis-output']),
|
||||
@@ -199,6 +203,7 @@ class CommandLineOptions {
|
||||
lintsAreFatal = cast(args['fatal-lints']),
|
||||
implicitCasts = cast(args[implicitCastsFlag]),
|
||||
implicitDynamic = !cast<bool>(args['no-implicit-dynamic']),
|
||||
trainSnapshot = cast(args['train-snapshot']),
|
||||
verbose = cast(args['verbose']),
|
||||
color = cast(args['color']);
|
||||
|
||||
@@ -510,7 +515,12 @@ class CommandLineOptions {
|
||||
help: 'Enable the Dart 2.0 preview.',
|
||||
defaultsTo: true,
|
||||
hide: hide,
|
||||
negatable: true);
|
||||
negatable: true)
|
||||
..addFlag('train-snapshot',
|
||||
help: "Analyze the given source for the purposes of training a "
|
||||
"dartanalyzer snapshot.",
|
||||
hide: hide,
|
||||
negatable: false);
|
||||
|
||||
try {
|
||||
if (args.contains('--$ignoreUnrecognizedFlagsFlag')) {
|
||||
|
||||
@@ -74,6 +74,7 @@ main() {
|
||||
expect(options.strongMode, isTrue);
|
||||
expect(options.lintsAreFatal, isFalse);
|
||||
expect(options.previewDart2, isTrue);
|
||||
expect(options.trainSnapshot, isFalse);
|
||||
});
|
||||
|
||||
test('batch', () {
|
||||
@@ -242,6 +243,12 @@ main() {
|
||||
CommandLineOptions.parse(['--preview-dart-2', 'foo.dart']);
|
||||
expect(options.previewDart2, isTrue);
|
||||
});
|
||||
|
||||
test('--train-snapshot', () {
|
||||
CommandLineOptions options =
|
||||
CommandLineOptions.parse(['--train-snapshot', 'foo.dart']);
|
||||
expect(options.trainSnapshot, isTrue);
|
||||
});
|
||||
});
|
||||
});
|
||||
defineReflectiveTests(CommandLineOptionsTest);
|
||||
|
||||
@@ -7,7 +7,7 @@ import("../application_snapshot.gni")
|
||||
application_snapshot("analysis_server") {
|
||||
main_dart = "../../pkg/analysis_server/bin/server.dart"
|
||||
training_args = [
|
||||
"--train-using=" + rebase_path("../../pkg/analyzer_cli"),
|
||||
"--sdk=" + rebase_path("../../sdk/")
|
||||
"--sdk=" + rebase_path("../../sdk/"),
|
||||
"--train-using=" + rebase_path("../../pkg/analyzer_cli")
|
||||
]
|
||||
}
|
||||
|
||||
@@ -22,8 +22,9 @@ analyzer_files = exec_script("../../tools/list_dart_files.py",
|
||||
application_snapshot("generate_dartanalyzer_snapshot") {
|
||||
main_dart = "../../pkg/analyzer_cli/bin/analyzer.dart"
|
||||
training_args = [
|
||||
"--dart-sdk=" + rebase_path("../../sdk"),
|
||||
rebase_path("../../tests/language/first_test.dart"),
|
||||
"--dart-sdk=" + rebase_path("../../sdk/"),
|
||||
"--train-snapshot",
|
||||
rebase_path("../../pkg/analyzer_cli")
|
||||
]
|
||||
name = "dartanalyzer"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user