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

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

Issue 2994763002: Switch build mode to Analysis Driver. (Closed)
Patch Set: Created 3 years, 4 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 | « no previous file | pkg/analyzer_cli/lib/src/driver.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.build_mode; 5 library analyzer_cli.src.build_mode;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 import 'package:analyzer/dart/ast/ast.dart' show CompilationUnit;
11 import 'package:analyzer/error/error.dart'; 10 import 'package:analyzer/error/error.dart';
12 import 'package:analyzer/file_system/file_system.dart'; 11 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/src/dart/analysis/driver.dart';
13 import 'package:analyzer/src/dart/analysis/file_state.dart';
13 import 'package:analyzer/src/dart/sdk/sdk.dart'; 14 import 'package:analyzer/src/dart/sdk/sdk.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/sdk.dart'; 16 import 'package:analyzer/src/generated/sdk.dart';
16 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
17 import 'package:analyzer/src/generated/source_io.dart'; 18 import 'package:analyzer/src/generated/source_io.dart';
18 import 'package:analyzer/src/source/source_resource.dart'; 19 import 'package:analyzer/src/source/source_resource.dart';
19 import 'package:analyzer/src/summary/format.dart'; 20 import 'package:analyzer/src/summary/format.dart';
20 import 'package:analyzer/src/summary/idl.dart'; 21 import 'package:analyzer/src/summary/idl.dart';
21 import 'package:analyzer/src/summary/link.dart'; 22 import 'package:analyzer/src/summary/link.dart';
22 import 'package:analyzer/src/summary/package_bundle_reader.dart'; 23 import 'package:analyzer/src/summary/package_bundle_reader.dart';
23 import 'package:analyzer/src/summary/summarize_ast.dart'; 24 import 'package:analyzer/src/summary/summarize_ast.dart';
24 import 'package:analyzer/src/summary/summarize_elements.dart'; 25 import 'package:analyzer/src/summary/summarize_elements.dart';
25 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; 26 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
26 import 'package:analyzer/task/dart.dart';
27 import 'package:analyzer_cli/src/driver.dart'; 27 import 'package:analyzer_cli/src/driver.dart';
28 import 'package:analyzer_cli/src/error_formatter.dart'; 28 import 'package:analyzer_cli/src/error_formatter.dart';
29 import 'package:analyzer_cli/src/error_severity.dart'; 29 import 'package:analyzer_cli/src/error_severity.dart';
30 import 'package:analyzer_cli/src/options.dart'; 30 import 'package:analyzer_cli/src/options.dart';
31 import 'package:bazel_worker/bazel_worker.dart'; 31 import 'package:bazel_worker/bazel_worker.dart';
32 import 'package:front_end/src/base/performace_logger.dart';
33 import 'package:front_end/src/byte_store/byte_store.dart';
32 34
33 /** 35 /**
34 * Persistent Bazel worker. 36 * Persistent Bazel worker.
35 */ 37 */
36 class AnalyzerWorkerLoop extends AsyncWorkerLoop { 38 class AnalyzerWorkerLoop extends AsyncWorkerLoop {
37 final StringBuffer errorBuffer = new StringBuffer(); 39 final StringBuffer errorBuffer = new StringBuffer();
38 final StringBuffer outBuffer = new StringBuffer(); 40 final StringBuffer outBuffer = new StringBuffer();
39 41
40 final ResourceProvider resourceProvider; 42 final ResourceProvider resourceProvider;
41 final String dartSdkPath; 43 final String dartSdkPath;
42 44
43 AnalyzerWorkerLoop(this.resourceProvider, AsyncWorkerConnection connection, 45 AnalyzerWorkerLoop(this.resourceProvider, AsyncWorkerConnection connection,
44 {this.dartSdkPath}) 46 {this.dartSdkPath})
45 : super(connection: connection); 47 : super(connection: connection);
46 48
47 factory AnalyzerWorkerLoop.std(ResourceProvider resourceProvider, 49 factory AnalyzerWorkerLoop.std(ResourceProvider resourceProvider,
48 {io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) { 50 {io.Stdin stdinStream, io.Stdout stdoutStream, String dartSdkPath}) {
49 AsyncWorkerConnection connection = new StdAsyncWorkerConnection( 51 AsyncWorkerConnection connection = new StdAsyncWorkerConnection(
50 inputStream: stdinStream, outputStream: stdoutStream); 52 inputStream: stdinStream, outputStream: stdoutStream);
51 return new AnalyzerWorkerLoop(resourceProvider, connection, 53 return new AnalyzerWorkerLoop(resourceProvider, connection,
52 dartSdkPath: dartSdkPath); 54 dartSdkPath: dartSdkPath);
53 } 55 }
54 56
55 /** 57 /**
56 * Performs analysis with given [options]. 58 * Performs analysis with given [options].
57 */ 59 */
58 void analyze(CommandLineOptions options) { 60 Future<Null> analyze(CommandLineOptions options) async {
59 new BuildMode(resourceProvider, options, new AnalysisStats()).analyze(); 61 var buildMode =
62 new BuildMode(resourceProvider, options, new AnalysisStats());
63 await buildMode.analyze();
60 AnalysisEngine.instance.clearCaches(); 64 AnalysisEngine.instance.clearCaches();
61 } 65 }
62 66
63 /** 67 /**
64 * Perform a single loop step. 68 * Perform a single loop step.
65 */ 69 */
66 @override 70 @override
67 Future<WorkResponse> performRequest(WorkRequest request) async { 71 Future<WorkResponse> performRequest(WorkRequest request) async {
68 errorBuffer.clear(); 72 errorBuffer.clear();
69 outBuffer.clear(); 73 outBuffer.clear();
70 try { 74 try {
71 // Add in the dart-sdk argument if `dartSdkPath` is not null, otherwise it 75 // Add in the dart-sdk argument if `dartSdkPath` is not null, otherwise it
72 // will try to find the currently installed sdk. 76 // will try to find the currently installed sdk.
73 var arguments = new List<String>.from(request.arguments); 77 var arguments = new List<String>.from(request.arguments);
74 if (dartSdkPath != null && 78 if (dartSdkPath != null &&
75 !arguments.any((arg) => arg.startsWith('--dart-sdk'))) { 79 !arguments.any((arg) => arg.startsWith('--dart-sdk'))) {
76 arguments.add('--dart-sdk=$dartSdkPath'); 80 arguments.add('--dart-sdk=$dartSdkPath');
77 } 81 }
78 // Prepare options. 82 // Prepare options.
79 CommandLineOptions options = 83 CommandLineOptions options =
80 CommandLineOptions.parse(arguments, printAndFail: (String msg) { 84 CommandLineOptions.parse(arguments, printAndFail: (String msg) {
81 throw new ArgumentError(msg); 85 throw new ArgumentError(msg);
82 }); 86 });
83 // Analyze and respond. 87 // Analyze and respond.
84 analyze(options); 88 await analyze(options);
85 String msg = _getErrorOutputBuffersText(); 89 String msg = _getErrorOutputBuffersText();
86 return new WorkResponse() 90 return new WorkResponse()
87 ..exitCode = EXIT_CODE_OK 91 ..exitCode = EXIT_CODE_OK
88 ..output = msg; 92 ..output = msg;
89 } catch (e, st) { 93 } catch (e, st) {
90 String msg = _getErrorOutputBuffersText(); 94 String msg = _getErrorOutputBuffersText();
91 msg += '$e\n$st'; 95 msg += '$e\n$st';
92 return new WorkResponse() 96 return new WorkResponse()
93 ..exitCode = EXIT_CODE_ERROR 97 ..exitCode = EXIT_CODE_ERROR
94 ..output = msg; 98 ..output = msg;
(...skipping 27 matching lines...) Expand all
122 126
123 /** 127 /**
124 * Analyzer used when the "--build-mode" option is supplied. 128 * Analyzer used when the "--build-mode" option is supplied.
125 */ 129 */
126 class BuildMode { 130 class BuildMode {
127 final ResourceProvider resourceProvider; 131 final ResourceProvider resourceProvider;
128 final CommandLineOptions options; 132 final CommandLineOptions options;
129 final AnalysisStats stats; 133 final AnalysisStats stats;
130 134
131 SummaryDataStore summaryDataStore; 135 SummaryDataStore summaryDataStore;
132 InternalAnalysisContext context; 136 AnalysisOptions analysisOptions;
137 AnalysisDriver analysisDriver;
133 Map<Uri, File> uriToFileMap; 138 Map<Uri, File> uriToFileMap;
134 final List<Source> explicitSources = <Source>[]; 139 final List<Source> explicitSources = <Source>[];
135 final List<PackageBundle> unlinkedBundles = <PackageBundle>[]; 140 final List<PackageBundle> unlinkedBundles = <PackageBundle>[];
136 141
137 PackageBundleAssembler assembler; 142 PackageBundleAssembler assembler;
138 final Set<Source> processedSources = new Set<Source>(); 143 final Set<Source> processedSources = new Set<Source>();
139 final Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{}; 144 final Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{};
140 145
141 BuildMode(this.resourceProvider, this.options, this.stats); 146 BuildMode(this.resourceProvider, this.options, this.stats);
142 147
143 bool get _shouldOutputSummary => 148 bool get _shouldOutputSummary =>
144 options.buildSummaryOutput != null || 149 options.buildSummaryOutput != null ||
145 options.buildSummaryOutputSemantic != null; 150 options.buildSummaryOutputSemantic != null;
146 151
147 /** 152 /**
148 * Perform package analysis according to the given [options]. 153 * Perform package analysis according to the given [options].
149 */ 154 */
150 ErrorSeverity analyze() { 155 Future<ErrorSeverity> analyze() async {
151 // Write initial progress message. 156 // Write initial progress message.
152 if (!options.machineFormat) { 157 if (!options.machineFormat) {
153 outSink.writeln("Analyzing ${options.sourceFiles.join(', ')}..."); 158 outSink.writeln("Analyzing ${options.sourceFiles.join(', ')}...");
154 } 159 }
155 160
156 // Create the URI to file map. 161 // Create the URI to file map.
157 uriToFileMap = _createUriToFileMap(options.sourceFiles); 162 uriToFileMap = _createUriToFileMap(options.sourceFiles);
158 if (uriToFileMap == null) { 163 if (uriToFileMap == null) {
159 io.exitCode = ErrorSeverity.ERROR.ordinal; 164 io.exitCode = ErrorSeverity.ERROR.ordinal;
160 return ErrorSeverity.ERROR; 165 return ErrorSeverity.ERROR;
161 } 166 }
162 167
163 // BuildMode expects sourceFiles in the format "<uri>|<filepath>", 168 // BuildMode expects sourceFiles in the format "<uri>|<filepath>",
164 // but the rest of the code base does not understand this format. 169 // but the rest of the code base does not understand this format.
165 // Rewrite sourceFiles, stripping the "<uri>|" prefix, so that it 170 // Rewrite sourceFiles, stripping the "<uri>|" prefix, so that it
166 // does not cause problems with code that does not expect this format. 171 // does not cause problems with code that does not expect this format.
167 options.rewriteSourceFiles(options.sourceFiles 172 options.rewriteSourceFiles(options.sourceFiles
168 .map((String uriPipePath) => 173 .map((String uriPipePath) =>
169 uriPipePath.substring(uriPipePath.indexOf('|') + 1)) 174 uriPipePath.substring(uriPipePath.indexOf('|') + 1))
170 .toList()); 175 .toList());
171 176
172 // Prepare the analysis context. 177 // Prepare the analysis driver.
173 try { 178 try {
174 _createContext(); 179 _createAnalysisDriver();
175 } on ConflictingSummaryException catch (e) { 180 } on ConflictingSummaryException catch (e) {
176 errorSink.writeln('$e'); 181 errorSink.writeln('$e');
177 io.exitCode = ErrorSeverity.ERROR.ordinal; 182 io.exitCode = ErrorSeverity.ERROR.ordinal;
178 return ErrorSeverity.ERROR; 183 return ErrorSeverity.ERROR;
179 } 184 }
180 185
181 // Add sources. 186 // Add sources.
182 ChangeSet changeSet = new ChangeSet();
183 for (Uri uri in uriToFileMap.keys) { 187 for (Uri uri in uriToFileMap.keys) {
184 File file = uriToFileMap[uri]; 188 File file = uriToFileMap[uri];
185 if (!file.exists) { 189 if (!file.exists) {
186 errorSink.writeln('File not found: ${file.path}'); 190 errorSink.writeln('File not found: ${file.path}');
187 io.exitCode = ErrorSeverity.ERROR.ordinal; 191 io.exitCode = ErrorSeverity.ERROR.ordinal;
188 return ErrorSeverity.ERROR; 192 return ErrorSeverity.ERROR;
189 } 193 }
190 Source source = new FileSource(file, uri); 194 Source source = new FileSource(file, uri);
191 explicitSources.add(source); 195 explicitSources.add(source);
192 changeSet.addedSource(source);
193 }
194 context.applyChanges(changeSet);
195
196 if (!options.buildSummaryOnly) {
197 // Perform full analysis.
198 while (true) {
199 AnalysisResult analysisResult = context.performAnalysisTask();
200 if (!analysisResult.hasMoreWork) {
201 break;
202 }
203 }
204 } 196 }
205 197
206 // Write summary. 198 // Write summary.
207 assembler = new PackageBundleAssembler(); 199 assembler = new PackageBundleAssembler();
208 if (_shouldOutputSummary) { 200 if (_shouldOutputSummary) {
209 // Prepare all unlinked units. 201 // Prepare all unlinked units.
210 for (var src in explicitSources) { 202 for (var src in explicitSources) {
211 _prepareUnlinkedUnit('${src.uri}'); 203 await _prepareUnlinkedUnit('${src.uri}');
212 } 204 }
213 205
214 // Build and assemble linked libraries. 206 // Build and assemble linked libraries.
215 if (!options.buildSummaryOnlyUnlinked) { 207 if (!options.buildSummaryOnlyUnlinked) {
216 // Prepare URIs of unlinked units that should be linked. 208 // Prepare URIs of unlinked units that should be linked.
217 var unlinkedUris = new Set<String>(); 209 var unlinkedUris = new Set<String>();
218 for (var bundle in unlinkedBundles) { 210 for (var bundle in unlinkedBundles) {
219 unlinkedUris.addAll(bundle.unlinkedUnitUris); 211 unlinkedUris.addAll(bundle.unlinkedUnitUris);
220 } 212 }
221 for (var src in explicitSources) { 213 for (var src in explicitSources) {
(...skipping 14 matching lines...) Expand all
236 bundle.flushInformative(); 228 bundle.flushInformative();
237 io.File file = new io.File(options.buildSummaryOutputSemantic); 229 io.File file = new io.File(options.buildSummaryOutputSemantic);
238 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY); 230 file.writeAsBytesSync(bundle.toBuffer(), mode: io.FileMode.WRITE_ONLY);
239 } 231 }
240 } 232 }
241 233
242 if (options.buildSummaryOnly) { 234 if (options.buildSummaryOnly) {
243 return ErrorSeverity.NONE; 235 return ErrorSeverity.NONE;
244 } else { 236 } else {
245 // Process errors. 237 // Process errors.
246 _printErrors(outputPath: options.buildAnalysisOutput); 238 await _printErrors(outputPath: options.buildAnalysisOutput);
247 return _computeMaxSeverity(); 239 return await _computeMaxSeverity();
248 } 240 }
249 } 241 }
250 242
251 /** 243 /**
252 * Compute linked libraries for the given [libraryUris] using the linked 244 * Compute linked libraries for the given [libraryUris] using the linked
253 * libraries of the [summaryDataStore] and unlinked units in [uriToUnit], and 245 * libraries of the [summaryDataStore] and unlinked units in [uriToUnit], and
254 * add them to the [assembler]. 246 * add them to the [assembler].
255 */ 247 */
256 void _computeLinkedLibraries(Set<String> libraryUris) { 248 void _computeLinkedLibraries(Set<String> libraryUris) {
257 LinkedLibrary getDependency(String absoluteUri) => 249 LinkedLibrary getDependency(String absoluteUri) =>
258 summaryDataStore.linkedMap[absoluteUri]; 250 summaryDataStore.linkedMap[absoluteUri];
259 251
260 UnlinkedUnit getUnit(String absoluteUri) => 252 UnlinkedUnit getUnit(String absoluteUri) =>
261 summaryDataStore.unlinkedMap[absoluteUri] ?? uriToUnit[absoluteUri]; 253 summaryDataStore.unlinkedMap[absoluteUri] ?? uriToUnit[absoluteUri];
262 254
263 Map<String, LinkedLibraryBuilder> linkResult = link( 255 Map<String, LinkedLibraryBuilder> linkResult = link(
264 libraryUris, 256 libraryUris,
265 getDependency, 257 getDependency,
266 getUnit, 258 getUnit,
267 context.declaredVariables.get, 259 analysisDriver.declaredVariables.get,
268 options.strongMode); 260 options.strongMode);
269 linkResult.forEach(assembler.addLinkedLibrary); 261 linkResult.forEach(assembler.addLinkedLibrary);
270 } 262 }
271 263
272 ErrorSeverity _computeMaxSeverity() { 264 Future<ErrorSeverity> _computeMaxSeverity() async {
273 ErrorSeverity maxSeverity = ErrorSeverity.NONE; 265 ErrorSeverity maxSeverity = ErrorSeverity.NONE;
274 if (!options.buildSuppressExitCode) { 266 if (!options.buildSuppressExitCode) {
275 for (Source source in explicitSources) { 267 for (Source source in explicitSources) {
276 AnalysisErrorInfo errorInfo = context.getErrors(source); 268 ErrorsResult result = await analysisDriver.getErrors(source.fullName);
277 for (AnalysisError error in errorInfo.errors) { 269 for (AnalysisError error in result.errors) {
278 ErrorSeverity processedSeverity = determineProcessedSeverity( 270 ErrorSeverity processedSeverity = determineProcessedSeverity(
279 error, options, context.analysisOptions); 271 error, options, analysisDriver.analysisOptions);
280 if (processedSeverity != null) { 272 if (processedSeverity != null) {
281 maxSeverity = maxSeverity.max(processedSeverity); 273 maxSeverity = maxSeverity.max(processedSeverity);
282 } 274 }
283 } 275 }
284 } 276 }
285 } 277 }
286 return maxSeverity; 278 return maxSeverity;
287 } 279 }
288 280
289 void _createContext() { 281 void _createAnalysisDriver() {
290 // Read the summaries. 282 // Read the summaries.
291 summaryDataStore = new SummaryDataStore(<String>[], 283 summaryDataStore = new SummaryDataStore(<String>[],
292 recordDependencyInfo: _shouldOutputSummary); 284 recordDependencyInfo: _shouldOutputSummary);
293 285
294 // Adds a bundle at `path` to `summaryDataStore`. 286 // Adds a bundle at `path` to `summaryDataStore`.
295 PackageBundle addBundle(String path) { 287 PackageBundle addBundle(String path) {
296 var bundle = 288 var bundle =
297 new PackageBundle.fromBuffer(new io.File(path).readAsBytesSync()); 289 new PackageBundle.fromBuffer(new io.File(path).readAsBytesSync());
298 summaryDataStore.addBundle(path, bundle); 290 summaryDataStore.addBundle(path, bundle);
299 return bundle; 291 return bundle;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 Driver.createAnalysisOptionsForCommandLineOptions( 327 Driver.createAnalysisOptionsForCommandLineOptions(
336 resourceProvider, options); 328 resourceProvider, options);
337 dartSdk.useSummary = !options.buildSummaryOnly; 329 dartSdk.useSummary = !options.buildSummaryOnly;
338 sdk = dartSdk; 330 sdk = dartSdk;
339 sdkBundle = dartSdk.getSummarySdkBundle(options.strongMode); 331 sdkBundle = dartSdk.getSummarySdkBundle(options.strongMode);
340 } 332 }
341 333
342 // Include SDK bundle to avoid parsing SDK sources. 334 // Include SDK bundle to avoid parsing SDK sources.
343 summaryDataStore.addBundle(null, sdkBundle); 335 summaryDataStore.addBundle(null, sdkBundle);
344 336
345 // Create the context. 337 var sourceFactory = new SourceFactory(<UriResolver>[
346 context = AnalysisEngine.instance.createAnalysisContext();
347 context.sourceFactory = new SourceFactory(<UriResolver>[
348 new DartUriResolver(sdk), 338 new DartUriResolver(sdk),
349 new InSummaryUriResolver(resourceProvider, summaryDataStore), 339 new InSummaryUriResolver(resourceProvider, summaryDataStore),
350 new ExplicitSourceResolver(uriToFileMap) 340 new ExplicitSourceResolver(uriToFileMap)
351 ]); 341 ]);
352 342
353 // Set context options. 343 analysisOptions = Driver.createAnalysisOptionsForCommandLineOptions(
354 Driver.declareVariables(context.declaredVariables, options); 344 resourceProvider, options);
355 AnalysisOptionsImpl analysisOptions = Driver
356 .createAnalysisOptionsForCommandLineOptions(resourceProvider, options);
357 context.analysisOptions = analysisOptions;
358 345
359 if (!options.buildSummaryOnly) { 346 PerformanceLog logger = new PerformanceLog(null);
360 // Configure using summaries. 347 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(logger);
361 context.typeProvider = sdk.context.typeProvider; 348 analysisDriver = new AnalysisDriver(
362 context.resultProvider = 349 scheduler,
363 new InputPackagesResultProvider(context, summaryDataStore); 350 logger,
364 } 351 resourceProvider,
352 new MemoryByteStore(),
353 new FileContentOverlay(),
354 null,
355 sourceFactory,
356 analysisOptions,
357 externalSummaries: summaryDataStore);
358 Driver.declareVariables(analysisDriver.declaredVariables, options);
359
360 scheduler.start();
365 } 361 }
366 362
367 /** 363 /**
368 * Convert [sourceEntities] (a list of file specifications of the form 364 * Convert [sourceEntities] (a list of file specifications of the form
369 * "$uri|$path") to a map from URI to path. If an error occurs, report the 365 * "$uri|$path") to a map from URI to path. If an error occurs, report the
370 * error and return null. 366 * error and return null.
371 */ 367 */
372 Map<Uri, File> _createUriToFileMap(List<String> sourceEntities) { 368 Map<Uri, File> _createUriToFileMap(List<String> sourceEntities) {
373 Map<Uri, File> uriToFileMap = <Uri, File>{}; 369 Map<Uri, File> uriToFileMap = <Uri, File>{};
374 for (String sourceFile in sourceEntities) { 370 for (String sourceFile in sourceEntities) {
(...skipping 11 matching lines...) Expand all
386 return uriToFileMap; 382 return uriToFileMap;
387 } 383 }
388 384
389 /** 385 /**
390 * Ensure that the [UnlinkedUnit] for [absoluteUri] is available. 386 * Ensure that the [UnlinkedUnit] for [absoluteUri] is available.
391 * 387 *
392 * If the unit is in the input [summaryDataStore], do nothing. 388 * If the unit is in the input [summaryDataStore], do nothing.
393 * 389 *
394 * Otherwise compute it and store into the [uriToUnit] and [assembler]. 390 * Otherwise compute it and store into the [uriToUnit] and [assembler].
395 */ 391 */
396 void _prepareUnlinkedUnit(String absoluteUri) { 392 Future<Null> _prepareUnlinkedUnit(String absoluteUri) async {
397 // Maybe an input package contains the source. 393 // Maybe an input package contains the source.
398 if (summaryDataStore.unlinkedMap[absoluteUri] != null) { 394 if (summaryDataStore.unlinkedMap[absoluteUri] != null) {
399 return; 395 return;
400 } 396 }
401 // Parse the source and serialize its AST. 397 // Parse the source and serialize its AST.
402 Uri uri = Uri.parse(absoluteUri); 398 Uri uri = Uri.parse(absoluteUri);
403 Source source = context.sourceFactory.forUri2(uri); 399 Source source = analysisDriver.sourceFactory.forUri2(uri);
404 if (!source.exists()) { 400 if (!source.exists()) {
405 // TODO(paulberry): we should report a warning/error because DDC 401 // TODO(paulberry): we should report a warning/error because DDC
406 // compilations are unlikely to work. 402 // compilations are unlikely to work.
407 return; 403 return;
408 } 404 }
409 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); 405 var result = await analysisDriver.parseFile(source.fullName);
410 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); 406 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(result.unit);
411 uriToUnit[absoluteUri] = unlinkedUnit; 407 uriToUnit[absoluteUri] = unlinkedUnit;
412 assembler.addUnlinkedUnit(source, unlinkedUnit); 408 assembler.addUnlinkedUnit(source, unlinkedUnit);
413 } 409 }
414 410
415 /** 411 /**
416 * Print errors for all explicit sources. If [outputPath] is supplied, output 412 * Print errors for all explicit sources. If [outputPath] is supplied, output
417 * is sent to a new file at that path. 413 * is sent to a new file at that path.
418 */ 414 */
419 void _printErrors({String outputPath}) { 415 Future<Null> _printErrors({String outputPath}) async {
420 StringBuffer buffer = new StringBuffer(); 416 StringBuffer buffer = new StringBuffer();
421 var severityProcessor = (AnalysisError error) => 417 var severityProcessor = (AnalysisError error) =>
422 determineProcessedSeverity(error, options, context.analysisOptions); 418 determineProcessedSeverity(error, options, analysisOptions);
423 ErrorFormatter formatter = options.machineFormat 419 ErrorFormatter formatter = options.machineFormat
424 ? new MachineErrorFormatter(buffer, options, stats, 420 ? new MachineErrorFormatter(buffer, options, stats,
425 severityProcessor: severityProcessor) 421 severityProcessor: severityProcessor)
426 : new HumanErrorFormatter(buffer, options, stats, 422 : new HumanErrorFormatter(buffer, options, stats,
427 severityProcessor: severityProcessor); 423 severityProcessor: severityProcessor);
428 for (Source source in explicitSources) { 424 for (Source source in explicitSources) {
429 AnalysisErrorInfo errorInfo = context.getErrors(source); 425 var result = await analysisDriver.getErrors(source.fullName);
426 var errorInfo = new AnalysisErrorInfoImpl(result.errors, result.lineInfo);
430 formatter.formatErrors([errorInfo]); 427 formatter.formatErrors([errorInfo]);
431 } 428 }
432 formatter.flush(); 429 formatter.flush();
433 if (!options.machineFormat) { 430 if (!options.machineFormat) {
434 stats.print(buffer); 431 stats.print(buffer);
435 } 432 }
436 if (outputPath == null) { 433 if (outputPath == null) {
437 StringSink sink = options.machineFormat ? errorSink : outSink; 434 StringSink sink = options.machineFormat ? errorSink : outSink;
438 sink.write(buffer); 435 sink.write(buffer);
439 } else { 436 } else {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 * Build the inverse mapping of [uriToSourceMap]. 475 * Build the inverse mapping of [uriToSourceMap].
479 */ 476 */
480 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) { 477 static Map<String, Uri> _computePathToUriMap(Map<Uri, File> uriToSourceMap) {
481 Map<String, Uri> pathToUriMap = <String, Uri>{}; 478 Map<String, Uri> pathToUriMap = <String, Uri>{};
482 uriToSourceMap.forEach((Uri uri, File file) { 479 uriToSourceMap.forEach((Uri uri, File file) {
483 pathToUriMap[file.path] = uri; 480 pathToUriMap[file.path] = uri;
484 }); 481 });
485 return pathToUriMap; 482 return pathToUriMap;
486 } 483 }
487 } 484 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/driver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698