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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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: null, | 54 this.packageRoot: null, |
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 factory AnalyzerOptions.fromArguments(ArgResults args) { |
59 : summaryPaths = args['summary'] as List<String>, | 59 var sdkPath = args['dart-sdk'] ?? getSdkDir().path; |
60 dartSdkPath = args['dart-sdk'] ?? getSdkDir().path, | 60 var sdkSummaryPath = args['dart-sdk-summary']; |
61 dartSdkSummaryPath = args['dart-sdk-summary'], | 61 |
62 customUrlMappings = _parseUrlMappings(args['url-mapping']), | 62 if (sdkSummaryPath == null) { |
63 packageRoot = args['package-root'], | 63 sdkSummaryPath = path.join(sdkPath, 'lib', '_internal', 'ddc_sdk.sum'); |
64 packagePaths = (args['package-paths'] as String)?.split(',') ?? []; | 64 } else if (sdkSummaryPath == 'build') { |
| 65 // For building the SDK, we explicitly set the path to none. |
| 66 sdkSummaryPath = null; |
| 67 } |
| 68 |
| 69 return new AnalyzerOptions( |
| 70 summaryPaths: args['summary'] as List<String>, |
| 71 dartSdkPath: sdkPath, |
| 72 dartSdkSummaryPath: sdkSummaryPath, |
| 73 customUrlMappings: _parseUrlMappings(args['url-mapping']), |
| 74 packageRoot: args['package-root'], |
| 75 packagePaths: (args['package-paths'] as String)?.split(',') ?? []); |
| 76 } |
65 | 77 |
66 /// Whether to resolve 'package:' uris using the multi-package resolver. | 78 /// Whether to resolve 'package:' uris using the multi-package resolver. |
67 bool get useMultiPackage => packagePaths.isNotEmpty; | 79 bool get useMultiPackage => packagePaths.isNotEmpty; |
68 | 80 |
69 static void addArguments(ArgParser parser) { | 81 static void addArguments(ArgParser parser) { |
70 parser | 82 parser |
71 ..addOption('summary', | 83 ..addOption('summary', |
72 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) | 84 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) |
73 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) | 85 ..addOption('dart-sdk', |
| 86 help: 'Dart SDK Path', defaultsTo: null, hide: true) |
74 ..addOption('dart-sdk-summary', | 87 ..addOption('dart-sdk-summary', |
75 help: 'Dart SDK Summary Path', defaultsTo: null) | 88 help: 'Dart SDK Summary Path', defaultsTo: null, hide: true) |
76 ..addOption('package-root', | 89 ..addOption('package-root', |
77 abbr: 'p', help: 'Package root to resolve "package:" imports') | 90 abbr: 'p', help: 'Package root to resolve "package:" imports') |
78 ..addOption('url-mapping', | 91 ..addOption('url-mapping', |
79 help: '--url-mapping=libraryUri,/path/to/library.dart uses\n' | 92 help: '--url-mapping=libraryUri,/path/to/library.dart uses\n' |
80 'library.dart as the source for an import of of "libraryUri".', | 93 'library.dart as the source for an import of of "libraryUri".', |
81 allowMultiple: true, | 94 allowMultiple: true, |
82 splitCommas: false) | 95 splitCommas: false) |
83 ..addOption('package-paths', | 96 ..addOption('package-paths', |
84 help: 'use a list of directories to resolve "package:" imports'); | 97 help: 'use a list of directories to resolve "package:" imports'); |
85 } | 98 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return sdk; | 179 return sdk; |
167 } | 180 } |
168 | 181 |
169 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. | 182 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. |
170 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { | 183 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { |
171 var sdk = (sdkSummaryPath != null) | 184 var sdk = (sdkSummaryPath != null) |
172 ? new SummaryBasedDartSdk(sdkSummaryPath, true) | 185 ? new SummaryBasedDartSdk(sdkSummaryPath, true) |
173 : _createFolderBasedDartSdk(sdkPath); | 186 : _createFolderBasedDartSdk(sdkPath); |
174 return new DartUriResolver(sdk); | 187 return new DartUriResolver(sdk); |
175 } | 188 } |
OLD | NEW |