OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Set of flags and options passed to the compiler | 5 /// Set of flags and options passed to the compiler |
6 library dev_compiler.src.options; | 6 library dev_compiler.src.options; |
7 | 7 |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
11 import 'package:cli_util/cli_util.dart' show getSdkDir; | 11 import 'package:cli_util/cli_util.dart' show getSdkDir; |
12 import 'package:dev_compiler/config.dart'; | 12 import 'package:dev_compiler/config.dart'; |
13 import 'package:logging/logging.dart' show Level; | 13 import 'package:logging/logging.dart' show Level; |
14 import 'package:path/path.dart' as path; | 14 import 'package:path/path.dart' as path; |
15 import 'package:yaml/yaml.dart'; | 15 import 'package:yaml/yaml.dart'; |
16 | 16 |
17 /// Options used by our checker. | 17 /// Options used by our checker. |
18 // TODO(jmesserly): move useMultiPackage/packageRoot to CompilerOptions. | 18 // TODO(jmesserly): move useMultiPackage/packageRoot to CompilerOptions. |
19 class ResolverOptions { | 19 class ResolverOptions { |
20 /// Whether to resolve 'package:' uris using the multi-package resolver. | 20 /// Whether to resolve 'package:' uris using the multi-package resolver. |
21 final bool useMultiPackage; | 21 final bool useMultiPackage; |
22 | 22 |
23 /// Package root when resolving 'package:' urls the standard way. | 23 /// Package root when resolving 'package:' urls the standard way. |
24 final String packageRoot; | 24 final String packageRoot; |
25 | 25 |
26 /// List of paths used for the multi-package resolver. | 26 /// List of paths used for the multi-package resolver. |
27 final List<String> packagePaths; | 27 final List<String> packagePaths; |
28 | 28 |
| 29 /// List of additional non-Dart resources to resolve and serve. |
| 30 final List<String> resources; |
| 31 |
29 /// Whether to infer return types and field types from overriden members. | 32 /// Whether to infer return types and field types from overriden members. |
30 final bool inferFromOverrides; | 33 final bool inferFromOverrides; |
31 static const inferFromOverridesDefault = true; | 34 static const inferFromOverridesDefault = true; |
32 | 35 |
33 /// Whether to infer types for consts and fields by looking at initializers on | 36 /// Whether to infer types for consts and fields by looking at initializers on |
34 /// the RHS. For example, in a constant declaration like: | 37 /// the RHS. For example, in a constant declaration like: |
35 /// | 38 /// |
36 /// const A = B; | 39 /// const A = B; |
37 /// | 40 /// |
38 /// We can infer the type of `A` based on the type of `B`. | 41 /// We can infer the type of `A` based on the type of `B`. |
(...skipping 14 matching lines...) Expand all Loading... |
53 static const onlyInferConstAndFinalFieldsDefault = false; | 56 static const onlyInferConstAndFinalFieldsDefault = false; |
54 | 57 |
55 /// File where to start compilation from. | 58 /// File where to start compilation from. |
56 final String entryPointFile; | 59 final String entryPointFile; |
57 | 60 |
58 // True if the resolver should implicitly provide an html entry point. | 61 // True if the resolver should implicitly provide an html entry point. |
59 final bool useImplicitHtml; | 62 final bool useImplicitHtml; |
60 static const String implicitHtmlFile = 'index.html'; | 63 static const String implicitHtmlFile = 'index.html'; |
61 | 64 |
62 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', | 65 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', |
63 this.packagePaths: const <String>[], | 66 this.packagePaths: const <String>[], this.resources: const <String>[], |
64 this.inferFromOverrides: inferFromOverridesDefault, | 67 this.inferFromOverrides: inferFromOverridesDefault, |
65 this.inferTransitively: inferTransitivelyDefault, | 68 this.inferTransitively: inferTransitivelyDefault, |
66 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, | 69 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, |
67 this.entryPointFile: null, this.useImplicitHtml: false}); | 70 this.entryPointFile: null, this.useImplicitHtml: false}); |
68 } | 71 } |
69 | 72 |
70 // TODO(vsm): Merge RulesOptions and TypeOptions | 73 // TODO(vsm): Merge RulesOptions and TypeOptions |
71 /// Options used by our RestrictedRules. | 74 /// Options used by our RestrictedRules. |
72 class RulesOptions extends TypeOptions { | 75 class RulesOptions extends TypeOptions { |
73 /// Whether to allow casts in constant contexts. | 76 /// Whether to allow casts in constant contexts. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 final bool useMultiPackage; | 188 final bool useMultiPackage; |
186 | 189 |
187 /// Package root when resolving 'package:' urls the standard way. | 190 /// Package root when resolving 'package:' urls the standard way. |
188 @override | 191 @override |
189 final String packageRoot; | 192 final String packageRoot; |
190 | 193 |
191 /// List of paths used for the multi-package resolver. | 194 /// List of paths used for the multi-package resolver. |
192 @override | 195 @override |
193 final List<String> packagePaths; | 196 final List<String> packagePaths; |
194 | 197 |
| 198 /// List of additional non-Dart resources to resolve and serve. |
| 199 @override |
| 200 final List<String> resources; |
| 201 |
195 /// Whether to infer types downwards from local context | 202 /// Whether to infer types downwards from local context |
196 @override | 203 @override |
197 final bool inferDownwards; | 204 final bool inferDownwards; |
198 | 205 |
199 /// Whether to infer return types and field types from overriden members. | 206 /// Whether to infer return types and field types from overriden members. |
200 @override | 207 @override |
201 final bool inferFromOverrides; | 208 final bool inferFromOverrides; |
202 | 209 |
203 /// Whether to infer types for consts and static fields by looking at | 210 /// Whether to infer types for consts and static fields by looking at |
204 /// identifiers on the RHS. | 211 /// identifiers on the RHS. |
(...skipping 27 matching lines...) Expand all Loading... |
232 final String runtimeDir; | 239 final String runtimeDir; |
233 | 240 |
234 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, | 241 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, |
235 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir, | 242 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir, |
236 this.forceCompile: false, this.formatOutput: false, | 243 this.forceCompile: false, this.formatOutput: false, |
237 this.cheapTestFormat: false, this.ignoreTypes: false, | 244 this.cheapTestFormat: false, this.ignoreTypes: false, |
238 this.wrapClosures: RulesOptions.wrapClosuresDefault, this.outputDir, | 245 this.wrapClosures: RulesOptions.wrapClosuresDefault, this.outputDir, |
239 this.outputDart: false, this.useColors: true, | 246 this.outputDart: false, this.useColors: true, |
240 this.covariantGenerics: true, this.relaxedCasts: true, | 247 this.covariantGenerics: true, this.relaxedCasts: true, |
241 this.useMultiPackage: false, this.packageRoot: 'packages/', | 248 this.useMultiPackage: false, this.packageRoot: 'packages/', |
242 this.packagePaths: const <String>[], | 249 this.packagePaths: const <String>[], this.resources: const <String>[], |
243 this.inferDownwards: RulesOptions.inferDownwardsDefault, | 250 this.inferDownwards: RulesOptions.inferDownwardsDefault, |
244 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, | 251 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, |
245 this.inferTransitively: ResolverOptions.inferTransitivelyDefault, | 252 this.inferTransitively: ResolverOptions.inferTransitivelyDefault, |
246 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal
FieldsDefault, | 253 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal
FieldsDefault, |
247 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, | 254 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, |
248 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, | 255 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, |
249 this.emitSourceMaps: true, this.entryPointFile: null, | 256 this.emitSourceMaps: true, this.entryPointFile: null, |
250 this.serverMode: false, this.useImplicitHtml: false, | 257 this.serverMode: false, this.useImplicitHtml: false, |
251 this.enableHashing: false, this.host: 'localhost', this.port: 8080, | 258 this.enableHashing: false, this.host: 'localhost', this.port: 8080, |
252 this.runtimeDir}); | 259 this.runtimeDir}); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 ignoreTypes: args['ignore-types'], | 304 ignoreTypes: args['ignore-types'], |
298 wrapClosures: args['wrap-closures'], | 305 wrapClosures: args['wrap-closures'], |
299 outputDart: args['dart-gen'], | 306 outputDart: args['dart-gen'], |
300 outputDir: outputDir, | 307 outputDir: outputDir, |
301 covariantGenerics: args['covariant-generics'], | 308 covariantGenerics: args['covariant-generics'], |
302 relaxedCasts: args['relaxed-casts'], | 309 relaxedCasts: args['relaxed-casts'], |
303 useColors: useColors, | 310 useColors: useColors, |
304 useMultiPackage: args['use-multi-package'], | 311 useMultiPackage: args['use-multi-package'], |
305 packageRoot: args['package-root'], | 312 packageRoot: args['package-root'], |
306 packagePaths: args['package-paths'].split(','), | 313 packagePaths: args['package-paths'].split(','), |
| 314 resources: args['resources'].split(','), |
307 inferDownwards: args['infer-downwards'], | 315 inferDownwards: args['infer-downwards'], |
308 inferFromOverrides: args['infer-from-overrides'], | 316 inferFromOverrides: args['infer-from-overrides'], |
309 inferTransitively: args['infer-transitively'], | 317 inferTransitively: args['infer-transitively'], |
310 onlyInferConstsAndFinalFields: args['infer-only-finals'], | 318 onlyInferConstsAndFinalFields: args['infer-only-finals'], |
311 nonnullableTypes: optionsToList(args['nonnullable'], | 319 nonnullableTypes: optionsToList(args['nonnullable'], |
312 defaultValue: TypeOptions.NONNULLABLE_TYPES), | 320 defaultValue: TypeOptions.NONNULLABLE_TYPES), |
313 help: args['help'], | 321 help: args['help'], |
314 useMockSdk: args['mock-sdk'], | 322 useMockSdk: args['mock-sdk'], |
315 dartSdkPath: sdkPath, | 323 dartSdkPath: sdkPath, |
316 logLevel: logLevel, | 324 logLevel: logLevel, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 ..addOption('package-root', | 378 ..addOption('package-root', |
371 abbr: 'p', | 379 abbr: 'p', |
372 help: 'Package root to resolve "package:" imports', | 380 help: 'Package root to resolve "package:" imports', |
373 defaultsTo: 'packages/') | 381 defaultsTo: 'packages/') |
374 ..addFlag('use-multi-package', | 382 ..addFlag('use-multi-package', |
375 help: 'Whether to use the multi-package resolver for "package:" imports', | 383 help: 'Whether to use the multi-package resolver for "package:" imports', |
376 defaultsTo: false) | 384 defaultsTo: false) |
377 ..addOption('package-paths', | 385 ..addOption('package-paths', |
378 help: 'if using the multi-package resolver, the list of directories to\n' | 386 help: 'if using the multi-package resolver, the list of directories to\n' |
379 'look for packages in.', defaultsTo: '') | 387 'look for packages in.', defaultsTo: '') |
| 388 ..addOption('resources', |
| 389 help: 'Additional resources to serve', defaultsTo: '') |
380 ..addFlag('source-maps', | 390 ..addFlag('source-maps', |
381 help: 'Whether to emit source map files', defaultsTo: true) | 391 help: 'Whether to emit source map files', defaultsTo: true) |
382 ..addOption('runtime-dir', | 392 ..addOption('runtime-dir', |
383 help: 'Where to find dev_compiler\'s runtime files', defaultsTo: null) | 393 help: 'Where to find dev_compiler\'s runtime files', defaultsTo: null) |
384 | 394 |
385 // general options | 395 // general options |
386 ..addFlag('help', abbr: 'h', help: 'Display this message') | 396 ..addFlag('help', abbr: 'h', help: 'Display this message') |
387 ..addFlag('server', help: 'Run as a development server.', defaultsTo: false) | 397 ..addFlag('server', help: 'Run as a development server.', defaultsTo: false) |
388 ..addFlag('hashing', | 398 ..addFlag('hashing', |
389 help: 'Enable hash-based file caching.', defaultsTo: null) | 399 help: 'Enable hash-based file caching.', defaultsTo: null) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 // The pub-cache directory is two levels up, but we verify that the layout | 457 // The pub-cache directory is two levels up, but we verify that the layout |
448 // looks correct. | 458 // looks correct. |
449 if (path.basename(dir) != 'dev_compiler') return null; | 459 if (path.basename(dir) != 'dev_compiler') return null; |
450 dir = path.dirname(dir); | 460 dir = path.dirname(dir); |
451 if (path.basename(dir) != 'global_packages') return null; | 461 if (path.basename(dir) != 'global_packages') return null; |
452 dir = path.dirname(dir); | 462 dir = path.dirname(dir); |
453 return path.join(dir, cacheDir, 'lib', 'runtime'); | 463 return path.join(dir, cacheDir, 'lib', 'runtime'); |
454 } | 464 } |
455 return null; | 465 return null; |
456 } | 466 } |
OLD | NEW |