OLD | NEW |
---|---|
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 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 import 'package:analyzer/src/generated/error.dart'; | 25 import 'package:analyzer/src/generated/error.dart'; |
26 import 'package:analyzer/src/generated/interner.dart'; | 26 import 'package:analyzer/src/generated/interner.dart'; |
27 import 'package:analyzer/src/generated/java_engine.dart'; | 27 import 'package:analyzer/src/generated/java_engine.dart'; |
28 import 'package:analyzer/src/generated/sdk.dart'; | 28 import 'package:analyzer/src/generated/sdk.dart'; |
29 import 'package:analyzer/src/generated/source.dart'; | 29 import 'package:analyzer/src/generated/source.dart'; |
30 import 'package:analyzer/src/generated/source_io.dart'; | 30 import 'package:analyzer/src/generated/source_io.dart'; |
31 import 'package:analyzer/src/generated/utilities_general.dart' | 31 import 'package:analyzer/src/generated/utilities_general.dart' |
32 show PerformanceTag; | 32 show PerformanceTag; |
33 import 'package:analyzer/src/services/lint.dart'; | 33 import 'package:analyzer/src/services/lint.dart'; |
34 import 'package:analyzer/src/source/source_resource.dart'; | 34 import 'package:analyzer/src/source/source_resource.dart'; |
35 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | |
35 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; | 36 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk; |
36 import 'package:analyzer/src/task/options.dart'; | 37 import 'package:analyzer/src/task/options.dart'; |
37 import 'package:analyzer_cli/src/analyzer_impl.dart'; | 38 import 'package:analyzer_cli/src/analyzer_impl.dart'; |
38 import 'package:analyzer_cli/src/build_mode.dart'; | 39 import 'package:analyzer_cli/src/build_mode.dart'; |
39 import 'package:analyzer_cli/src/error_formatter.dart'; | 40 import 'package:analyzer_cli/src/error_formatter.dart'; |
40 import 'package:analyzer_cli/src/incremental_analyzer.dart'; | 41 import 'package:analyzer_cli/src/incremental_analyzer.dart'; |
41 import 'package:analyzer_cli/src/options.dart'; | 42 import 'package:analyzer_cli/src/options.dart'; |
42 import 'package:analyzer_cli/src/perf_report.dart'; | 43 import 'package:analyzer_cli/src/perf_report.dart'; |
43 import 'package:analyzer_cli/starter.dart'; | 44 import 'package:analyzer_cli/starter.dart'; |
44 import 'package:linter/src/plugin/linter_plugin.dart'; | 45 import 'package:linter/src/plugin/linter_plugin.dart'; |
(...skipping 26 matching lines...) Expand all Loading... | |
71 | 72 |
72 class Driver implements CommandLineStarter { | 73 class Driver implements CommandLineStarter { |
73 static final PerformanceTag _analyzeAllTag = | 74 static final PerformanceTag _analyzeAllTag = |
74 new PerformanceTag("Driver._analyzeAll"); | 75 new PerformanceTag("Driver._analyzeAll"); |
75 | 76 |
76 /// The plugins that are defined outside the `analyzer_cli` package. | 77 /// The plugins that are defined outside the `analyzer_cli` package. |
77 List<Plugin> _userDefinedPlugins = <Plugin>[]; | 78 List<Plugin> _userDefinedPlugins = <Plugin>[]; |
78 | 79 |
79 /// The context that was most recently created by a call to [_analyzeAll], or | 80 /// The context that was most recently created by a call to [_analyzeAll], or |
80 /// `null` if [_analyzeAll] hasn't been called yet. | 81 /// `null` if [_analyzeAll] hasn't been called yet. |
81 AnalysisContext _context; | 82 InternalAnalysisContext _context; |
82 | 83 |
83 /// The total number of source files loaded by an AnalysisContext. | 84 /// The total number of source files loaded by an AnalysisContext. |
84 int _analyzedFileCount = 0; | 85 int _analyzedFileCount = 0; |
85 | 86 |
86 /// If [_context] is not `null`, the [CommandLineOptions] that guided its | 87 /// If [_context] is not `null`, the [CommandLineOptions] that guided its |
87 /// creation. | 88 /// creation. |
88 CommandLineOptions _previousOptions; | 89 CommandLineOptions _previousOptions; |
89 | 90 |
90 IncrementalAnalysisSession incrementalSession; | 91 IncrementalAnalysisSession incrementalSession; |
91 | 92 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 } | 308 } |
308 if (options.strongMode != _previousOptions.strongMode) { | 309 if (options.strongMode != _previousOptions.strongMode) { |
309 return false; | 310 return false; |
310 } | 311 } |
311 if (options.enableSuperMixins != _previousOptions.enableSuperMixins) { | 312 if (options.enableSuperMixins != _previousOptions.enableSuperMixins) { |
312 return false; | 313 return false; |
313 } | 314 } |
314 if (options.incrementalCachePath != _previousOptions.incrementalCachePath) { | 315 if (options.incrementalCachePath != _previousOptions.incrementalCachePath) { |
315 return false; | 316 return false; |
316 } | 317 } |
318 if (!_equalLists( | |
319 options.buildSummaryInputs, _previousOptions.buildSummaryInputs)) { | |
320 return false; | |
321 } | |
317 return true; | 322 return true; |
318 } | 323 } |
319 | 324 |
320 /// Decide on the appropriate policy for which files need to be fully parsed | 325 /// Decide on the appropriate policy for which files need to be fully parsed |
321 /// and which files need to be diet parsed, based on [options], and return an | 326 /// and which files need to be diet parsed, based on [options], and return an |
322 /// [AnalyzeFunctionBodiesPredicate] that implements this policy. | 327 /// [AnalyzeFunctionBodiesPredicate] that implements this policy. |
323 AnalyzeFunctionBodiesPredicate _chooseDietParsingPolicy( | 328 AnalyzeFunctionBodiesPredicate _chooseDietParsingPolicy( |
324 CommandLineOptions options) { | 329 CommandLineOptions options) { |
325 if (options.shouldBatch) { | 330 if (options.shouldBatch) { |
326 // As analyzer is currently implemented, once a file has been diet | 331 // As analyzer is currently implemented, once a file has been diet |
(...skipping 13 matching lines...) Expand all Loading... | |
340 // TODO(paulberry): diet parse 'package:' imports when we don't want | 345 // TODO(paulberry): diet parse 'package:' imports when we don't want |
341 // diagnostics. (Full parse is still needed for "self" packages.) | 346 // diagnostics. (Full parse is still needed for "self" packages.) |
342 return true; | 347 return true; |
343 } | 348 } |
344 }; | 349 }; |
345 } | 350 } |
346 | 351 |
347 /// Decide on the appropriate method for resolving URIs based on the given | 352 /// Decide on the appropriate method for resolving URIs based on the given |
348 /// [options] and [customUrlMappings] settings, and return a | 353 /// [options] and [customUrlMappings] settings, and return a |
349 /// [SourceFactory] that has been configured accordingly. | 354 /// [SourceFactory] that has been configured accordingly. |
350 SourceFactory _chooseUriResolutionPolicy(CommandLineOptions options, | 355 SourceFactory _chooseUriResolutionPolicy( |
351 Map<file_system.Folder, YamlMap> embedderMap, _PackageInfo packageInfo) { | 356 CommandLineOptions options, |
357 Map<file_system.Folder, YamlMap> embedderMap, | |
358 _PackageInfo packageInfo, | |
359 SummaryDataStore summaryDataStore) { | |
352 // Create a custom package resolver if one has been specified. | 360 // Create a custom package resolver if one has been specified. |
353 if (packageResolverProvider != null) { | 361 if (packageResolverProvider != null) { |
354 file_system.Folder folder = resourceProvider.getResource('.'); | 362 file_system.Folder folder = resourceProvider.getResource('.'); |
355 UriResolver resolver = packageResolverProvider(folder); | 363 UriResolver resolver = packageResolverProvider(folder); |
356 if (resolver != null) { | 364 if (resolver != null) { |
357 UriResolver sdkResolver = new DartUriResolver(sdk); | 365 UriResolver sdkResolver = new DartUriResolver(sdk); |
358 | 366 |
359 // TODO(brianwilkerson) This doesn't handle sdk extensions. | 367 // TODO(brianwilkerson) This doesn't handle sdk extensions. |
360 List<UriResolver> resolvers = <UriResolver>[ | 368 List<UriResolver> resolvers = <UriResolver>[ |
361 sdkResolver, | 369 sdkResolver, |
370 new InSummaryUriResolver(resourceProvider, summaryDataStore), | |
362 resolver, | 371 resolver, |
363 new file_system.ResourceUriResolver(resourceProvider) | 372 new file_system.ResourceUriResolver(resourceProvider) |
364 ]; | 373 ]; |
365 return new SourceFactory(resolvers); | 374 return new SourceFactory(resolvers); |
366 } | 375 } |
367 } | 376 } |
368 | 377 |
369 UriResolver packageUriResolver; | 378 UriResolver packageUriResolver; |
370 | 379 |
371 if (options.packageRootPath != null) { | 380 if (options.packageRootPath != null) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 // The embedder uri resolver has mappings, use it instead of the default | 419 // The embedder uri resolver has mappings, use it instead of the default |
411 // Dart SDK uri resolver. | 420 // Dart SDK uri resolver. |
412 resolvers.add(new DartUriResolver(embedderSdk)); | 421 resolvers.add(new DartUriResolver(embedderSdk)); |
413 } | 422 } |
414 | 423 |
415 // Next SdkExts. | 424 // Next SdkExts. |
416 if (packageInfo.packageMap != null) { | 425 if (packageInfo.packageMap != null) { |
417 resolvers.add(new SdkExtUriResolver(packageInfo.packageMap)); | 426 resolvers.add(new SdkExtUriResolver(packageInfo.packageMap)); |
418 } | 427 } |
419 | 428 |
429 // Then package URIs from summaries. | |
430 resolvers.add(new InSummaryUriResolver(resourceProvider, summaryDataStore)); | |
431 | |
420 // Then package URIs. | 432 // Then package URIs. |
421 if (packageUriResolver != null) { | 433 if (packageUriResolver != null) { |
422 resolvers.add(packageUriResolver); | 434 resolvers.add(packageUriResolver); |
423 } | 435 } |
424 | 436 |
425 // Finally files. | 437 // Finally files. |
426 resolvers.add(new file_system.ResourceUriResolver(resourceProvider)); | 438 resolvers.add(new file_system.ResourceUriResolver(resourceProvider)); |
427 | 439 |
428 return new SourceFactory(resolvers, packageInfo.packages); | 440 return new SourceFactory(resolvers, packageInfo.packages); |
429 } | 441 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 // Process embedders. | 510 // Process embedders. |
499 Map<file_system.Folder, YamlMap> embedderMap = | 511 Map<file_system.Folder, YamlMap> embedderMap = |
500 new EmbedderYamlLocator(packageInfo.packageMap).embedderYamls; | 512 new EmbedderYamlLocator(packageInfo.packageMap).embedderYamls; |
501 | 513 |
502 // Scan for SDK extenders. | 514 // Scan for SDK extenders. |
503 bool hasSdkExt = _hasSdkExt(packageInfo.packageMap?.values); | 515 bool hasSdkExt = _hasSdkExt(packageInfo.packageMap?.values); |
504 | 516 |
505 // No summaries in the presence of embedders or extenders. | 517 // No summaries in the presence of embedders or extenders. |
506 bool useSummaries = embedderMap.isEmpty && !hasSdkExt; | 518 bool useSummaries = embedderMap.isEmpty && !hasSdkExt; |
507 | 519 |
520 if (!useSummaries && options.buildSummaryInputs.isNotEmpty) { | |
521 throw new _DriverError( | |
522 'Summaries are not supported in this configuration'); | |
Brian Wilkerson
2016/09/16 19:27:30
Could we be more specific? Maybe something like
S
Paul Berry
2016/09/16 21:50:14
Done.
| |
523 } | |
524 | |
525 // Read any input summaries. | |
526 SummaryDataStore summaryDataStore = new SummaryDataStore( | |
527 useSummaries ? options.buildSummaryInputs : <String>[]); | |
528 | |
508 // Once options and embedders are processed, setup the SDK. | 529 // Once options and embedders are processed, setup the SDK. |
509 _setupSdk(options, useSummaries); | 530 _setupSdk(options, useSummaries); |
510 | 531 |
511 // Choose a package resolution policy and a diet parsing policy based on | 532 // Choose a package resolution policy and a diet parsing policy based on |
512 // the command-line options. | 533 // the command-line options. |
513 SourceFactory sourceFactory = | 534 SourceFactory sourceFactory = _chooseUriResolutionPolicy( |
514 _chooseUriResolutionPolicy(options, embedderMap, packageInfo); | 535 options, embedderMap, packageInfo, summaryDataStore); |
515 | 536 |
516 _context.sourceFactory = sourceFactory; | 537 _context.sourceFactory = sourceFactory; |
538 _context.resultProvider = | |
539 new InputPackagesResultProvider(_context, summaryDataStore); | |
517 | 540 |
518 incrementalSession = configureIncrementalAnalysis(options, context); | 541 incrementalSession = configureIncrementalAnalysis(options, context); |
519 } | 542 } |
520 | 543 |
521 /// Return discovered packagespec, or `null` if none is found. | 544 /// Return discovered packagespec, or `null` if none is found. |
522 Packages _discoverPackagespec(Uri root) { | 545 Packages _discoverPackagespec(Uri root) { |
523 try { | 546 try { |
524 Packages packages = pkg_discovery.findPackagesFromFile(root); | 547 Packages packages = pkg_discovery.findPackagesFromFile(root); |
525 if (packages != Packages.noPackages) { | 548 if (packages != Packages.noPackages) { |
526 return packages; | 549 return packages; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 createAnalysisOptionsForCommandLineOptions(options); | 709 createAnalysisOptionsForCommandLineOptions(options); |
687 configureContextOptions(contextOptions); | 710 configureContextOptions(contextOptions); |
688 | 711 |
689 // Set context options. | 712 // Set context options. |
690 context.analysisOptions = contextOptions; | 713 context.analysisOptions = contextOptions; |
691 | 714 |
692 // Process analysis options file (and notify all interested parties). | 715 // Process analysis options file (and notify all interested parties). |
693 _processAnalysisOptions(resourceProvider, context, options); | 716 _processAnalysisOptions(resourceProvider, context, options); |
694 } | 717 } |
695 | 718 |
719 /// Perform a deep comparison of two string lists. | |
720 static bool _equalLists(List<String> l1, List<String> l2) { | |
721 if (l1.length != l2.length) { | |
722 return false; | |
723 } | |
724 for (int i = 0; i < l1.length; i++) { | |
725 if (l1[i] != l2[i]) { | |
726 return false; | |
727 } | |
728 } | |
729 return true; | |
730 } | |
731 | |
696 /// Perform a deep comparison of two string maps. | 732 /// Perform a deep comparison of two string maps. |
697 static bool _equalMaps(Map<String, String> m1, Map<String, String> m2) { | 733 static bool _equalMaps(Map<String, String> m1, Map<String, String> m2) { |
698 if (m1.length != m2.length) { | 734 if (m1.length != m2.length) { |
699 return false; | 735 return false; |
700 } | 736 } |
701 for (String key in m1.keys) { | 737 for (String key in m1.keys) { |
702 if (!m2.containsKey(key) || m1[key] != m2[key]) { | 738 if (!m2.containsKey(key) || m1[key] != m2[key]) { |
703 return false; | 739 return false; |
704 } | 740 } |
705 } | 741 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 for (var package in packages) { | 883 for (var package in packages) { |
848 var packageName = path.basename(package.path); | 884 var packageName = path.basename(package.path); |
849 var realPath = package.resolveSymbolicLinksSync(); | 885 var realPath = package.resolveSymbolicLinksSync(); |
850 result[packageName] = [ | 886 result[packageName] = [ |
851 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 887 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
852 ]; | 888 ]; |
853 } | 889 } |
854 return result; | 890 return result; |
855 } | 891 } |
856 } | 892 } |
OLD | NEW |