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 import 'package:args/args.dart' show ArgParser, ArgResults; | 5 import 'package:args/args.dart' show ArgParser, ArgResults; |
| 6 import 'package:analyzer/file_system/file_system.dart' | 6 import 'package:analyzer/file_system/file_system.dart' |
| 7 show ResourceProvider, ResourceUriResolver; | 7 show ResourceProvider, ResourceUriResolver; |
| 8 import 'package:analyzer/file_system/physical_file_system.dart' | 8 import 'package:analyzer/file_system/physical_file_system.dart' |
| 9 show PhysicalResourceProvider; | 9 show PhysicalResourceProvider; |
| 10 import 'package:analyzer/source/custom_resolver.dart'; | 10 import 'package:analyzer/source/custom_resolver.dart'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 | 44 |
| 45 /// Path to the dart-sdk summary. If this is set, it will be used in favor | 45 /// Path to the dart-sdk summary. If this is set, it will be used in favor |
| 46 /// of the unsummarized one. | 46 /// of the unsummarized one. |
| 47 final String dartSdkSummaryPath; | 47 final String dartSdkSummaryPath; |
| 48 | 48 |
| 49 AnalyzerOptions( | 49 AnalyzerOptions( |
| 50 {this.summaryPaths: const [], | 50 {this.summaryPaths: const [], |
| 51 String dartSdkPath, | 51 String dartSdkPath, |
| 52 this.dartSdkSummaryPath, | 52 this.dartSdkSummaryPath, |
| 53 this.customUrlMappings: const {}, | 53 this.customUrlMappings: const {}, |
| 54 this.packageRoot: 'packages/', | 54 this.packageRoot: null, |
|
Bob Nystrom
2016/09/28 16:02:47
You should be able to just omit this argument, rig
vsm
2016/09/28 16:10:03
Good point. Looking into whether I can just remov
| |
| 55 this.packagePaths: const []}) | 55 this.packagePaths: const []}) |
| 56 : dartSdkPath = dartSdkPath ?? getSdkDir().path; | 56 : dartSdkPath = dartSdkPath ?? getSdkDir().path; |
| 57 | 57 |
| 58 AnalyzerOptions.fromArguments(ArgResults args) | 58 AnalyzerOptions.fromArguments(ArgResults args) |
| 59 : summaryPaths = args['summary'] as List<String>, | 59 : summaryPaths = args['summary'] as List<String>, |
| 60 dartSdkPath = args['dart-sdk'] ?? getSdkDir().path, | 60 dartSdkPath = args['dart-sdk'] ?? getSdkDir().path, |
| 61 dartSdkSummaryPath = args['dart-sdk-summary'], | 61 dartSdkSummaryPath = args['dart-sdk-summary'], |
| 62 customUrlMappings = _parseUrlMappings(args['url-mapping']), | 62 customUrlMappings = _parseUrlMappings(args['url-mapping']), |
| 63 packageRoot = args['package-root'], | 63 packageRoot = args['package-root'], |
| 64 packagePaths = (args['package-paths'] as String)?.split(',') ?? []; | 64 packagePaths = (args['package-paths'] as String)?.split(',') ?? []; |
| 65 | 65 |
| 66 /// Whether to resolve 'package:' uris using the multi-package resolver. | 66 /// Whether to resolve 'package:' uris using the multi-package resolver. |
| 67 bool get useMultiPackage => packagePaths.isNotEmpty; | 67 bool get useMultiPackage => packagePaths.isNotEmpty; |
| 68 | 68 |
| 69 static void addArguments(ArgParser parser) { | 69 static void addArguments(ArgParser parser) { |
| 70 parser | 70 parser |
| 71 ..addOption('summary', | 71 ..addOption('summary', |
| 72 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) | 72 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) |
| 73 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) | 73 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) |
| 74 ..addOption('dart-sdk-summary', | 74 ..addOption('dart-sdk-summary', |
| 75 help: 'Dart SDK Summary Path', defaultsTo: null) | 75 help: 'Dart SDK Summary Path', defaultsTo: null) |
| 76 ..addOption('package-root', | 76 ..addOption('package-root', |
| 77 abbr: 'p', | 77 abbr: 'p', help: 'Package root to resolve "package:" imports') |
| 78 help: 'Package root to resolve "package:" imports', | |
| 79 defaultsTo: 'packages/') | |
| 80 ..addOption('url-mapping', | 78 ..addOption('url-mapping', |
| 81 help: '--url-mapping=libraryUri,/path/to/library.dart uses\n' | 79 help: '--url-mapping=libraryUri,/path/to/library.dart uses\n' |
| 82 'library.dart as the source for an import of of "libraryUri".', | 80 'library.dart as the source for an import of of "libraryUri".', |
| 83 allowMultiple: true, | 81 allowMultiple: true, |
| 84 splitCommas: false) | 82 splitCommas: false) |
| 85 ..addOption('package-paths', | 83 ..addOption('package-paths', |
| 86 help: 'use a list of directories to resolve "package:" imports'); | 84 help: 'use a list of directories to resolve "package:" imports'); |
| 87 } | 85 } |
| 88 | 86 |
| 89 static Map<String, String> _parseUrlMappings(Iterable argument) { | 87 static Map<String, String> _parseUrlMappings(Iterable argument) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 createFileResolvers(options, resourceProvider: resourceProvider); | 133 createFileResolvers(options, resourceProvider: resourceProvider); |
| 136 resolvers.addAll(fileResolvers); | 134 resolvers.addAll(fileResolvers); |
| 137 return new SourceFactory(resolvers, null, resourceProvider); | 135 return new SourceFactory(resolvers, null, resourceProvider); |
| 138 } | 136 } |
| 139 | 137 |
| 140 List<UriResolver> createFileResolvers(AnalyzerOptions options, | 138 List<UriResolver> createFileResolvers(AnalyzerOptions options, |
| 141 {ResourceProvider resourceProvider}) { | 139 {ResourceProvider resourceProvider}) { |
| 142 resourceProvider ??= PhysicalResourceProvider.INSTANCE; | 140 resourceProvider ??= PhysicalResourceProvider.INSTANCE; |
| 143 UriResolver packageResolver() { | 141 UriResolver packageResolver() { |
| 144 ContextBuilder builder = new ContextBuilder(resourceProvider, null, null); | 142 ContextBuilder builder = new ContextBuilder(resourceProvider, null, null); |
| 145 builder.defaultPackagesDirectoryPath = options.packageRoot; | 143 if (options.packageRoot != null) { |
| 144 builder.defaultPackagesDirectoryPath = options.packageRoot; | |
| 145 } | |
| 146 return new PackageMapUriResolver(resourceProvider, | 146 return new PackageMapUriResolver(resourceProvider, |
| 147 builder.convertPackagesToMap(builder.createPackageMap(''))); | 147 builder.convertPackagesToMap(builder.createPackageMap(''))); |
| 148 } | 148 } |
| 149 | 149 |
| 150 return [ | 150 return [ |
| 151 new ResourceUriResolver(resourceProvider), | 151 new ResourceUriResolver(resourceProvider), |
| 152 options.useMultiPackage | 152 options.useMultiPackage |
| 153 ? new MultiPackageResolver(options.packagePaths) | 153 ? new MultiPackageResolver(options.packagePaths) |
| 154 : packageResolver() | 154 : packageResolver() |
| 155 ]; | 155 ]; |
| 156 } | 156 } |
| 157 | 157 |
| 158 FolderBasedDartSdk _createFolderBasedDartSdk(String sdkPath) { | 158 FolderBasedDartSdk _createFolderBasedDartSdk(String sdkPath) { |
| 159 var resourceProvider = PhysicalResourceProvider.INSTANCE; | 159 var resourceProvider = PhysicalResourceProvider.INSTANCE; |
| 160 var sdk = new FolderBasedDartSdk(resourceProvider, | 160 var sdk = new FolderBasedDartSdk(resourceProvider, |
| 161 resourceProvider.getFolder(sdkPath), /*useDart2jsPaths:*/ true); | 161 resourceProvider.getFolder(sdkPath), /*useDart2jsPaths:*/ true); |
| 162 sdk.useSummary = true; | 162 sdk.useSummary = true; |
| 163 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = true; | 163 sdk.analysisOptions = new AnalysisOptionsImpl()..strongMode = true; |
| 164 return sdk; | 164 return sdk; |
| 165 } | 165 } |
| 166 | 166 |
| 167 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. | 167 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. |
| 168 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { | 168 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { |
| 169 var sdk = (sdkSummaryPath != null) | 169 var sdk = (sdkSummaryPath != null) |
| 170 ? new SummaryBasedDartSdk(sdkSummaryPath, true) | 170 ? new SummaryBasedDartSdk(sdkSummaryPath, true) |
| 171 : _createFolderBasedDartSdk(sdkPath); | 171 : _createFolderBasedDartSdk(sdkPath); |
| 172 return new DartUriResolver(sdk); | 172 return new DartUriResolver(sdk); |
| 173 } | 173 } |
| OLD | NEW |