| 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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 setupAnalysisContext(_context, options, analysisOptions); | 580 setupAnalysisContext(_context, options, analysisOptions); |
| 573 _context.sourceFactory = sourceFactory; | 581 _context.sourceFactory = sourceFactory; |
| 574 | 582 |
| 575 if (options.enableNewAnalysisDriver) { | 583 if (options.enableNewAnalysisDriver) { |
| 576 PerformanceLog log = new PerformanceLog(null); | 584 PerformanceLog log = new PerformanceLog(null); |
| 577 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(log); | 585 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(log); |
| 578 analysisDriver = new AnalysisDriver( | 586 analysisDriver = new AnalysisDriver( |
| 579 scheduler, | 587 scheduler, |
| 580 log, | 588 log, |
| 581 resourceProvider, | 589 resourceProvider, |
| 582 analysisDriverByteStore, | 590 options.useAnalysisDriverMemoryByteStore |
| 591 ? analysisDriverMemoryByteStore |
| 592 : analysisDriverFileByteStore, |
| 583 new FileContentOverlay(), | 593 new FileContentOverlay(), |
| 584 'test', | 594 'test', |
| 585 context.sourceFactory, | 595 context.sourceFactory, |
| 586 context.analysisOptions); | 596 context.analysisOptions); |
| 587 analysisDriver.results.listen((_) {}); | 597 analysisDriver.results.listen((_) {}); |
| 588 analysisDriver.exceptions.listen((_) {}); | 598 analysisDriver.exceptions.listen((_) {}); |
| 589 scheduler.start(); | 599 scheduler.start(); |
| 590 } else { | 600 } else { |
| 591 if (sdkBundle != null) { | 601 if (sdkBundle != null) { |
| 592 _context.resultProvider = | 602 _context.resultProvider = |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 sourcePath = path.absolute(sourcePath); | 726 sourcePath = path.absolute(sourcePath); |
| 717 sourcePath = path.normalize(sourcePath); | 727 sourcePath = path.normalize(sourcePath); |
| 718 return !path.isWithin(dartSdkPath, sourcePath); | 728 return !path.isWithin(dartSdkPath, sourcePath); |
| 719 }); | 729 }); |
| 720 dartSdk.analysisOptions = analysisOptions; | 730 dartSdk.analysisOptions = analysisOptions; |
| 721 sdk = dartSdk; | 731 sdk = dartSdk; |
| 722 } | 732 } |
| 723 } | 733 } |
| 724 } | 734 } |
| 725 | 735 |
| 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 |
| 726 static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( | 750 static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( |
| 727 CommandLineOptions options) { | 751 CommandLineOptions options) { |
| 728 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); | 752 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); |
| 729 contextOptions.trackCacheDependencies = false; | 753 contextOptions.trackCacheDependencies = false; |
| 730 contextOptions.disableCacheFlushing = options.disableCacheFlushing; | 754 contextOptions.disableCacheFlushing = options.disableCacheFlushing; |
| 731 contextOptions.hint = !options.disableHints; | 755 contextOptions.hint = !options.disableHints; |
| 732 contextOptions.enableStrictCallChecks = options.enableStrictCallChecks; | 756 contextOptions.enableStrictCallChecks = options.enableStrictCallChecks; |
| 733 contextOptions.enableSuperMixins = options.enableSuperMixins; | 757 contextOptions.enableSuperMixins = options.enableSuperMixins; |
| 734 contextOptions.generateImplicitErrors = options.showPackageWarnings; | 758 contextOptions.generateImplicitErrors = options.showPackageWarnings; |
| 735 contextOptions.generateSdkErrors = options.showSdkWarnings; | 759 contextOptions.generateSdkErrors = options.showSdkWarnings; |
| 736 contextOptions.lint = options.lints; | 760 contextOptions.lint = options.lints; |
| 737 contextOptions.strongMode = options.strongMode; | 761 contextOptions.strongMode = options.strongMode; |
| 738 contextOptions.implicitCasts = options.implicitCasts; | 762 contextOptions.implicitCasts = options.implicitCasts; |
| 739 contextOptions.implicitDynamic = options.implicitDynamic; | 763 contextOptions.implicitDynamic = options.implicitDynamic; |
| 740 return contextOptions; | 764 return contextOptions; |
| 741 } | 765 } |
| 742 | 766 |
| 743 static AnalysisOptionsImpl createAnalysisOptions( | |
| 744 file_system.ResourceProvider resourceProvider, | |
| 745 SourceFactory sourceFactory, | |
| 746 CommandLineOptions options) { | |
| 747 // Prepare context options. | |
| 748 AnalysisOptionsImpl analysisOptions = | |
| 749 createAnalysisOptionsForCommandLineOptions(options); | |
| 750 | |
| 751 // Process analysis options file (and notify all interested parties). | |
| 752 _processAnalysisOptions( | |
| 753 resourceProvider, sourceFactory, analysisOptions, options); | |
| 754 return analysisOptions; | |
| 755 } | |
| 756 | |
| 757 static void setAnalysisContextOptions( | 767 static void setAnalysisContextOptions( |
| 758 file_system.ResourceProvider resourceProvider, | 768 file_system.ResourceProvider resourceProvider, |
| 759 SourceFactory sourceFactory, | 769 SourceFactory sourceFactory, |
| 760 AnalysisContext context, | 770 AnalysisContext context, |
| 761 CommandLineOptions options, | 771 CommandLineOptions options, |
| 762 void configureContextOptions(AnalysisOptionsImpl contextOptions)) { | 772 void configureContextOptions(AnalysisOptionsImpl contextOptions)) { |
| 763 AnalysisOptionsImpl analysisOptions = | 773 AnalysisOptionsImpl analysisOptions = |
| 764 createAnalysisOptions(resourceProvider, sourceFactory, options); | 774 createAnalysisOptions(resourceProvider, sourceFactory, options); |
| 765 configureContextOptions(analysisOptions); | 775 configureContextOptions(analysisOptions); |
| 766 setupAnalysisContext(context, options, analysisOptions); | 776 setupAnalysisContext(context, options, analysisOptions); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 for (var package in packages) { | 955 for (var package in packages) { |
| 946 var packageName = path.basename(package.path); | 956 var packageName = path.basename(package.path); |
| 947 var realPath = package.resolveSymbolicLinksSync(); | 957 var realPath = package.resolveSymbolicLinksSync(); |
| 948 result[packageName] = [ | 958 result[packageName] = [ |
| 949 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 959 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 950 ]; | 960 ]; |
| 951 } | 961 } |
| 952 return result; | 962 return result; |
| 953 } | 963 } |
| 954 } | 964 } |
| OLD | NEW |