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

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

Issue 2541933002: update analyzer cli to support include directive in analysis options file (Closed)
Patch Set: merge Created 4 years 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
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' as io; 9 import 'dart:io' as io;
10 10
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 _previousOptions = options; 484 _previousOptions = options;
485 485
486 // Save stats from previous context before clobbering it. 486 // Save stats from previous context before clobbering it.
487 if (_context != null) { 487 if (_context != null) {
488 _analyzedFileCount += _context.sources.length; 488 _analyzedFileCount += _context.sources.length;
489 } 489 }
490 490
491 // Create a context. 491 // Create a context.
492 _context = AnalysisEngine.instance.createAnalysisContext(); 492 _context = AnalysisEngine.instance.createAnalysisContext();
493 493
494 AnalyzeFunctionBodiesPredicate dietParsingPolicy =
495 _chooseDietParsingPolicy(options);
496 setAnalysisContextOptions(resourceProvider, _context, options,
497 (AnalysisOptionsImpl contextOptions) {
498 contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy;
499 });
500
501 // Find package info. 494 // Find package info.
502 _PackageInfo packageInfo = _findPackages(options); 495 _PackageInfo packageInfo = _findPackages(options);
503 496
504 // Process embedders. 497 // Process embedders.
505 Map<file_system.Folder, YamlMap> embedderMap = 498 Map<file_system.Folder, YamlMap> embedderMap =
506 new EmbedderYamlLocator(packageInfo.packageMap).embedderYamls; 499 new EmbedderYamlLocator(packageInfo.packageMap).embedderYamls;
507 500
508 // Scan for SDK extenders. 501 // Scan for SDK extenders.
509 bool hasSdkExt = _hasSdkExt(packageInfo.packageMap?.values); 502 bool hasSdkExt = _hasSdkExt(packageInfo.packageMap?.values);
510 503
(...skipping 10 matching lines...) Expand all
521 useSummaries ? options.buildSummaryInputs : <String>[]); 514 useSummaries ? options.buildSummaryInputs : <String>[]);
522 515
523 // Once options and embedders are processed, setup the SDK. 516 // Once options and embedders are processed, setup the SDK.
524 _setupSdk(options, useSummaries); 517 _setupSdk(options, useSummaries);
525 518
526 // Choose a package resolution policy and a diet parsing policy based on 519 // Choose a package resolution policy and a diet parsing policy based on
527 // the command-line options. 520 // the command-line options.
528 SourceFactory sourceFactory = _chooseUriResolutionPolicy( 521 SourceFactory sourceFactory = _chooseUriResolutionPolicy(
529 options, embedderMap, packageInfo, summaryDataStore); 522 options, embedderMap, packageInfo, summaryDataStore);
530 523
524 AnalyzeFunctionBodiesPredicate dietParsingPolicy =
525 _chooseDietParsingPolicy(options);
526 setAnalysisContextOptions(
527 resourceProvider, sourceFactory, _context, options,
528 (AnalysisOptionsImpl contextOptions) {
529 contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy;
530 });
531
531 _context.sourceFactory = sourceFactory; 532 _context.sourceFactory = sourceFactory;
532 _context.resultProvider = 533 _context.resultProvider =
533 new InputPackagesResultProvider(_context, summaryDataStore); 534 new InputPackagesResultProvider(_context, summaryDataStore);
534 } 535 }
535 536
536 /// Return discovered packagespec, or `null` if none is found. 537 /// Return discovered packagespec, or `null` if none is found.
537 Packages _discoverPackagespec(Uri root) { 538 Packages _discoverPackagespec(Uri root) {
538 try { 539 try {
539 Packages packages = pkg_discovery.findPackagesFromFile(root); 540 Packages packages = pkg_discovery.findPackagesFromFile(root);
540 if (packages != Packages.noPackages) { 541 if (packages != Packages.noPackages) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 contextOptions.generateSdkErrors = options.showSdkWarnings; 674 contextOptions.generateSdkErrors = options.showSdkWarnings;
674 contextOptions.lint = options.lints; 675 contextOptions.lint = options.lints;
675 contextOptions.strongMode = options.strongMode; 676 contextOptions.strongMode = options.strongMode;
676 contextOptions.implicitCasts = options.implicitCasts; 677 contextOptions.implicitCasts = options.implicitCasts;
677 contextOptions.implicitDynamic = options.implicitDynamic; 678 contextOptions.implicitDynamic = options.implicitDynamic;
678 return contextOptions; 679 return contextOptions;
679 } 680 }
680 681
681 static void setAnalysisContextOptions( 682 static void setAnalysisContextOptions(
682 file_system.ResourceProvider resourceProvider, 683 file_system.ResourceProvider resourceProvider,
684 SourceFactory sourceFactory,
683 AnalysisContext context, 685 AnalysisContext context,
684 CommandLineOptions options, 686 CommandLineOptions options,
685 void configureContextOptions(AnalysisOptionsImpl contextOptions)) { 687 void configureContextOptions(AnalysisOptionsImpl contextOptions)) {
686 Map<String, String> definedVariables = options.definedVariables; 688 Map<String, String> definedVariables = options.definedVariables;
687 if (definedVariables.isNotEmpty) { 689 if (definedVariables.isNotEmpty) {
688 DeclaredVariables declaredVariables = context.declaredVariables; 690 DeclaredVariables declaredVariables = context.declaredVariables;
689 definedVariables.forEach((String variableName, String value) { 691 definedVariables.forEach((String variableName, String value) {
690 declaredVariables.define(variableName, value); 692 declaredVariables.define(variableName, value);
691 }); 693 });
692 } 694 }
693 695
694 if (options.log) { 696 if (options.log) {
695 AnalysisEngine.instance.logger = new StdLogger(); 697 AnalysisEngine.instance.logger = new StdLogger();
696 } 698 }
697 699
698 // Prepare context options. 700 // Prepare context options.
699 AnalysisOptionsImpl contextOptions = 701 AnalysisOptionsImpl contextOptions =
700 createAnalysisOptionsForCommandLineOptions(options); 702 createAnalysisOptionsForCommandLineOptions(options);
701 configureContextOptions(contextOptions); 703 configureContextOptions(contextOptions);
702 704
703 // Set context options. 705 // Set context options.
704 context.analysisOptions = contextOptions; 706 context.analysisOptions = contextOptions;
705 707
706 // Process analysis options file (and notify all interested parties). 708 // Process analysis options file (and notify all interested parties).
707 _processAnalysisOptions(resourceProvider, context, options); 709 _processAnalysisOptions(resourceProvider, sourceFactory, context, options);
708 } 710 }
709 711
710 /// Perform a deep comparison of two string lists. 712 /// Perform a deep comparison of two string lists.
711 static bool _equalLists(List<String> l1, List<String> l2) { 713 static bool _equalLists(List<String> l1, List<String> l2) {
712 if (l1.length != l2.length) { 714 if (l1.length != l2.length) {
713 return false; 715 return false;
714 } 716 }
715 for (int i = 0; i < l1.length; i++) { 717 for (int i = 0; i < l1.length; i++) {
716 if (l1[i] != l2[i]) { 718 if (l1[i] != l2[i]) {
717 return false; 719 return false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 } 756 }
755 return file; 757 return file;
756 } 758 }
757 759
758 /// Convert [sourcePath] into an absolute path. 760 /// Convert [sourcePath] into an absolute path.
759 static String _normalizeSourcePath(String sourcePath) => 761 static String _normalizeSourcePath(String sourcePath) =>
760 path.normalize(new io.File(sourcePath).absolute.path); 762 path.normalize(new io.File(sourcePath).absolute.path);
761 763
762 static void _processAnalysisOptions( 764 static void _processAnalysisOptions(
763 file_system.ResourceProvider resourceProvider, 765 file_system.ResourceProvider resourceProvider,
766 SourceFactory sourceFactory,
764 AnalysisContext context, 767 AnalysisContext context,
765 CommandLineOptions options) { 768 CommandLineOptions options) {
766 file_system.File file = _getOptionsFile(resourceProvider, options); 769 file_system.File file = _getOptionsFile(resourceProvider, options);
767 List<OptionsProcessor> optionsProcessors = 770 List<OptionsProcessor> optionsProcessors =
768 AnalysisEngine.instance.optionsPlugin.optionsProcessors; 771 AnalysisEngine.instance.optionsPlugin.optionsProcessors;
772
769 try { 773 try {
770 AnalysisOptionsProvider analysisOptionsProvider = 774 AnalysisOptionsProvider analysisOptionsProvider =
771 new AnalysisOptionsProvider(); 775 new AnalysisOptionsProvider(sourceFactory);
772 Map<String, YamlNode> optionMap = 776 Map<String, YamlNode> optionMap =
773 analysisOptionsProvider.getOptionsFromFile(file); 777 analysisOptionsProvider.getOptionsFromFile(file);
774 optionsProcessors.forEach( 778 optionsProcessors.forEach(
775 (OptionsProcessor p) => p.optionsProcessed(context, optionMap)); 779 (OptionsProcessor p) => p.optionsProcessed(context, optionMap));
776 780
777 // Fill in lint rule defaults in case lints are enabled and rules are 781 // Fill in lint rule defaults in case lints are enabled and rules are
778 // not specified in an options file. 782 // not specified in an options file.
779 if (options.lints && !containsLintRuleEntry(optionMap)) { 783 if (options.lints && !containsLintRuleEntry(optionMap)) {
780 setLints(context, linterPlugin.contributedRules); 784 setLints(context, linterPlugin.contributedRules);
781 } 785 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 for (var package in packages) { 878 for (var package in packages) {
875 var packageName = path.basename(package.path); 879 var packageName = path.basename(package.path);
876 var realPath = package.resolveSymbolicLinksSync(); 880 var realPath = package.resolveSymbolicLinksSync();
877 result[packageName] = [ 881 result[packageName] = [
878 PhysicalResourceProvider.INSTANCE.getFolder(realPath) 882 PhysicalResourceProvider.INSTANCE.getFolder(realPath)
879 ]; 883 ];
880 } 884 }
881 return result; 885 return result;
882 } 886 }
883 } 887 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698