Chromium Code Reviews| 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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 | 554 |
| 555 if (!useSummaries && options.buildSummaryInputs.isNotEmpty) { | 555 if (!useSummaries && options.buildSummaryInputs.isNotEmpty) { |
| 556 throw new _DriverError( | 556 throw new _DriverError( |
| 557 'Summaries are not yet supported when using Flutter.'); | 557 'Summaries are not yet supported when using Flutter.'); |
| 558 } | 558 } |
| 559 | 559 |
| 560 // Read any input summaries. | 560 // Read any input summaries. |
| 561 SummaryDataStore summaryDataStore = new SummaryDataStore( | 561 SummaryDataStore summaryDataStore = new SummaryDataStore( |
| 562 useSummaries ? options.buildSummaryInputs : <String>[]); | 562 useSummaries ? options.buildSummaryInputs : <String>[]); |
| 563 | 563 |
| 564 // Create a temporary source factory without an SDK resolver | |
| 565 // for resolving "include:" directives in analysis options files. | |
| 566 SourceFactory tempSourceFactory = _chooseUriResolutionPolicy( | |
| 567 options, embedderMap, packageInfo, summaryDataStore, false, null); | |
| 568 | |
| 569 AnalysisOptionsImpl analysisOptions = | 564 AnalysisOptionsImpl analysisOptions = |
| 570 createAnalysisOptions(resourceProvider, tempSourceFactory, options); | 565 createAnalysisOptionsForCommandLineOptions(resourceProvider, options); |
| 571 analysisOptions.analyzeFunctionBodiesPredicate = | 566 analysisOptions.analyzeFunctionBodiesPredicate = |
| 572 _chooseDietParsingPolicy(options); | 567 _chooseDietParsingPolicy(options); |
| 573 | 568 |
| 574 // Once options and embedders are processed, setup the SDK. | 569 // Once options and embedders are processed, setup the SDK. |
| 575 _setupSdk(options, useSummaries, analysisOptions); | 570 _setupSdk(options, useSummaries, analysisOptions); |
| 576 | 571 |
| 577 PackageBundle sdkBundle = sdk.getLinkedBundle(); | 572 PackageBundle sdkBundle = sdk.getLinkedBundle(); |
| 578 if (sdkBundle != null) { | 573 if (sdkBundle != null) { |
| 579 summaryDataStore.addBundle(null, sdkBundle); | 574 summaryDataStore.addBundle(null, sdkBundle); |
| 580 } | 575 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 sourcePath = path.absolute(sourcePath); | 728 sourcePath = path.absolute(sourcePath); |
| 734 sourcePath = path.normalize(sourcePath); | 729 sourcePath = path.normalize(sourcePath); |
| 735 return !path.isWithin(dartSdkPath, sourcePath); | 730 return !path.isWithin(dartSdkPath, sourcePath); |
| 736 }); | 731 }); |
| 737 dartSdk.analysisOptions = analysisOptions; | 732 dartSdk.analysisOptions = analysisOptions; |
| 738 sdk = dartSdk; | 733 sdk = dartSdk; |
| 739 } | 734 } |
| 740 } | 735 } |
| 741 } | 736 } |
| 742 | 737 |
| 743 static AnalysisOptionsImpl createAnalysisOptions( | 738 static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( |
| 744 file_system.ResourceProvider resourceProvider, | 739 ResourceProvider resourceProvider, CommandLineOptions options) { |
| 745 SourceFactory sourceFactory, | 740 if (options.analysisOptionsFile != null) { |
| 746 CommandLineOptions options) { | 741 file_system.File file = |
| 747 // Prepare context options. | 742 resourceProvider.getFile(options.analysisOptionsFile); |
| 748 AnalysisOptionsImpl analysisOptions = | 743 if (!file.exists) { |
| 749 createAnalysisOptionsForCommandLineOptions(options); | 744 printAndFail('Options file not found: ${options.analysisOptionsFile}', |
| 745 exitCode: ErrorSeverity.ERROR.ordinal); | |
| 746 } | |
| 747 } | |
| 750 | 748 |
| 751 // Process analysis options file (and notify all interested parties). | 749 AnalysisOptionsImpl contextOptions = new ContextBuilder( |
| 752 _processAnalysisOptions( | 750 resourceProvider, null, null, |
| 753 resourceProvider, sourceFactory, analysisOptions, options); | 751 options: options.contextBuilderOptions) |
|
Brian Wilkerson
2017/02/23 21:29:23
Might be good to create a ContextBuilder in one pl
danrubel
2017/02/23 21:51:20
Good point. I'll do that when we start using Conte
| |
| 754 return analysisOptions; | 752 .getAnalysisOptions(options.sourceFiles.isNotEmpty |
| 755 } | 753 ? options.sourceFiles[0] |
| 754 : path.current); | |
| 756 | 755 |
| 757 static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( | |
| 758 CommandLineOptions options) { | |
| 759 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); | |
| 760 contextOptions.trackCacheDependencies = false; | 756 contextOptions.trackCacheDependencies = false; |
| 761 contextOptions.disableCacheFlushing = options.disableCacheFlushing; | 757 contextOptions.disableCacheFlushing = options.disableCacheFlushing; |
| 762 contextOptions.hint = !options.disableHints; | 758 contextOptions.hint = !options.disableHints; |
| 763 contextOptions.enableStrictCallChecks = options.enableStrictCallChecks; | |
| 764 contextOptions.enableSuperMixins = options.enableSuperMixins; | |
| 765 contextOptions.generateImplicitErrors = options.showPackageWarnings; | 759 contextOptions.generateImplicitErrors = options.showPackageWarnings; |
| 766 contextOptions.generateSdkErrors = options.showSdkWarnings; | 760 contextOptions.generateSdkErrors = options.showSdkWarnings; |
| 767 contextOptions.lint = options.lints; | 761 |
| 768 contextOptions.strongMode = options.strongMode; | 762 // The following options are updated as appropriate by the |
| 769 contextOptions.implicitCasts = options.implicitCasts; | 763 // ContextBuilder getAnalysisOptions(...) |
| 770 contextOptions.implicitDynamic = options.implicitDynamic; | 764 //contextOptions.enableStrictCallChecks = options.enableStrictCallChecks; |
| 765 //contextOptions.enableSuperMixins = options.enableSuperMixins; | |
| 766 //contextOptions.strongMode = options.strongMode; | |
| 767 //contextOptions.implicitCasts = options.implicitCasts; | |
| 768 //contextOptions.implicitDynamic = options.implicitDynamic; | |
|
Brian Wilkerson
2017/02/23 21:29:22
Did you intend to remove these?
danrubel
2017/02/23 21:51:20
Yeah. Forgot to do so. Now removed.
| |
| 769 | |
| 771 return contextOptions; | 770 return contextOptions; |
| 772 } | 771 } |
| 773 | 772 |
| 774 static void setAnalysisContextOptions( | 773 static void setAnalysisContextOptions( |
| 775 file_system.ResourceProvider resourceProvider, | 774 file_system.ResourceProvider resourceProvider, |
| 776 SourceFactory sourceFactory, | |
| 777 AnalysisContext context, | 775 AnalysisContext context, |
| 778 CommandLineOptions options, | 776 CommandLineOptions options, |
| 779 void configureContextOptions(AnalysisOptionsImpl contextOptions)) { | 777 void configureContextOptions(AnalysisOptionsImpl contextOptions)) { |
| 780 AnalysisOptionsImpl analysisOptions = | 778 AnalysisOptionsImpl analysisOptions = |
| 781 createAnalysisOptions(resourceProvider, sourceFactory, options); | 779 createAnalysisOptionsForCommandLineOptions(resourceProvider, options); |
| 782 configureContextOptions(analysisOptions); | 780 configureContextOptions(analysisOptions); |
| 783 setupAnalysisContext(context, options, analysisOptions); | 781 setupAnalysisContext(context, options, analysisOptions); |
| 784 } | 782 } |
| 785 | 783 |
| 786 static void setupAnalysisContext(AnalysisContext context, | 784 static void setupAnalysisContext(AnalysisContext context, |
| 787 CommandLineOptions options, AnalysisOptionsImpl analysisOptions) { | 785 CommandLineOptions options, AnalysisOptionsImpl analysisOptions) { |
| 788 Map<String, String> definedVariables = options.definedVariables; | 786 Map<String, String> definedVariables = options.definedVariables; |
| 789 if (definedVariables.isNotEmpty) { | 787 if (definedVariables.isNotEmpty) { |
| 790 DeclaredVariables declaredVariables = context.declaredVariables; | 788 DeclaredVariables declaredVariables = context.declaredVariables; |
| 791 definedVariables.forEach((String variableName, String value) { | 789 definedVariables.forEach((String variableName, String value) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 820 return false; | 818 return false; |
| 821 } | 819 } |
| 822 for (String key in m1.keys) { | 820 for (String key in m1.keys) { |
| 823 if (!m2.containsKey(key) || m1[key] != m2[key]) { | 821 if (!m2.containsKey(key) || m1[key] != m2[key]) { |
| 824 return false; | 822 return false; |
| 825 } | 823 } |
| 826 } | 824 } |
| 827 return true; | 825 return true; |
| 828 } | 826 } |
| 829 | 827 |
| 830 static file_system.File _getOptionsFile( | |
| 831 file_system.ResourceProvider resourceProvider, | |
| 832 CommandLineOptions options) { | |
| 833 file_system.File file; | |
| 834 String filePath = options.analysisOptionsFile; | |
| 835 if (filePath != null) { | |
| 836 file = resourceProvider.getFile(filePath); | |
| 837 if (!file.exists) { | |
| 838 printAndFail('Options file not found: $filePath', | |
| 839 exitCode: ErrorSeverity.ERROR.ordinal); | |
| 840 } | |
| 841 } else { | |
| 842 filePath = AnalysisEngine.ANALYSIS_OPTIONS_FILE; | |
| 843 file = resourceProvider.getFile(filePath); | |
| 844 if (!file.exists) { | |
| 845 filePath = AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE; | |
| 846 file = resourceProvider.getFile(filePath); | |
| 847 } | |
| 848 } | |
| 849 return file; | |
| 850 } | |
| 851 | |
| 852 /// Convert [sourcePath] into an absolute path. | 828 /// Convert [sourcePath] into an absolute path. |
| 853 static String _normalizeSourcePath(String sourcePath) => | 829 static String _normalizeSourcePath(String sourcePath) => |
| 854 path.normalize(new io.File(sourcePath).absolute.path); | 830 path.normalize(new io.File(sourcePath).absolute.path); |
| 855 | |
| 856 static void _processAnalysisOptions( | |
| 857 file_system.ResourceProvider resourceProvider, | |
| 858 SourceFactory sourceFactory, | |
| 859 AnalysisOptionsImpl analysisOptions, | |
| 860 CommandLineOptions options) { | |
| 861 file_system.File file = _getOptionsFile(resourceProvider, options); | |
| 862 | |
| 863 AnalysisOptionsProvider analysisOptionsProvider = | |
| 864 new AnalysisOptionsProvider(sourceFactory); | |
| 865 Map<String, YamlNode> optionMap = | |
| 866 analysisOptionsProvider.getOptionsFromFile(file); | |
| 867 | |
| 868 // Fill in lint rule defaults in case lints are enabled and rules are | |
| 869 // not specified in an options file. | |
| 870 if (options.lints && !containsLintRuleEntry(optionMap)) { | |
| 871 analysisOptions.lintRules = Registry.ruleRegistry.defaultRules; | |
| 872 } | |
| 873 | |
| 874 // Ask engine to further process options. | |
| 875 if (optionMap != null) { | |
| 876 applyToAnalysisOptions(analysisOptions, optionMap); | |
| 877 } | |
| 878 } | |
| 879 } | 831 } |
| 880 | 832 |
| 881 /// Provides a framework to read command line options from stdin and feed them | 833 /// Provides a framework to read command line options from stdin and feed them |
| 882 /// to a callback. | 834 /// to a callback. |
| 883 class _BatchRunner { | 835 class _BatchRunner { |
| 884 /// Run the tool in 'batch' mode, receiving command lines through stdin and | 836 /// Run the tool in 'batch' mode, receiving command lines through stdin and |
| 885 /// returning pass/fail status through stdout. This feature is intended for | 837 /// returning pass/fail status through stdout. This feature is intended for |
| 886 /// use in unit testing. | 838 /// use in unit testing. |
| 887 static void runAsBatch(List<String> sharedArgs, _BatchRunnerHandler handler) { | 839 static void runAsBatch(List<String> sharedArgs, _BatchRunnerHandler handler) { |
| 888 outSink.writeln('>>> BATCH START'); | 840 outSink.writeln('>>> BATCH START'); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 for (var package in packages) { | 914 for (var package in packages) { |
| 963 var packageName = path.basename(package.path); | 915 var packageName = path.basename(package.path); |
| 964 var realPath = package.resolveSymbolicLinksSync(); | 916 var realPath = package.resolveSymbolicLinksSync(); |
| 965 result[packageName] = [ | 917 result[packageName] = [ |
| 966 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 918 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 967 ]; | 919 ]; |
| 968 } | 920 } |
| 969 return result; | 921 return result; |
| 970 } | 922 } |
| 971 } | 923 } |
| OLD | NEW |