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

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

Issue 2956093002: Issue 29960. Both CommandLineOptions and AnalysisOptions must be equal to reuse the context. (Closed)
Patch Set: Created 3 years, 5 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/lib/src/generated/engine.dart ('k') | no next file » | 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io' as io; 6 import 'dart:io' as io;
7 7
8 import 'package:analyzer/error/error.dart'; 8 import 'package:analyzer/error/error.dart';
9 import 'package:analyzer/file_system/file_system.dart' as file_system; 9 import 'package:analyzer/file_system/file_system.dart' as file_system;
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 dartSdkPath: options.dartSdkPath) 306 dartSdkPath: options.dartSdkPath)
307 .run(); 307 .run();
308 } else { 308 } else {
309 return new BuildMode(resourceProvider, options, stats).analyze(); 309 return new BuildMode(resourceProvider, options, stats).analyze();
310 } 310 }
311 }); 311 });
312 } 312 }
313 313
314 /// Determine whether the context created during a previous call to 314 /// Determine whether the context created during a previous call to
315 /// [_analyzeAll] can be re-used in order to analyze using [options]. 315 /// [_analyzeAll] can be re-used in order to analyze using [options].
316 bool _canContextBeReused(CommandLineOptions options) { 316 bool _canContextBeReused(
317 CommandLineOptions options, AnalysisOptionsImpl other) {
317 // TODO(paulberry): add a command-line option that disables context re-use. 318 // TODO(paulberry): add a command-line option that disables context re-use.
318 if (_context == null) { 319 if (_context == null) {
319 return false; 320 return false;
320 } 321 }
322
323 // Check command line options.
321 if (options.packageRootPath != _previousOptions.packageRootPath) { 324 if (options.packageRootPath != _previousOptions.packageRootPath) {
322 return false; 325 return false;
323 } 326 }
324 if (options.packageConfigPath != _previousOptions.packageConfigPath) { 327 if (options.packageConfigPath != _previousOptions.packageConfigPath) {
325 return false; 328 return false;
326 } 329 }
327 if (!_equalMaps( 330 if (!_equalMaps(
328 options.definedVariables, _previousOptions.definedVariables)) { 331 options.definedVariables, _previousOptions.definedVariables)) {
329 return false; 332 return false;
330 } 333 }
(...skipping 30 matching lines...) Expand all
361 if (options.enableSuperMixins != _previousOptions.enableSuperMixins) { 364 if (options.enableSuperMixins != _previousOptions.enableSuperMixins) {
362 return false; 365 return false;
363 } 366 }
364 if (!_equalLists( 367 if (!_equalLists(
365 options.buildSummaryInputs, _previousOptions.buildSummaryInputs)) { 368 options.buildSummaryInputs, _previousOptions.buildSummaryInputs)) {
366 return false; 369 return false;
367 } 370 }
368 if (options.disableCacheFlushing != _previousOptions.disableCacheFlushing) { 371 if (options.disableCacheFlushing != _previousOptions.disableCacheFlushing) {
369 return false; 372 return false;
370 } 373 }
374
375 // Check analysis options.
376 var c = _context.analysisOptions;
377 if (!(other.enableAssertInitializer == c.enableAssertInitializer &&
378 other.enableStrictCallChecks == c.enableStrictCallChecks &&
379 other.enableLazyAssignmentOperators ==
380 c.enableLazyAssignmentOperators &&
381 other.enableSuperMixins == c.enableSuperMixins &&
382 other.enableTiming == c.enableTiming &&
383 other.generateImplicitErrors == c.generateImplicitErrors &&
384 other.generateSdkErrors == c.generateSdkErrors &&
385 other.hint == c.hint &&
386 other.lint == c.lint &&
387 AnalysisOptionsImpl.compareLints(other.lintRules, c.lintRules) &&
388 other.preserveComments == c.preserveComments &&
389 other.strongMode == c.strongMode)) {
390 return false;
391 }
392
371 return true; 393 return true;
372 } 394 }
373 395
374 /// Decide on the appropriate policy for which files need to be fully parsed 396 /// Decide on the appropriate policy for which files need to be fully parsed
375 /// and which files need to be diet parsed, based on [options], and return an 397 /// and which files need to be diet parsed, based on [options], and return an
376 /// [AnalyzeFunctionBodiesPredicate] that implements this policy. 398 /// [AnalyzeFunctionBodiesPredicate] that implements this policy.
377 AnalyzeFunctionBodiesPredicate _chooseDietParsingPolicy( 399 AnalyzeFunctionBodiesPredicate _chooseDietParsingPolicy(
378 CommandLineOptions options) { 400 CommandLineOptions options) {
379 if (options.shouldBatch) { 401 if (options.shouldBatch) {
380 // As analyzer is currently implemented, once a file has been diet 402 // As analyzer is currently implemented, once a file has been diet
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 Uri uri = _context.sourceFactory.restoreUri(source); 560 Uri uri = _context.sourceFactory.restoreUri(source);
539 if (uri == null) { 561 if (uri == null) {
540 return source; 562 return source;
541 } 563 }
542 return new FileSource(sourceFile, uri); 564 return new FileSource(sourceFile, uri);
543 } 565 }
544 566
545 /// Create an analysis context that is prepared to analyze sources according 567 /// Create an analysis context that is prepared to analyze sources according
546 /// to the given [options], and store it in [_context]. 568 /// to the given [options], and store it in [_context].
547 void _createAnalysisContext(CommandLineOptions options) { 569 void _createAnalysisContext(CommandLineOptions options) {
548 if (_canContextBeReused(options)) { 570 AnalysisOptionsImpl analysisOptions =
571 createAnalysisOptionsForCommandLineOptions(resourceProvider, options);
572 analysisOptions.analyzeFunctionBodiesPredicate =
573 _chooseDietParsingPolicy(options);
574
575 if (_canContextBeReused(options, analysisOptions)) {
549 return; 576 return;
550 } 577 }
578
551 _previousOptions = options; 579 _previousOptions = options;
552 580
553 // Save stats from previous context before clobbering it. 581 // Save stats from previous context before clobbering it.
554 if (_context != null) { 582 if (_context != null) {
555 _analyzedFileCount += _context.sources.length; 583 _analyzedFileCount += _context.sources.length;
556 } 584 }
557 585
558 // Find package info. 586 // Find package info.
559 _PackageInfo packageInfo = _findPackages(options); 587 _PackageInfo packageInfo = _findPackages(options);
560 588
561 // Process embedders. 589 // Process embedders.
562 Map<file_system.Folder, YamlMap> embedderMap = 590 Map<file_system.Folder, YamlMap> embedderMap =
563 new EmbedderYamlLocator(packageInfo.packageMap).embedderYamls; 591 new EmbedderYamlLocator(packageInfo.packageMap).embedderYamls;
564 592
565 // Scan for SDK extenders. 593 // Scan for SDK extenders.
566 bool hasSdkExt = _hasSdkExt(packageInfo.packageMap?.values); 594 bool hasSdkExt = _hasSdkExt(packageInfo.packageMap?.values);
567 595
568 // No summaries in the presence of embedders or extenders. 596 // No summaries in the presence of embedders or extenders.
569 bool useSummaries = embedderMap.isEmpty && !hasSdkExt; 597 bool useSummaries = embedderMap.isEmpty && !hasSdkExt;
570 598
571 if (!useSummaries && options.buildSummaryInputs.isNotEmpty) { 599 if (!useSummaries && options.buildSummaryInputs.isNotEmpty) {
572 throw new _DriverError( 600 throw new _DriverError(
573 'Summaries are not yet supported when using Flutter.'); 601 'Summaries are not yet supported when using Flutter.');
574 } 602 }
575 603
576 // Read any input summaries. 604 // Read any input summaries.
577 SummaryDataStore summaryDataStore = new SummaryDataStore( 605 SummaryDataStore summaryDataStore = new SummaryDataStore(
578 useSummaries ? options.buildSummaryInputs : <String>[]); 606 useSummaries ? options.buildSummaryInputs : <String>[]);
579 607
580 AnalysisOptionsImpl analysisOptions =
581 createAnalysisOptionsForCommandLineOptions(resourceProvider, options);
582 analysisOptions.analyzeFunctionBodiesPredicate =
583 _chooseDietParsingPolicy(options);
584
585 // Once options and embedders are processed, setup the SDK. 608 // Once options and embedders are processed, setup the SDK.
586 _setupSdk(options, useSummaries, analysisOptions); 609 _setupSdk(options, useSummaries, analysisOptions);
587 610
588 PackageBundle sdkBundle = sdk.getLinkedBundle(); 611 PackageBundle sdkBundle = sdk.getLinkedBundle();
589 if (sdkBundle != null) { 612 if (sdkBundle != null) {
590 summaryDataStore.addBundle(null, sdkBundle); 613 summaryDataStore.addBundle(null, sdkBundle);
591 } 614 }
592 615
593 // Choose a package resolution policy and a diet parsing policy based on 616 // Choose a package resolution policy and a diet parsing policy based on
594 // the command-line options. 617 // the command-line options.
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 for (var package in packages) { 912 for (var package in packages) {
890 var packageName = path.basename(package.path); 913 var packageName = path.basename(package.path);
891 var realPath = package.resolveSymbolicLinksSync(); 914 var realPath = package.resolveSymbolicLinksSync();
892 result[packageName] = [ 915 result[packageName] = [
893 PhysicalResourceProvider.INSTANCE.getFolder(realPath) 916 PhysicalResourceProvider.INSTANCE.getFolder(realPath)
894 ]; 917 ];
895 } 918 }
896 return result; 919 return result;
897 } 920 }
898 } 921 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698