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 28 matching lines...) Expand all Loading... |
39 final List<String> packagePaths; | 39 final List<String> packagePaths; |
40 | 40 |
41 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't | 41 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't |
42 /// be determined | 42 /// be determined |
43 final String dartSdkPath; | 43 final String dartSdkPath; |
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 /// Defined variables used by `bool.fromEnvironment` etc. |
| 50 final Map<String, String> declaredVariables; |
| 51 |
49 AnalyzerOptions( | 52 AnalyzerOptions( |
50 {this.summaryPaths: const [], | 53 {this.summaryPaths: const [], |
51 String dartSdkPath, | 54 String dartSdkPath, |
52 this.dartSdkSummaryPath, | 55 this.dartSdkSummaryPath, |
53 this.customUrlMappings: const {}, | 56 this.customUrlMappings: const {}, |
54 this.packageRoot: null, | 57 this.packageRoot: null, |
55 this.packagePaths: const []}) | 58 this.packagePaths: const [], |
| 59 this.declaredVariables: const {}}) |
56 : dartSdkPath = dartSdkPath ?? getSdkDir().path; | 60 : dartSdkPath = dartSdkPath ?? getSdkDir().path; |
57 | 61 |
58 factory AnalyzerOptions.fromArguments(ArgResults args) { | 62 factory AnalyzerOptions.fromArguments( |
| 63 ArgResults args, Map<String, String> declaredVariables) { |
59 var sdkPath = args['dart-sdk'] ?? getSdkDir().path; | 64 var sdkPath = args['dart-sdk'] ?? getSdkDir().path; |
60 var sdkSummaryPath = args['dart-sdk-summary']; | 65 var sdkSummaryPath = args['dart-sdk-summary']; |
61 | 66 |
62 if (sdkSummaryPath == null) { | 67 if (sdkSummaryPath == null) { |
63 sdkSummaryPath = path.join(sdkPath, 'lib', '_internal', 'ddc_sdk.sum'); | 68 sdkSummaryPath = path.join(sdkPath, 'lib', '_internal', 'ddc_sdk.sum'); |
64 } else if (sdkSummaryPath == 'build') { | 69 } else if (sdkSummaryPath == 'build') { |
65 // For building the SDK, we explicitly set the path to none. | 70 // For building the SDK, we explicitly set the path to none. |
66 sdkSummaryPath = null; | 71 sdkSummaryPath = null; |
67 } | 72 } |
68 | 73 |
69 return new AnalyzerOptions( | 74 return new AnalyzerOptions( |
70 summaryPaths: args['summary'] as List<String>, | 75 summaryPaths: args['summary'] as List<String>, |
71 dartSdkPath: sdkPath, | 76 dartSdkPath: sdkPath, |
72 dartSdkSummaryPath: sdkSummaryPath, | 77 dartSdkSummaryPath: sdkSummaryPath, |
73 customUrlMappings: _parseUrlMappings(args['url-mapping']), | 78 customUrlMappings: _parseUrlMappings(args['url-mapping']), |
74 packageRoot: args['package-root'], | 79 packageRoot: args['package-root'], |
75 packagePaths: (args['package-paths'] as String)?.split(',') ?? []); | 80 packagePaths: (args['package-paths'] as String)?.split(',') ?? [], |
| 81 declaredVariables: declaredVariables); |
76 } | 82 } |
77 | 83 |
78 /// Whether to resolve 'package:' uris using the multi-package resolver. | 84 /// Whether to resolve 'package:' uris using the multi-package resolver. |
79 bool get useMultiPackage => packagePaths.isNotEmpty; | 85 bool get useMultiPackage => packagePaths.isNotEmpty; |
80 | 86 |
81 static void addArguments(ArgParser parser) { | 87 static void addArguments(ArgParser parser) { |
82 parser | 88 parser |
83 ..addOption('summary', | 89 ..addOption('summary', |
84 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) | 90 abbr: 's', help: 'summary file(s) to include', allowMultiple: true) |
85 ..addOption('dart-sdk', | 91 ..addOption('dart-sdk', |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 return sdk; | 185 return sdk; |
180 } | 186 } |
181 | 187 |
182 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. | 188 /// Creates a [DartUriResolver] that uses the SDK at the given [sdkPath]. |
183 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { | 189 DartUriResolver createSdkPathResolver(String sdkSummaryPath, String sdkPath) { |
184 var sdk = (sdkSummaryPath != null) | 190 var sdk = (sdkSummaryPath != null) |
185 ? new SummaryBasedDartSdk(sdkSummaryPath, true) | 191 ? new SummaryBasedDartSdk(sdkSummaryPath, true) |
186 : _createFolderBasedDartSdk(sdkPath); | 192 : _createFolderBasedDartSdk(sdkPath); |
187 return new DartUriResolver(sdk); | 193 return new DartUriResolver(sdk); |
188 } | 194 } |
| 195 |
| 196 List<String> parseDeclaredVariables( |
| 197 List<String> args, Map<String, String> declaredVars) { |
| 198 var count = args.length; |
| 199 var remainingArgs = <String>[]; |
| 200 for (int i = 0; i < count; i++) { |
| 201 var arg = args[i]; |
| 202 if (arg == '--') { |
| 203 while (i < count) { |
| 204 remainingArgs.add(args[i++]); |
| 205 } |
| 206 } else if (arg.startsWith("-D")) { |
| 207 // The format for defined variables is: |
| 208 // -D<name>=<value> |
| 209 var parts = arg.substring(2).split('='); |
| 210 declaredVars[parts[0]] = parts.length > 1 ? parts[1] : ''; |
| 211 } else { |
| 212 remainingArgs.add(arg); |
| 213 } |
| 214 } |
| 215 return remainingArgs; |
| 216 } |
OLD | NEW |