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

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

Issue 2212813003: Clean up use of resource provider in cli (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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_cli/lib/src/build_mode.dart ('k') | pkg/analyzer_cli/test/build_mode_test.dart » ('j') | 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 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'; 9 import 'dart:io';
10 10
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 stats.print(outSink); 245 stats.print(outSink);
246 } 246 }
247 247
248 return allResult; 248 return allResult;
249 } 249 }
250 250
251 /// Perform analysis in build mode according to the given [options]. 251 /// Perform analysis in build mode according to the given [options].
252 ErrorSeverity _buildModeAnalyze(CommandLineOptions options) { 252 ErrorSeverity _buildModeAnalyze(CommandLineOptions options) {
253 return _analyzeAllTag.makeCurrentWhile(() { 253 return _analyzeAllTag.makeCurrentWhile(() {
254 if (options.buildModePersistentWorker) { 254 if (options.buildModePersistentWorker) {
255 new AnalyzerWorkerLoop.std(dartSdkPath: options.dartSdkPath).run(); 255 new AnalyzerWorkerLoop.std(resourceProvider,
256 dartSdkPath: options.dartSdkPath)
257 .run();
256 } else { 258 } else {
257 return new BuildMode(options, stats).analyze(); 259 return new BuildMode(resourceProvider, options, stats).analyze();
258 } 260 }
259 }); 261 });
260 } 262 }
261 263
262 /// Determine whether the context created during a previous call to 264 /// Determine whether the context created during a previous call to
263 /// [_analyzeAll] can be re-used in order to analyze using [options]. 265 /// [_analyzeAll] can be re-used in order to analyze using [options].
264 bool _canContextBeReused(CommandLineOptions options) { 266 bool _canContextBeReused(CommandLineOptions options) {
265 // TODO(paulberry): add a command-line option that disables context re-use. 267 // TODO(paulberry): add a command-line option that disables context re-use.
266 if (_context == null) { 268 if (_context == null) {
267 return false; 269 return false;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // Save stats from previous context before clobbering it. 474 // Save stats from previous context before clobbering it.
473 if (_context != null) { 475 if (_context != null) {
474 _analyzedFileCount += _context.sources.length; 476 _analyzedFileCount += _context.sources.length;
475 } 477 }
476 478
477 // Create a context. 479 // Create a context.
478 _context = AnalysisEngine.instance.createAnalysisContext(); 480 _context = AnalysisEngine.instance.createAnalysisContext();
479 481
480 AnalyzeFunctionBodiesPredicate dietParsingPolicy = 482 AnalyzeFunctionBodiesPredicate dietParsingPolicy =
481 _chooseDietParsingPolicy(options); 483 _chooseDietParsingPolicy(options);
482 setAnalysisContextOptions(_context, options, 484 setAnalysisContextOptions(resourceProvider, _context, options,
483 (AnalysisOptionsImpl contextOptions) { 485 (AnalysisOptionsImpl contextOptions) {
484 contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy; 486 contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy;
485 }); 487 });
486 488
487 // Find package info. 489 // Find package info.
488 _PackageInfo packageInfo = _findPackages(options); 490 _PackageInfo packageInfo = _findPackages(options);
489 491
490 // Process embedders. 492 // Process embedders.
491 Map<file_system.Folder, YamlMap> embedderMap = 493 Map<file_system.Folder, YamlMap> embedderMap =
492 new EmbedderYamlLocator(packageInfo.packageMap).embedderYamls; 494 new EmbedderYamlLocator(packageInfo.packageMap).embedderYamls;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 contextOptions.generateImplicitErrors = options.showPackageWarnings; 650 contextOptions.generateImplicitErrors = options.showPackageWarnings;
649 contextOptions.generateSdkErrors = options.showSdkWarnings; 651 contextOptions.generateSdkErrors = options.showSdkWarnings;
650 contextOptions.lint = options.lints; 652 contextOptions.lint = options.lints;
651 contextOptions.strongMode = options.strongMode; 653 contextOptions.strongMode = options.strongMode;
652 contextOptions.implicitCasts = options.implicitCasts; 654 contextOptions.implicitCasts = options.implicitCasts;
653 contextOptions.implicitDynamic = options.implicitDynamic; 655 contextOptions.implicitDynamic = options.implicitDynamic;
654 return contextOptions; 656 return contextOptions;
655 } 657 }
656 658
657 static void setAnalysisContextOptions( 659 static void setAnalysisContextOptions(
660 file_system.ResourceProvider resourceProvider,
658 AnalysisContext context, 661 AnalysisContext context,
659 CommandLineOptions options, 662 CommandLineOptions options,
660 void configureContextOptions(AnalysisOptionsImpl contextOptions)) { 663 void configureContextOptions(AnalysisOptionsImpl contextOptions)) {
661 Map<String, String> definedVariables = options.definedVariables; 664 Map<String, String> definedVariables = options.definedVariables;
662 if (definedVariables.isNotEmpty) { 665 if (definedVariables.isNotEmpty) {
663 DeclaredVariables declaredVariables = context.declaredVariables; 666 DeclaredVariables declaredVariables = context.declaredVariables;
664 definedVariables.forEach((String variableName, String value) { 667 definedVariables.forEach((String variableName, String value) {
665 declaredVariables.define(variableName, value); 668 declaredVariables.define(variableName, value);
666 }); 669 });
667 } 670 }
668 671
669 if (options.log) { 672 if (options.log) {
670 AnalysisEngine.instance.logger = new StdLogger(); 673 AnalysisEngine.instance.logger = new StdLogger();
671 } 674 }
672 675
673 // Prepare context options. 676 // Prepare context options.
674 AnalysisOptionsImpl contextOptions = 677 AnalysisOptionsImpl contextOptions =
675 createAnalysisOptionsForCommandLineOptions(options); 678 createAnalysisOptionsForCommandLineOptions(options);
676 configureContextOptions(contextOptions); 679 configureContextOptions(contextOptions);
677 680
678 // Set context options. 681 // Set context options.
679 context.analysisOptions = contextOptions; 682 context.analysisOptions = contextOptions;
680 683
681 // Process analysis options file (and notify all interested parties). 684 // Process analysis options file (and notify all interested parties).
682 _processAnalysisOptions(context, options); 685 _processAnalysisOptions(resourceProvider, context, options);
683 } 686 }
684 687
685 /// Perform a deep comparison of two string maps. 688 /// Perform a deep comparison of two string maps.
686 static bool _equalMaps(Map<String, String> m1, Map<String, String> m2) { 689 static bool _equalMaps(Map<String, String> m1, Map<String, String> m2) {
687 if (m1.length != m2.length) { 690 if (m1.length != m2.length) {
688 return false; 691 return false;
689 } 692 }
690 for (String key in m1.keys) { 693 for (String key in m1.keys) {
691 if (!m2.containsKey(key) || m1[key] != m2[key]) { 694 if (!m2.containsKey(key) || m1[key] != m2[key]) {
692 return false; 695 return false;
693 } 696 }
694 } 697 }
695 return true; 698 return true;
696 } 699 }
697 700
698 static file_system.File _getOptionsFile(CommandLineOptions options) { 701 static file_system.File _getOptionsFile(
702 file_system.ResourceProvider resourceProvider,
703 CommandLineOptions options) {
699 file_system.File file; 704 file_system.File file;
700 String filePath = options.analysisOptionsFile; 705 String filePath = options.analysisOptionsFile;
701 if (filePath != null) { 706 if (filePath != null) {
702 file = PhysicalResourceProvider.INSTANCE.getFile(filePath); 707 file = resourceProvider.getFile(filePath);
703 if (!file.exists) { 708 if (!file.exists) {
704 printAndFail('Options file not found: $filePath', 709 printAndFail('Options file not found: $filePath',
705 exitCode: ErrorSeverity.ERROR.ordinal); 710 exitCode: ErrorSeverity.ERROR.ordinal);
706 } 711 }
707 } else { 712 } else {
708 filePath = AnalysisEngine.ANALYSIS_OPTIONS_FILE; 713 filePath = AnalysisEngine.ANALYSIS_OPTIONS_FILE;
709 file = PhysicalResourceProvider.INSTANCE.getFile(filePath); 714 file = resourceProvider.getFile(filePath);
710 if (!file.exists) { 715 if (!file.exists) {
711 filePath = AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE; 716 filePath = AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE;
712 file = PhysicalResourceProvider.INSTANCE.getFile(filePath); 717 file = resourceProvider.getFile(filePath);
713 } 718 }
714 } 719 }
715 return file; 720 return file;
716 } 721 }
717 722
718 /// Convert [sourcePath] into an absolute path. 723 /// Convert [sourcePath] into an absolute path.
719 static String _normalizeSourcePath(String sourcePath) => 724 static String _normalizeSourcePath(String sourcePath) =>
720 path.normalize(new File(sourcePath).absolute.path); 725 path.normalize(new File(sourcePath).absolute.path);
721 726
722 static void _processAnalysisOptions( 727 static void _processAnalysisOptions(
723 AnalysisContext context, CommandLineOptions options) { 728 file_system.ResourceProvider resourceProvider,
724 file_system.File file = _getOptionsFile(options); 729 AnalysisContext context,
730 CommandLineOptions options) {
731 file_system.File file = _getOptionsFile(resourceProvider, options);
725 List<OptionsProcessor> optionsProcessors = 732 List<OptionsProcessor> optionsProcessors =
726 AnalysisEngine.instance.optionsPlugin.optionsProcessors; 733 AnalysisEngine.instance.optionsPlugin.optionsProcessors;
727 try { 734 try {
728 AnalysisOptionsProvider analysisOptionsProvider = 735 AnalysisOptionsProvider analysisOptionsProvider =
729 new AnalysisOptionsProvider(); 736 new AnalysisOptionsProvider();
730 Map<String, YamlNode> optionMap = 737 Map<String, YamlNode> optionMap =
731 analysisOptionsProvider.getOptionsFromFile(file); 738 analysisOptionsProvider.getOptionsFromFile(file);
732 optionsProcessors.forEach( 739 optionsProcessors.forEach(
733 (OptionsProcessor p) => p.optionsProcessed(context, optionMap)); 740 (OptionsProcessor p) => p.optionsProcessed(context, optionMap));
734 741
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 for (var package in packages) { 839 for (var package in packages) {
833 var packageName = path.basename(package.path); 840 var packageName = path.basename(package.path);
834 var realPath = package.resolveSymbolicLinksSync(); 841 var realPath = package.resolveSymbolicLinksSync();
835 result[packageName] = [ 842 result[packageName] = [
836 PhysicalResourceProvider.INSTANCE.getFolder(realPath) 843 PhysicalResourceProvider.INSTANCE.getFolder(realPath)
837 ]; 844 ];
838 } 845 }
839 return result; 846 return result;
840 } 847 }
841 } 848 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/lib/src/build_mode.dart ('k') | pkg/analyzer_cli/test/build_mode_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698