| 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'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 this.packagePaths: const <String>[], this.resources: const <String>[], | 66 this.packagePaths: const <String>[], this.resources: const <String>[], |
| 67 this.inferFromOverrides: inferFromOverridesDefault, | 67 this.inferFromOverrides: inferFromOverridesDefault, |
| 68 this.inferTransitively: inferTransitivelyDefault, | 68 this.inferTransitively: inferTransitivelyDefault, |
| 69 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, | 69 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, |
| 70 this.entryPointFile: null, this.useImplicitHtml: false}); | 70 this.entryPointFile: null, this.useImplicitHtml: false}); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // TODO(vsm): Merge RulesOptions and TypeOptions | 73 // TODO(vsm): Merge RulesOptions and TypeOptions |
| 74 /// Options used by our RestrictedRules. | 74 /// Options used by our RestrictedRules. |
| 75 class RulesOptions extends TypeOptions { | 75 class RulesOptions extends TypeOptions { |
| 76 /// Whether to allow casts in constant contexts. | |
| 77 final bool allowConstCasts; | |
| 78 | |
| 79 /// Whether to use covariant generics | 76 /// Whether to use covariant generics |
| 80 final bool covariantGenerics; | 77 final bool covariantGenerics; |
| 81 | 78 |
| 82 /// Whether to infer types downwards from local context | 79 /// Whether to infer types downwards from local context |
| 83 final bool inferDownwards; | 80 final bool inferDownwards; |
| 84 static const inferDownwardsDefault = true; | 81 static const inferDownwardsDefault = true; |
| 85 | 82 |
| 86 /// Whether to inject casts between Dart assignable types. | 83 /// Whether to inject casts between Dart assignable types. |
| 87 final bool relaxedCasts; | 84 final bool relaxedCasts; |
| 88 | 85 |
| 89 /// Whether to use static types for code generation. | 86 /// Whether to use static types for code generation. |
| 90 final bool ignoreTypes; | 87 final bool ignoreTypes; |
| 91 | 88 |
| 92 /// Whether to wrap closures for compatibility. | 89 /// Whether to wrap closures for compatibility. |
| 93 final bool wrapClosures; | 90 final bool wrapClosures; |
| 94 static const wrapClosuresDefault = false; | 91 static const wrapClosuresDefault = false; |
| 95 | 92 |
| 96 RulesOptions({this.allowConstCasts: true, this.covariantGenerics: true, | 93 RulesOptions({this.covariantGenerics: true, |
| 97 this.inferDownwards: inferDownwardsDefault, this.relaxedCasts: true, | 94 this.inferDownwards: inferDownwardsDefault, this.relaxedCasts: true, |
| 98 this.ignoreTypes: false, this.wrapClosures: wrapClosuresDefault}); | 95 this.ignoreTypes: false, this.wrapClosures: wrapClosuresDefault}); |
| 99 } | 96 } |
| 100 | 97 |
| 101 class JSCodeOptions { | 98 class JSCodeOptions { |
| 102 /// Whether to emit the source map files. | 99 /// Whether to emit the source map files. |
| 103 final bool emitSourceMaps; | 100 final bool emitSourceMaps; |
| 104 | 101 |
| 105 JSCodeOptions({this.emitSourceMaps: true}); | 102 JSCodeOptions({this.emitSourceMaps: true}); |
| 106 } | 103 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 135 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't | 132 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't |
| 136 /// be determined | 133 /// be determined |
| 137 final String dartSdkPath; | 134 final String dartSdkPath; |
| 138 | 135 |
| 139 /// Minimum log-level reported on the command-line. | 136 /// Minimum log-level reported on the command-line. |
| 140 final Level logLevel; | 137 final Level logLevel; |
| 141 | 138 |
| 142 /// File where to start compilation from. | 139 /// File where to start compilation from. |
| 143 final String entryPointFile; | 140 final String entryPointFile; |
| 144 | 141 |
| 145 /// Whether to allow casts in constant contexts. | |
| 146 @override | |
| 147 final bool allowConstCasts; | |
| 148 | |
| 149 /// Whether to run as a development server. | 142 /// Whether to run as a development server. |
| 150 final bool serverMode; | 143 final bool serverMode; |
| 151 | 144 |
| 152 /// Whether to create an implicit HTML entry file in server mode. | 145 /// Whether to create an implicit HTML entry file in server mode. |
| 153 final bool useImplicitHtml; | 146 final bool useImplicitHtml; |
| 154 | 147 |
| 155 /// Whether to enable hash-based caching of files. | 148 /// Whether to enable hash-based caching of files. |
| 156 final bool enableHashing; | 149 final bool enableHashing; |
| 157 | 150 |
| 158 /// Port used for the HTTP server when [serverMode] is on. | 151 /// Port used for the HTTP server when [serverMode] is on. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 final bool emitSourceMaps; | 213 final bool emitSourceMaps; |
| 221 | 214 |
| 222 /// Location for runtime files, such as `dart_runtime.js`. By default this is | 215 /// Location for runtime files, such as `dart_runtime.js`. By default this is |
| 223 /// inferred to be under `lib/runtime/` in the location of the `dev_compiler` | 216 /// inferred to be under `lib/runtime/` in the location of the `dev_compiler` |
| 224 /// package (if we can infer where that is located). | 217 /// package (if we can infer where that is located). |
| 225 final String runtimeDir; | 218 final String runtimeDir; |
| 226 | 219 |
| 227 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" | 220 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" |
| 228 final Map<String, String> customUrlMappings; | 221 final Map<String, String> customUrlMappings; |
| 229 | 222 |
| 230 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, | 223 CompilerOptions({this.checkSdk: false, this.dumpInfo: false, |
| 231 this.dumpInfo: false, this.dumpInfoFile, this.forceCompile: false, | 224 this.dumpInfoFile, this.forceCompile: false, this.ignoreTypes: false, |
| 232 this.ignoreTypes: false, | |
| 233 this.wrapClosures: RulesOptions.wrapClosuresDefault, this.outputDir, | 225 this.wrapClosures: RulesOptions.wrapClosuresDefault, this.outputDir, |
| 234 this.useColors: true, this.covariantGenerics: true, | 226 this.useColors: true, this.covariantGenerics: true, |
| 235 this.relaxedCasts: true, this.useMultiPackage: false, | 227 this.relaxedCasts: true, this.useMultiPackage: false, |
| 236 this.packageRoot: 'packages/', this.packagePaths: const <String>[], | 228 this.packageRoot: 'packages/', this.packagePaths: const <String>[], |
| 237 this.resources: const <String>[], | 229 this.resources: const <String>[], |
| 238 this.inferDownwards: RulesOptions.inferDownwardsDefault, | 230 this.inferDownwards: RulesOptions.inferDownwardsDefault, |
| 239 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, | 231 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, |
| 240 this.inferTransitively: ResolverOptions.inferTransitivelyDefault, | 232 this.inferTransitively: ResolverOptions.inferTransitivelyDefault, |
| 241 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal
FieldsDefault, | 233 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal
FieldsDefault, |
| 242 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, | 234 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 if (splitMapping.length != 2) { | 279 if (splitMapping.length != 2) { |
| 288 showUsage = true; | 280 showUsage = true; |
| 289 continue; | 281 continue; |
| 290 } | 282 } |
| 291 customUrlMappings[splitMapping[0]] = splitMapping[1]; | 283 customUrlMappings[splitMapping[0]] = splitMapping[1]; |
| 292 } | 284 } |
| 293 | 285 |
| 294 var entryPointFile = args.rest.length == 0 ? null : args.rest.first; | 286 var entryPointFile = args.rest.length == 0 ? null : args.rest.first; |
| 295 | 287 |
| 296 return new CompilerOptions( | 288 return new CompilerOptions( |
| 297 allowConstCasts: args['allow-const-casts'], | |
| 298 checkSdk: args['sdk-check'], | 289 checkSdk: args['sdk-check'], |
| 299 dumpInfo: dumpInfo, | 290 dumpInfo: dumpInfo, |
| 300 dumpInfoFile: args['dump-info-file'], | 291 dumpInfoFile: args['dump-info-file'], |
| 301 forceCompile: args['force-compile'] || serverMode, | 292 forceCompile: args['force-compile'] || serverMode, |
| 302 ignoreTypes: args['ignore-types'], | 293 ignoreTypes: args['ignore-types'], |
| 303 wrapClosures: args['wrap-closures'], | 294 wrapClosures: args['wrap-closures'], |
| 304 outputDir: outputDir, | 295 outputDir: outputDir, |
| 305 covariantGenerics: args['covariant-generics'], | 296 covariantGenerics: args['covariant-generics'], |
| 306 relaxedCasts: args['relaxed-casts'], | 297 relaxedCasts: args['relaxed-casts'], |
| 307 useColors: useColors, | 298 useColors: useColors, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 328 serverMode: serverMode, | 319 serverMode: serverMode, |
| 329 useImplicitHtml: serverMode && entryPointFile.endsWith('.dart'), | 320 useImplicitHtml: serverMode && entryPointFile.endsWith('.dart'), |
| 330 enableHashing: enableHashing, | 321 enableHashing: enableHashing, |
| 331 host: args['host'], | 322 host: args['host'], |
| 332 port: int.parse(args['port']), | 323 port: int.parse(args['port']), |
| 333 runtimeDir: runtimeDir); | 324 runtimeDir: runtimeDir); |
| 334 } | 325 } |
| 335 | 326 |
| 336 final ArgParser argParser = new ArgParser() | 327 final ArgParser argParser = new ArgParser() |
| 337 // resolver/checker options | 328 // resolver/checker options |
| 338 ..addFlag('allow-const-casts', | |
| 339 help: 'Allow casts in const contexts', defaultsTo: true) | |
| 340 ..addFlag('sdk-check', | 329 ..addFlag('sdk-check', |
| 341 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) | 330 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) |
| 342 ..addFlag('mock-sdk', | 331 ..addFlag('mock-sdk', |
| 343 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false) | 332 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false) |
| 344 ..addFlag('covariant-generics', | 333 ..addFlag('covariant-generics', |
| 345 help: 'Use covariant generics', defaultsTo: true) | 334 help: 'Use covariant generics', defaultsTo: true) |
| 346 ..addFlag('ignore-types', | 335 ..addFlag('ignore-types', |
| 347 help: 'Ignore types during codegen', defaultsTo: false) | 336 help: 'Ignore types during codegen', defaultsTo: false) |
| 348 ..addFlag('wrap-closures', | 337 ..addFlag('wrap-closures', |
| 349 help: 'wrap closures implicitly', | 338 help: 'wrap closures implicitly', |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 // The pub-cache directory is two levels up, but we verify that the layout | 448 // The pub-cache directory is two levels up, but we verify that the layout |
| 460 // looks correct. | 449 // looks correct. |
| 461 if (path.basename(dir) != 'dev_compiler') return null; | 450 if (path.basename(dir) != 'dev_compiler') return null; |
| 462 dir = path.dirname(dir); | 451 dir = path.dirname(dir); |
| 463 if (path.basename(dir) != 'global_packages') return null; | 452 if (path.basename(dir) != 'global_packages') return null; |
| 464 dir = path.dirname(dir); | 453 dir = path.dirname(dir); |
| 465 return path.join(dir, cacheDir, 'lib', 'runtime'); | 454 return path.join(dir, cacheDir, 'lib', 'runtime'); |
| 466 } | 455 } |
| 467 return null; | 456 return null; |
| 468 } | 457 } |
| OLD | NEW |