| 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'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 EmbedderUriResolver embedderUriResolver = | 345 EmbedderUriResolver embedderUriResolver = |
| 346 embeddedUriResolverProvider(folder); | 346 embeddedUriResolverProvider(folder); |
| 347 if (embedderUriResolver != null && embedderUriResolver.length != 0) { | 347 if (embedderUriResolver != null && embedderUriResolver.length != 0) { |
| 348 sdkResolver = embedderUriResolver; | 348 sdkResolver = embedderUriResolver; |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 | 351 |
| 352 // Default to a Dart URI resolver if no embedder is found. | 352 // Default to a Dart URI resolver if no embedder is found. |
| 353 sdkResolver ??= new DartUriResolver(sdk); | 353 sdkResolver ??= new DartUriResolver(sdk); |
| 354 | 354 |
| 355 // TODO(brianwilkerson) This doesn't sdk extensions. | 355 // TODO(brianwilkerson) This doesn't handle sdk extensions. |
| 356 List<UriResolver> resolvers = <UriResolver>[ | 356 List<UriResolver> resolvers = <UriResolver>[ |
| 357 sdkResolver, | 357 sdkResolver, |
| 358 resolver, | 358 resolver, |
| 359 new FileUriResolver() | 359 new FileUriResolver() |
| 360 ]; | 360 ]; |
| 361 return new SourceFactory(resolvers); | 361 return new SourceFactory(resolvers); |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 | 364 |
| 365 UriResolver packageUriResolver; | 365 UriResolver packageUriResolver; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy; | 488 contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy; |
| 489 }); | 489 }); |
| 490 | 490 |
| 491 // Find package info. | 491 // Find package info. |
| 492 _PackageInfo packageInfo = _findPackages(options); | 492 _PackageInfo packageInfo = _findPackages(options); |
| 493 | 493 |
| 494 // Process embedders. | 494 // Process embedders. |
| 495 Map<fileSystem.Folder, YamlMap> embedderMap = | 495 Map<fileSystem.Folder, YamlMap> embedderMap = |
| 496 _findEmbedders(packageInfo.packageMap); | 496 _findEmbedders(packageInfo.packageMap); |
| 497 | 497 |
| 498 // Scan for SDK extenders. |
| 499 bool hasSdkExt = _hasSdkExt(packageInfo.packageMap?.values); |
| 500 |
| 501 // No summaries in the presence of embedders or extenders. |
| 502 bool useSummaries = embedderMap.isEmpty && !hasSdkExt; |
| 503 |
| 498 // Once options and embedders are processed, setup the SDK. | 504 // Once options and embedders are processed, setup the SDK. |
| 499 _setupSdk(options, embedderMap.isNotEmpty); | 505 _setupSdk(options, useSummaries); |
| 500 | 506 |
| 501 // Choose a package resolution policy and a diet parsing policy based on | 507 // Choose a package resolution policy and a diet parsing policy based on |
| 502 // the command-line options. | 508 // the command-line options. |
| 503 SourceFactory sourceFactory = | 509 SourceFactory sourceFactory = |
| 504 _chooseUriResolutionPolicy(options, embedderMap, packageInfo); | 510 _chooseUriResolutionPolicy(options, embedderMap, packageInfo); |
| 505 | 511 |
| 506 _context.sourceFactory = sourceFactory; | 512 _context.sourceFactory = sourceFactory; |
| 507 } | 513 } |
| 508 | 514 |
| 509 /// Return discovered packagespec, or `null` if none is found. | 515 /// Return discovered packagespec, or `null` if none is found. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 Map<String, List<fileSystem.Folder>> folderMap = | 578 Map<String, List<fileSystem.Folder>> folderMap = |
| 573 new Map<String, List<fileSystem.Folder>>(); | 579 new Map<String, List<fileSystem.Folder>>(); |
| 574 packages.asMap().forEach((String packagePath, Uri uri) { | 580 packages.asMap().forEach((String packagePath, Uri uri) { |
| 575 folderMap[packagePath] = [ | 581 folderMap[packagePath] = [ |
| 576 PhysicalResourceProvider.INSTANCE.getFolder(path.fromUri(uri)) | 582 PhysicalResourceProvider.INSTANCE.getFolder(path.fromUri(uri)) |
| 577 ]; | 583 ]; |
| 578 }); | 584 }); |
| 579 return folderMap; | 585 return folderMap; |
| 580 } | 586 } |
| 581 | 587 |
| 588 bool _hasSdkExt(Iterable<List<fileSystem.Folder>> folders) { |
| 589 if (folders != null) { |
| 590 //TODO: ideally share this traversal with SdkExtUriResolver |
| 591 for (Iterable<fileSystem.Folder> libDirs in folders) { |
| 592 if (libDirs.any((fileSystem.Folder libDir) => |
| 593 libDir |
| 594 .getChild(SdkExtUriResolver.SDK_EXT_NAME) |
| 595 .exists)) { |
| 596 return true; |
| 597 } |
| 598 } |
| 599 } |
| 600 return false; |
| 601 } |
| 602 |
| 582 /// Returns `true` if this relative path is a hidden directory. | 603 /// Returns `true` if this relative path is a hidden directory. |
| 583 bool _isInHiddenDir(String relative) => | 604 bool _isInHiddenDir(String relative) => |
| 584 path.split(relative).any((part) => part.startsWith(".")); | 605 path.split(relative).any((part) => part.startsWith(".")); |
| 585 | 606 |
| 586 void _processPlugins() { | 607 void _processPlugins() { |
| 587 List<Plugin> plugins = <Plugin>[]; | 608 List<Plugin> plugins = <Plugin>[]; |
| 588 plugins.addAll(AnalysisEngine.instance.requiredPlugins); | 609 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
| 589 plugins.add(AnalysisEngine.instance.commandLinePlugin); | 610 plugins.add(AnalysisEngine.instance.commandLinePlugin); |
| 590 plugins.add(AnalysisEngine.instance.optionsPlugin); | 611 plugins.add(AnalysisEngine.instance.optionsPlugin); |
| 591 plugins.add(linterPlugin); | 612 plugins.add(linterPlugin); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 603 var errorSeverity = analyzer.analyzeSync(); | 624 var errorSeverity = analyzer.analyzeSync(); |
| 604 if (errorSeverity == ErrorSeverity.ERROR) { | 625 if (errorSeverity == ErrorSeverity.ERROR) { |
| 605 exitCode = errorSeverity.ordinal; | 626 exitCode = errorSeverity.ordinal; |
| 606 } | 627 } |
| 607 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { | 628 if (options.warningsAreFatal && errorSeverity == ErrorSeverity.WARNING) { |
| 608 exitCode = errorSeverity.ordinal; | 629 exitCode = errorSeverity.ordinal; |
| 609 } | 630 } |
| 610 return errorSeverity; | 631 return errorSeverity; |
| 611 } | 632 } |
| 612 | 633 |
| 613 void _setupSdk(CommandLineOptions options, bool hasEmbedder) { | 634 void _setupSdk(CommandLineOptions options, bool useSummaries) { |
| 614 if (sdk == null) { | 635 if (sdk == null) { |
| 615 if (options.dartSdkSummaryPath != null) { | 636 if (options.dartSdkSummaryPath != null) { |
| 616 sdk = new SummaryBasedDartSdk( | 637 sdk = new SummaryBasedDartSdk( |
| 617 options.dartSdkSummaryPath, options.strongMode); | 638 options.dartSdkSummaryPath, options.strongMode); |
| 618 } else { | 639 } else { |
| 619 String dartSdkPath = options.dartSdkPath; | 640 String dartSdkPath = options.dartSdkPath; |
| 620 DirectoryBasedDartSdk directorySdk = | 641 DirectoryBasedDartSdk directorySdk = |
| 621 new DirectoryBasedDartSdk(new JavaFile(dartSdkPath)); | 642 new DirectoryBasedDartSdk(new JavaFile(dartSdkPath)); |
| 622 // Summaries are disabled in the presence of embedders. | 643 directorySdk.useSummary = useSummaries && |
| 623 if (hasEmbedder) { | 644 options.sourceFiles.every((String sourcePath) { |
| 624 directorySdk.useSummary = false; | 645 sourcePath = path.absolute(sourcePath); |
| 625 } else { | 646 sourcePath = path.normalize(sourcePath); |
| 626 directorySdk.useSummary = | 647 return !path.isWithin(dartSdkPath, sourcePath); |
| 627 options.sourceFiles.every((String sourcePath) { | 648 }); |
| 628 sourcePath = path.absolute(sourcePath); | 649 |
| 629 sourcePath = path.normalize(sourcePath); | |
| 630 return !path.isWithin(dartSdkPath, sourcePath); | |
| 631 }); | |
| 632 } | |
| 633 directorySdk.analysisOptions = context.analysisOptions; | 650 directorySdk.analysisOptions = context.analysisOptions; |
| 634 sdk = directorySdk; | 651 sdk = directorySdk; |
| 635 } | 652 } |
| 636 } | 653 } |
| 637 } | 654 } |
| 638 | 655 |
| 639 static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( | 656 static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( |
| 640 CommandLineOptions options) { | 657 CommandLineOptions options) { |
| 641 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); | 658 AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl(); |
| 642 contextOptions.hint = !options.disableHints; | 659 contextOptions.hint = !options.disableHints; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 for (var package in packages) { | 847 for (var package in packages) { |
| 831 var packageName = path.basename(package.path); | 848 var packageName = path.basename(package.path); |
| 832 var realPath = package.resolveSymbolicLinksSync(); | 849 var realPath = package.resolveSymbolicLinksSync(); |
| 833 result[packageName] = [ | 850 result[packageName] = [ |
| 834 PhysicalResourceProvider.INSTANCE.getFolder(realPath) | 851 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 835 ]; | 852 ]; |
| 836 } | 853 } |
| 837 return result; | 854 return result; |
| 838 } | 855 } |
| 839 } | 856 } |
| OLD | NEW |