| 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 |
| 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'; | 22 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 23 import 'package:analyzer/src/dart/analysis/driver.dart'; | 23 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 24 import 'package:analyzer/src/dart/analysis/file_byte_store.dart'; |
| 24 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 25 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 25 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 26 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 26 import 'package:analyzer/src/generated/constant.dart'; | 27 import 'package:analyzer/src/generated/constant.dart'; |
| 27 import 'package:analyzer/src/generated/engine.dart'; | 28 import 'package:analyzer/src/generated/engine.dart'; |
| 28 import 'package:analyzer/src/generated/interner.dart'; | 29 import 'package:analyzer/src/generated/interner.dart'; |
| 29 import 'package:analyzer/src/generated/java_engine.dart'; | 30 import 'package:analyzer/src/generated/java_engine.dart'; |
| 30 import 'package:analyzer/src/generated/sdk.dart'; | 31 import 'package:analyzer/src/generated/sdk.dart'; |
| 31 import 'package:analyzer/src/generated/source.dart'; | 32 import 'package:analyzer/src/generated/source.dart'; |
| 32 import 'package:analyzer/src/generated/source_io.dart'; | 33 import 'package:analyzer/src/generated/source_io.dart'; |
| 33 import 'package:analyzer/src/generated/utilities_general.dart' | 34 import 'package:analyzer/src/generated/utilities_general.dart' |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 var linterNode = options['linter']; | 70 var linterNode = options['linter']; |
| 70 return linterNode is YamlMap && linterNode.containsKey('rules'); | 71 return linterNode is YamlMap && linterNode.containsKey('rules'); |
| 71 } | 72 } |
| 72 | 73 |
| 73 typedef Future<ErrorSeverity> _BatchRunnerHandler(List<String> args); | 74 typedef Future<ErrorSeverity> _BatchRunnerHandler(List<String> args); |
| 74 | 75 |
| 75 class Driver implements CommandLineStarter { | 76 class Driver implements CommandLineStarter { |
| 76 static final PerformanceTag _analyzeAllTag = | 77 static final PerformanceTag _analyzeAllTag = |
| 77 new PerformanceTag("Driver._analyzeAll"); | 78 new PerformanceTag("Driver._analyzeAll"); |
| 78 | 79 |
| 79 static ByteStore analysisDriverByteStore = new MemoryByteStore(); | 80 static ByteStore analysisDriverMemoryByteStore = new MemoryByteStore(); |
| 81 static ByteStore analysisDriverFileByteStore = new MemoryCachingByteStore( |
| 82 new EvictingFileByteStore( |
| 83 PhysicalResourceProvider.INSTANCE |
| 84 .getStateLocation('.analysis-driver') |
| 85 .path, |
| 86 1024 * 1024 * 1024 /*1 GiB*/), |
| 87 64 * 1024 * 1024 /*64 MiB*/); |
| 80 | 88 |
| 81 /// The plugins that are defined outside the `analyzer_cli` package. | 89 /// The plugins that are defined outside the `analyzer_cli` package. |
| 82 List<Plugin> _userDefinedPlugins = <Plugin>[]; | 90 List<Plugin> _userDefinedPlugins = <Plugin>[]; |
| 83 | 91 |
| 84 /// The context that was most recently created by a call to [_analyzeAll], or | 92 /// The context that was most recently created by a call to [_analyzeAll], or |
| 85 /// `null` if [_analyzeAll] hasn't been called yet. | 93 /// `null` if [_analyzeAll] hasn't been called yet. |
| 86 InternalAnalysisContext _context; | 94 InternalAnalysisContext _context; |
| 87 | 95 |
| 88 AnalysisDriver analysisDriver; | 96 AnalysisDriver analysisDriver; |
| 89 | 97 |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 setupAnalysisContext(_context, options, analysisOptions); | 573 setupAnalysisContext(_context, options, analysisOptions); |
| 566 _context.sourceFactory = sourceFactory; | 574 _context.sourceFactory = sourceFactory; |
| 567 | 575 |
| 568 if (options.enableNewAnalysisDriver) { | 576 if (options.enableNewAnalysisDriver) { |
| 569 PerformanceLog log = new PerformanceLog(null); | 577 PerformanceLog log = new PerformanceLog(null); |
| 570 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(log); | 578 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(log); |
| 571 analysisDriver = new AnalysisDriver( | 579 analysisDriver = new AnalysisDriver( |
| 572 scheduler, | 580 scheduler, |
| 573 log, | 581 log, |
| 574 resourceProvider, | 582 resourceProvider, |
| 575 analysisDriverByteStore, | 583 options.useAnalysisDriverMemoryByteStore |
| 584 ? analysisDriverMemoryByteStore |
| 585 : analysisDriverFileByteStore, |
| 576 new FileContentOverlay(), | 586 new FileContentOverlay(), |
| 577 'test', | 587 'test', |
| 578 context.sourceFactory, | 588 context.sourceFactory, |
| 579 context.analysisOptions); | 589 context.analysisOptions); |
| 580 analysisDriver.results.listen((_) {}); | 590 analysisDriver.results.listen((_) {}); |
| 581 analysisDriver.exceptions.listen((_) {}); | 591 analysisDriver.exceptions.listen((_) {}); |
| 582 scheduler.start(); | 592 scheduler.start(); |
| 583 } else { | 593 } else { |
| 584 if (sdkBundle != null) { | 594 if (sdkBundle != null) { |
| 585 _context.resultProvider = | 595 _context.resultProvider = |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 sourcePath = path.absolute(sourcePath); | 719 sourcePath = path.absolute(sourcePath); |
| 710 sourcePath = path.normalize(sourcePath); | 720 sourcePath = path.normalize(sourcePath); |
| 711 return !path.isWithin(dartSdkPath, sourcePath); | 721 return !path.isWithin(dartSdkPath, sourcePath); |
| 712 }); | 722 }); |
| 713 dartSdk.analysisOptions = analysisOptions; | 723 dartSdk.analysisOptions = analysisOptions; |
| 714 sdk = dartSdk; | 724 sdk = dartSdk; |
| 715 } | 725 } |
| 716 } | 726 } |
| 717 } | 727 } |
| 718 | 728 |
| 729 static AnalysisOptionsImpl createAnalysisOptions( |
| 730 file_system.ResourceProvider resourceProvider, |
| 731 SourceFactory sourceFactory, |
| 732 CommandLineOptions options) { |
| 733 // Prepare context options. |
| 734 AnalysisOptionsImpl analysisOptions = |
| 735 createAnalysisOptionsForCommandLineOptions(options); |
| 736 |
| 737 // Process analysis options file (and notify all interested parties). |
| 738 _processAnalysisOptions( |
| 739 resourceProvider, sourceFactory, analysisOptions, options); |
| 740 return analysisOptions; |
| 741 } |
| 742 |
| 719 static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( | 743 static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( |
| 720 CommandLineOptions options) { | 744 CommandLineOptions options) { |
| 721 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); | 745 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); |
| 722 contextOptions.trackCacheDependencies = false; | 746 contextOptions.trackCacheDependencies = false; |
| 723 contextOptions.disableCacheFlushing = options.disableCacheFlushing; | 747 contextOptions.disableCacheFlushing = options.disableCacheFlushing; |
| 724 contextOptions.hint = !options.disableHints; | 748 contextOptions.hint = !options.disableHints; |
| 725 contextOptions.enableStrictCallChecks = options.enableStrictCallChecks; | 749 contextOptions.enableStrictCallChecks = options.enableStrictCallChecks; |
| 726 contextOptions.enableSuperMixins = options.enableSuperMixins; | 750 contextOptions.enableSuperMixins = options.enableSuperMixins; |
| 727 contextOptions.generateImplicitErrors = options.showPackageWarnings; | 751 contextOptions.generateImplicitErrors = options.showPackageWarnings; |
| 728 contextOptions.generateSdkErrors = options.showSdkWarnings; | 752 contextOptions.generateSdkErrors = options.showSdkWarnings; |
| 729 contextOptions.lint = options.lints; | 753 contextOptions.lint = options.lints; |
| 730 contextOptions.strongMode = options.strongMode; | 754 contextOptions.strongMode = options.strongMode; |
| 731 contextOptions.implicitCasts = options.implicitCasts; | 755 contextOptions.implicitCasts = options.implicitCasts; |
| 732 contextOptions.implicitDynamic = options.implicitDynamic; | 756 contextOptions.implicitDynamic = options.implicitDynamic; |
| 733 return contextOptions; | 757 return contextOptions; |
| 734 } | 758 } |
| 735 | 759 |
| 736 static AnalysisOptionsImpl createAnalysisOptions( | |
| 737 file_system.ResourceProvider resourceProvider, | |
| 738 SourceFactory sourceFactory, | |
| 739 CommandLineOptions options) { | |
| 740 // Prepare context options. | |
| 741 AnalysisOptionsImpl analysisOptions = | |
| 742 createAnalysisOptionsForCommandLineOptions(options); | |
| 743 | |
| 744 // Process analysis options file (and notify all interested parties). | |
| 745 _processAnalysisOptions( | |
| 746 resourceProvider, sourceFactory, analysisOptions, options); | |
| 747 return analysisOptions; | |
| 748 } | |
| 749 | |
| 750 static void setAnalysisContextOptions( | 760 static void setAnalysisContextOptions( |
| 751 file_system.ResourceProvider resourceProvider, | 761 file_system.ResourceProvider resourceProvider, |
| 752 SourceFactory sourceFactory, | 762 SourceFactory sourceFactory, |
| 753 AnalysisContext context, | 763 AnalysisContext context, |
| 754 CommandLineOptions options, | 764 CommandLineOptions options, |
| 755 void configureContextOptions(AnalysisOptionsImpl contextOptions)) { | 765 void configureContextOptions(AnalysisOptionsImpl contextOptions)) { |
| 756 AnalysisOptionsImpl analysisOptions = | 766 AnalysisOptionsImpl analysisOptions = |
| 757 createAnalysisOptions(resourceProvider, sourceFactory, options); | 767 createAnalysisOptions(resourceProvider, sourceFactory, options); |
| 758 configureContextOptions(analysisOptions); | 768 configureContextOptions(analysisOptions); |
| 759 setupAnalysisContext(context, options, analysisOptions); | 769 setupAnalysisContext(context, options, analysisOptions); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 for (var package in packages) { | 948 for (var package in packages) { |
| 939 var packageName = path.basename(package.path); | 949 var packageName = path.basename(package.path); |
| 940 var realPath = package.resolveSymbolicLinksSync(); | 950 var realPath = package.resolveSymbolicLinksSync(); |
| 941 result[packageName] = [ | 951 result[packageName] = [ |
| 942 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 952 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 943 ]; | 953 ]; |
| 944 } | 954 } |
| 945 return result; | 955 return result; |
| 946 } | 956 } |
| 947 } | 957 } |
| OLD | NEW |