Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: pkg/analyzer_cli/lib/src/driver.dart

Issue 2657903006: Implement using AnalysisDriver in analyzer_cli. Disabled. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer_cli/lib/src/analyzer_impl.dart ('k') | pkg/analyzer_cli/lib/src/options.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer_cli.src.driver; 5 library analyzer_cli.src.driver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io' as io; 9 import 'dart:io' as io;
10 10
11 import 'package:analyzer/error/error.dart'; 11 import 'package:analyzer/error/error.dart';
12 import 'package:analyzer/file_system/file_system.dart' as file_system; 12 import 'package:analyzer/file_system/file_system.dart' as file_system;
13 import 'package:analyzer/file_system/file_system.dart'; 13 import 'package:analyzer/file_system/file_system.dart';
14 import 'package:analyzer/file_system/physical_file_system.dart'; 14 import 'package:analyzer/file_system/physical_file_system.dart';
15 import 'package:analyzer/plugin/resolver_provider.dart'; 15 import 'package:analyzer/plugin/resolver_provider.dart';
16 import 'package:analyzer/source/analysis_options_provider.dart'; 16 import 'package:analyzer/source/analysis_options_provider.dart';
17 import 'package:analyzer/source/package_map_provider.dart'; 17 import 'package:analyzer/source/package_map_provider.dart';
18 import 'package:analyzer/source/package_map_resolver.dart'; 18 import 'package:analyzer/source/package_map_resolver.dart';
19 import 'package:analyzer/source/pub_package_map_provider.dart'; 19 import 'package:analyzer/source/pub_package_map_provider.dart';
20 import 'package:analyzer/source/sdk_ext.dart'; 20 import 'package:analyzer/source/sdk_ext.dart';
21 import 'package:analyzer/src/context/builder.dart'; 21 import 'package:analyzer/src/context/builder.dart';
22 import 'package:analyzer/src/dart/analysis/byte_store.dart';
23 import 'package:analyzer/src/dart/analysis/driver.dart';
24 import 'package:analyzer/src/dart/analysis/file_state.dart';
22 import 'package:analyzer/src/dart/sdk/sdk.dart'; 25 import 'package:analyzer/src/dart/sdk/sdk.dart';
23 import 'package:analyzer/src/generated/constant.dart'; 26 import 'package:analyzer/src/generated/constant.dart';
24 import 'package:analyzer/src/generated/engine.dart'; 27 import 'package:analyzer/src/generated/engine.dart';
25 import 'package:analyzer/src/generated/interner.dart'; 28 import 'package:analyzer/src/generated/interner.dart';
26 import 'package:analyzer/src/generated/java_engine.dart'; 29 import 'package:analyzer/src/generated/java_engine.dart';
27 import 'package:analyzer/src/generated/sdk.dart'; 30 import 'package:analyzer/src/generated/sdk.dart';
28 import 'package:analyzer/src/generated/source.dart'; 31 import 'package:analyzer/src/generated/source.dart';
29 import 'package:analyzer/src/generated/source_io.dart'; 32 import 'package:analyzer/src/generated/source_io.dart';
30 import 'package:analyzer/src/generated/utilities_general.dart' 33 import 'package:analyzer/src/generated/utilities_general.dart'
31 show PerformanceTag; 34 show PerformanceTag;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 var linterNode = options['linter']; 70 var linterNode = options['linter'];
68 return linterNode is YamlMap && linterNode.containsKey('rules'); 71 return linterNode is YamlMap && linterNode.containsKey('rules');
69 } 72 }
70 73
71 typedef Future<ErrorSeverity> _BatchRunnerHandler(List<String> args); 74 typedef Future<ErrorSeverity> _BatchRunnerHandler(List<String> args);
72 75
73 class Driver implements CommandLineStarter { 76 class Driver implements CommandLineStarter {
74 static final PerformanceTag _analyzeAllTag = 77 static final PerformanceTag _analyzeAllTag =
75 new PerformanceTag("Driver._analyzeAll"); 78 new PerformanceTag("Driver._analyzeAll");
76 79
80 static ByteStore analysisDriverByteStore = new MemoryByteStore();
81
77 /// The plugins that are defined outside the `analyzer_cli` package. 82 /// The plugins that are defined outside the `analyzer_cli` package.
78 List<Plugin> _userDefinedPlugins = <Plugin>[]; 83 List<Plugin> _userDefinedPlugins = <Plugin>[];
79 84
80 /// The context that was most recently created by a call to [_analyzeAll], or 85 /// The context that was most recently created by a call to [_analyzeAll], or
81 /// `null` if [_analyzeAll] hasn't been called yet. 86 /// `null` if [_analyzeAll] hasn't been called yet.
82 InternalAnalysisContext _context; 87 InternalAnalysisContext _context;
83 88
89 AnalysisDriver analysisDriver;
90
84 /// The total number of source files loaded by an AnalysisContext. 91 /// The total number of source files loaded by an AnalysisContext.
85 int _analyzedFileCount = 0; 92 int _analyzedFileCount = 0;
86 93
87 /// If [_context] is not `null`, the [CommandLineOptions] that guided its 94 /// If [_context] is not `null`, the [CommandLineOptions] that guided its
88 /// creation. 95 /// creation.
89 CommandLineOptions _previousOptions; 96 CommandLineOptions _previousOptions;
90 97
91 @override 98 @override
92 ResolverProvider packageResolverProvider; 99 ResolverProvider packageResolverProvider;
93 100
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 CommandLineOptions options = CommandLineOptions.parse(args); 135 CommandLineOptions options = CommandLineOptions.parse(args);
129 136
130 // Do analysis. 137 // Do analysis.
131 if (options.buildMode) { 138 if (options.buildMode) {
132 ErrorSeverity severity = _buildModeAnalyze(options); 139 ErrorSeverity severity = _buildModeAnalyze(options);
133 // In case of error propagate exit code. 140 // In case of error propagate exit code.
134 if (severity == ErrorSeverity.ERROR) { 141 if (severity == ErrorSeverity.ERROR) {
135 io.exitCode = severity.ordinal; 142 io.exitCode = severity.ordinal;
136 } 143 }
137 } else if (options.shouldBatch) { 144 } else if (options.shouldBatch) {
138 _BatchRunner.runAsBatch(args, (List<String> args) { 145 _BatchRunner.runAsBatch(args, (List<String> args) async {
139 CommandLineOptions options = CommandLineOptions.parse(args); 146 CommandLineOptions options = CommandLineOptions.parse(args);
140 return _analyzeAll(options); 147 return await _analyzeAll(options);
141 }); 148 });
142 } else { 149 } else {
143 ErrorSeverity severity = await _analyzeAll(options); 150 ErrorSeverity severity = await _analyzeAll(options);
144 // In case of error propagate exit code. 151 // In case of error propagate exit code.
145 if (severity == ErrorSeverity.ERROR) { 152 if (severity == ErrorSeverity.ERROR) {
146 io.exitCode = severity.ordinal; 153 io.exitCode = severity.ordinal;
147 } 154 }
148 } 155 }
149 156
150 if (_context != null) { 157 if (_context != null) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return ErrorSeverity.ERROR; 208 return ErrorSeverity.ERROR;
202 } 209 }
203 210
204 for (io.File file in files) { 211 for (io.File file in files) {
205 Source source = _computeLibrarySource(file.absolute.path); 212 Source source = _computeLibrarySource(file.absolute.path);
206 if (!knownSources.contains(source)) { 213 if (!knownSources.contains(source)) {
207 changeSet.addedSource(source); 214 changeSet.addedSource(source);
208 } 215 }
209 sourcesToAnalyze.add(source); 216 sourcesToAnalyze.add(source);
210 } 217 }
218
219 if (analysisDriver != null) {
220 files.forEach((file) {
221 analysisDriver.addFile(file.path);
222 });
223 } else {
224 context.applyChanges(changeSet);
225 }
211 } 226 }
212 context.applyChanges(changeSet);
213 227
214 // Analyze the libraries. 228 // Analyze the libraries.
215 ErrorSeverity allResult = ErrorSeverity.NONE; 229 ErrorSeverity allResult = ErrorSeverity.NONE;
216 var libUris = <Uri>[]; 230 var libUris = <Uri>[];
217 var parts = <Source>[]; 231 var parts = <Source>[];
218 for (Source source in sourcesToAnalyze) { 232 for (Source source in sourcesToAnalyze) {
219 if (context.computeKindOf(source) == SourceKind.PART) { 233 if (context.computeKindOf(source) == SourceKind.PART) {
220 parts.add(source); 234 parts.add(source);
221 continue; 235 continue;
222 } 236 }
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 AnalyzeFunctionBodiesPredicate dietParsingPolicy = 547 AnalyzeFunctionBodiesPredicate dietParsingPolicy =
534 _chooseDietParsingPolicy(options); 548 _chooseDietParsingPolicy(options);
535 setAnalysisContextOptions( 549 setAnalysisContextOptions(
536 resourceProvider, sourceFactory, _context, options, 550 resourceProvider, sourceFactory, _context, options,
537 (AnalysisOptionsImpl contextOptions) { 551 (AnalysisOptionsImpl contextOptions) {
538 contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy; 552 contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy;
539 }); 553 });
540 554
541 _context.sourceFactory = sourceFactory; 555 _context.sourceFactory = sourceFactory;
542 556
543 if (sdkBundle != null) { 557 if (options.enableNewAnalysisDriver) {
544 _context.resultProvider = 558 PerformanceLog log = new PerformanceLog(null);
545 new InputPackagesResultProvider(_context, summaryDataStore); 559 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(log);
560 analysisDriver = new AnalysisDriver(
561 scheduler,
562 log,
563 resourceProvider,
564 analysisDriverByteStore,
565 new FileContentOverlay(),
566 'test',
567 context.sourceFactory,
568 context.analysisOptions);
569 analysisDriver.results.listen((_) {});
570 analysisDriver.exceptions.listen((_) {});
571 scheduler.start();
572 } else {
573 if (sdkBundle != null) {
574 _context.resultProvider =
575 new InputPackagesResultProvider(_context, summaryDataStore);
576 }
546 } 577 }
547 } 578 }
548 579
549 /// Return discovered packagespec, or `null` if none is found. 580 /// Return discovered packagespec, or `null` if none is found.
550 Packages _discoverPackagespec(Uri root) { 581 Packages _discoverPackagespec(Uri root) {
551 try { 582 try {
552 Packages packages = pkg_discovery.findPackagesFromFile(root); 583 Packages packages = pkg_discovery.findPackagesFromFile(root);
553 if (packages != Packages.noPackages) { 584 if (packages != Packages.noPackages) {
554 return packages; 585 return packages;
555 } 586 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 ExtensionManager manager = new ExtensionManager(); 664 ExtensionManager manager = new ExtensionManager();
634 manager.processPlugins(plugins); 665 manager.processPlugins(plugins);
635 666
636 linter.registerLintRules(); 667 linter.registerLintRules();
637 } 668 }
638 669
639 /// Analyze a single source. 670 /// Analyze a single source.
640 Future<ErrorSeverity> _runAnalyzer( 671 Future<ErrorSeverity> _runAnalyzer(
641 Source source, CommandLineOptions options) async { 672 Source source, CommandLineOptions options) async {
642 int startTime = currentTimeMillis(); 673 int startTime = currentTimeMillis();
643 AnalyzerImpl analyzer = new AnalyzerImpl( 674 AnalyzerImpl analyzer = new AnalyzerImpl(_context.analysisOptions, _context,
644 _context.analysisOptions, _context, source, options, stats, startTime); 675 analysisDriver, source, options, stats, startTime);
645 ErrorSeverity errorSeverity = await analyzer.analyze(); 676 ErrorSeverity errorSeverity = await analyzer.analyze();
646 if (errorSeverity == ErrorSeverity.ERROR) { 677 if (errorSeverity == ErrorSeverity.ERROR) {
647 io.exitCode = errorSeverity.ordinal; 678 io.exitCode = errorSeverity.ordinal;
648 } 679 }
649 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { 680 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) {
650 io.exitCode = errorSeverity.ordinal; 681 io.exitCode = errorSeverity.ordinal;
651 } 682 }
652 return errorSeverity; 683 return errorSeverity;
653 } 684 }
654 685
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 for (var package in packages) { 913 for (var package in packages) {
883 var packageName = path.basename(package.path); 914 var packageName = path.basename(package.path);
884 var realPath = package.resolveSymbolicLinksSync(); 915 var realPath = package.resolveSymbolicLinksSync();
885 result[packageName] = [ 916 result[packageName] = [
886 PhysicalResourceProvider.INSTANCE.getFolder(realPath) 917 PhysicalResourceProvider.INSTANCE.getFolder(realPath)
887 ]; 918 ];
888 } 919 }
889 return result; 920 return result;
890 } 921 }
891 } 922 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/lib/src/analyzer_impl.dart ('k') | pkg/analyzer_cli/lib/src/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698