| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 /// When this feature is turned off, we don't use the type of `B` to infer the | 44 /// When this feature is turned off, we don't use the type of `B` to infer the |
| 45 /// type of `A`, even if `B` has a declared type. | 45 /// type of `A`, even if `B` has a declared type. |
| 46 final bool inferTransitively; | 46 final bool inferTransitively; |
| 47 static const inferTransitivelyDefault = true; | 47 static const inferTransitivelyDefault = true; |
| 48 | 48 |
| 49 /// Restrict inference of fields and top-levels to those that are final and | 49 /// Restrict inference of fields and top-levels to those that are final and |
| 50 /// const. | 50 /// const. |
| 51 final bool onlyInferConstsAndFinalFields; | 51 final bool onlyInferConstsAndFinalFields; |
| 52 static const onlyInferConstAndFinalFieldsDefault = false; | 52 static const onlyInferConstAndFinalFieldsDefault = false; |
| 53 | 53 |
| 54 /// File where to start compilation from. |
| 55 final String entryPointFile; |
| 56 |
| 57 // True if the resolver should implicitly provide an html entry point. |
| 58 final bool useImplicitHtml; |
| 59 static const String implicitHtmlFile = 'index.html'; |
| 60 |
| 54 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', | 61 ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/', |
| 55 this.packagePaths: const <String>[], | 62 this.packagePaths: const <String>[], |
| 56 this.inferFromOverrides: inferFromOverridesDefault, | 63 this.inferFromOverrides: inferFromOverridesDefault, |
| 57 this.inferTransitively: inferTransitivelyDefault, | 64 this.inferTransitively: inferTransitivelyDefault, |
| 58 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault}); | 65 this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault, |
| 66 this.entryPointFile: null, this.useImplicitHtml: false}); |
| 59 } | 67 } |
| 60 | 68 |
| 61 // TODO(vsm): Merge RulesOptions and TypeOptions | 69 // TODO(vsm): Merge RulesOptions and TypeOptions |
| 62 /// Options used by our RestrictedRules. | 70 /// Options used by our RestrictedRules. |
| 63 class RulesOptions extends TypeOptions { | 71 class RulesOptions extends TypeOptions { |
| 64 /// Whether to allow casts in constant contexts. | 72 /// Whether to allow casts in constant contexts. |
| 65 final bool allowConstCasts; | 73 final bool allowConstCasts; |
| 66 | 74 |
| 67 /// Whether to use covariant generics | 75 /// Whether to use covariant generics |
| 68 final bool covariantGenerics; | 76 final bool covariantGenerics; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 /// File where to start compilation from. | 152 /// File where to start compilation from. |
| 145 final String entryPointFile; | 153 final String entryPointFile; |
| 146 | 154 |
| 147 /// Whether to allow casts in constant contexts. | 155 /// Whether to allow casts in constant contexts. |
| 148 @override | 156 @override |
| 149 final bool allowConstCasts; | 157 final bool allowConstCasts; |
| 150 | 158 |
| 151 /// Whether to run as a development server. | 159 /// Whether to run as a development server. |
| 152 final bool serverMode; | 160 final bool serverMode; |
| 153 | 161 |
| 162 /// Whether to create an implicit HTML entry file in server mode. |
| 163 final bool useImplicitHtml; |
| 164 |
| 154 /// Whether to enable hash-based caching of files. | 165 /// Whether to enable hash-based caching of files. |
| 155 final bool enableHashing; | 166 final bool enableHashing; |
| 156 | 167 |
| 157 /// Port used for the HTTP server when [serverMode] is on. | 168 /// Port used for the HTTP server when [serverMode] is on. |
| 158 final int port; | 169 final int port; |
| 159 | 170 |
| 160 /// Host name or address for HTTP server when [serverMode] is on. | 171 /// Host name or address for HTTP server when [serverMode] is on. |
| 161 final String host; | 172 final String host; |
| 162 | 173 |
| 163 /// Whether to use covariant generics | 174 /// Whether to use covariant generics |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 this.covariantGenerics: true, this.relaxedCasts: true, | 239 this.covariantGenerics: true, this.relaxedCasts: true, |
| 229 this.useMultiPackage: false, this.packageRoot: 'packages/', | 240 this.useMultiPackage: false, this.packageRoot: 'packages/', |
| 230 this.packagePaths: const <String>[], | 241 this.packagePaths: const <String>[], |
| 231 this.inferDownwards: RulesOptions.inferDownwardsDefault, | 242 this.inferDownwards: RulesOptions.inferDownwardsDefault, |
| 232 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, | 243 this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault, |
| 233 this.inferTransitively: ResolverOptions.inferTransitivelyDefault, | 244 this.inferTransitively: ResolverOptions.inferTransitivelyDefault, |
| 234 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal
FieldsDefault, | 245 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal
FieldsDefault, |
| 235 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, | 246 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, |
| 236 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, | 247 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, |
| 237 this.emitSourceMaps: true, this.entryPointFile: null, | 248 this.emitSourceMaps: true, this.entryPointFile: null, |
| 238 this.serverMode: false, this.enableHashing: false, this.host: 'localhost', | 249 this.serverMode: false, this.useImplicitHtml: false, |
| 239 this.port: 8080, this.runtimeDir}); | 250 this.enableHashing: false, this.host: 'localhost', this.port: 8080, |
| 251 this.runtimeDir}); |
| 240 } | 252 } |
| 241 | 253 |
| 242 /// Parses options from the command-line | 254 /// Parses options from the command-line |
| 243 CompilerOptions parseOptions(List<String> argv) { | 255 CompilerOptions parseOptions(List<String> argv) { |
| 244 ArgResults args = argParser.parse(argv); | 256 ArgResults args = argParser.parse(argv); |
| 245 var serverMode = args['server']; | 257 var serverMode = args['server']; |
| 246 var enableHashing = args['hashing']; | 258 var enableHashing = args['hashing']; |
| 247 if (enableHashing == null) { | 259 if (enableHashing == null) { |
| 248 enableHashing = serverMode; | 260 enableHashing = serverMode; |
| 249 } | 261 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 263 if (runtimeDir == null) { | 275 if (runtimeDir == null) { |
| 264 runtimeDir = _computeRuntimeDir(); | 276 runtimeDir = _computeRuntimeDir(); |
| 265 } | 277 } |
| 266 var outputDir = args['out']; | 278 var outputDir = args['out']; |
| 267 if (outputDir == null && serverMode) { | 279 if (outputDir == null && serverMode) { |
| 268 outputDir = Directory.systemTemp.createTempSync("dev_compiler_out_").path; | 280 outputDir = Directory.systemTemp.createTempSync("dev_compiler_out_").path; |
| 269 } | 281 } |
| 270 var dumpInfo = args['dump-info']; | 282 var dumpInfo = args['dump-info']; |
| 271 if (dumpInfo == null) dumpInfo = serverMode; | 283 if (dumpInfo == null) dumpInfo = serverMode; |
| 272 | 284 |
| 285 var entryPointFile = args.rest.length == 0 ? null : args.rest.first; |
| 286 |
| 273 return new CompilerOptions( | 287 return new CompilerOptions( |
| 274 allowConstCasts: args['allow-const-casts'], | 288 allowConstCasts: args['allow-const-casts'], |
| 275 checkSdk: args['sdk-check'], | 289 checkSdk: args['sdk-check'], |
| 276 dumpInfo: dumpInfo, | 290 dumpInfo: dumpInfo, |
| 277 dumpInfoFile: args['dump-info-file'], | 291 dumpInfoFile: args['dump-info-file'], |
| 278 dumpSrcDir: args['dump-src-to'], | 292 dumpSrcDir: args['dump-src-to'], |
| 279 forceCompile: args['force-compile'] || serverMode, | 293 forceCompile: args['force-compile'] || serverMode, |
| 280 formatOutput: args['dart-gen-fmt'], | 294 formatOutput: args['dart-gen-fmt'], |
| 281 ignoreTypes: args['ignore-types'], | 295 ignoreTypes: args['ignore-types'], |
| 282 wrapClosures: args['wrap-closures'], | 296 wrapClosures: args['wrap-closures'], |
| 283 outputDart: args['dart-gen'], | 297 outputDart: args['dart-gen'], |
| 284 outputDir: outputDir, | 298 outputDir: outputDir, |
| 285 covariantGenerics: args['covariant-generics'], | 299 covariantGenerics: args['covariant-generics'], |
| 286 relaxedCasts: args['relaxed-casts'], | 300 relaxedCasts: args['relaxed-casts'], |
| 287 useColors: useColors, | 301 useColors: useColors, |
| 288 useMultiPackage: args['use-multi-package'], | 302 useMultiPackage: args['use-multi-package'], |
| 289 packageRoot: args['package-root'], | 303 packageRoot: args['package-root'], |
| 290 packagePaths: args['package-paths'].split(','), | 304 packagePaths: args['package-paths'].split(','), |
| 291 inferDownwards: args['infer-downwards'], | 305 inferDownwards: args['infer-downwards'], |
| 292 inferFromOverrides: args['infer-from-overrides'], | 306 inferFromOverrides: args['infer-from-overrides'], |
| 293 inferTransitively: args['infer-transitively'], | 307 inferTransitively: args['infer-transitively'], |
| 294 onlyInferConstsAndFinalFields: args['infer-only-finals'], | 308 onlyInferConstsAndFinalFields: args['infer-only-finals'], |
| 295 nonnullableTypes: optionsToList(args['nonnullable'], | 309 nonnullableTypes: optionsToList(args['nonnullable'], |
| 296 defaultValue: TypeOptions.NONNULLABLE_TYPES), | 310 defaultValue: TypeOptions.NONNULLABLE_TYPES), |
| 297 help: args['help'], | 311 help: args['help'], |
| 298 useMockSdk: args['mock-sdk'], | 312 useMockSdk: args['mock-sdk'], |
| 299 dartSdkPath: sdkPath, | 313 dartSdkPath: sdkPath, |
| 300 logLevel: logLevel, | 314 logLevel: logLevel, |
| 301 emitSourceMaps: args['source-maps'], | 315 emitSourceMaps: args['source-maps'], |
| 302 entryPointFile: args.rest.length == 0 ? null : args.rest.first, | 316 entryPointFile: entryPointFile, |
| 303 serverMode: serverMode, | 317 serverMode: serverMode, |
| 318 useImplicitHtml: serverMode && entryPointFile.endsWith('.dart'), |
| 304 enableHashing: enableHashing, | 319 enableHashing: enableHashing, |
| 305 host: args['host'], | 320 host: args['host'], |
| 306 port: int.parse(args['port']), | 321 port: int.parse(args['port']), |
| 307 runtimeDir: runtimeDir); | 322 runtimeDir: runtimeDir); |
| 308 } | 323 } |
| 309 | 324 |
| 310 final ArgParser argParser = new ArgParser() | 325 final ArgParser argParser = new ArgParser() |
| 311 // resolver/checker options | 326 // resolver/checker options |
| 312 ..addFlag('allow-const-casts', | 327 ..addFlag('allow-const-casts', |
| 313 help: 'Allow casts in const contexts', defaultsTo: true) | 328 help: 'Allow casts in const contexts', defaultsTo: true) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // The pub-cache directory is two levels up, but we verify that the layout | 445 // The pub-cache directory is two levels up, but we verify that the layout |
| 431 // looks correct. | 446 // looks correct. |
| 432 if (path.basename(dir) != 'dev_compiler') return null; | 447 if (path.basename(dir) != 'dev_compiler') return null; |
| 433 dir = path.dirname(dir); | 448 dir = path.dirname(dir); |
| 434 if (path.basename(dir) != 'global_packages') return null; | 449 if (path.basename(dir) != 'global_packages') return null; |
| 435 dir = path.dirname(dir); | 450 dir = path.dirname(dir); |
| 436 return path.join(dir, cacheDir, 'lib', 'runtime'); | 451 return path.join(dir, cacheDir, 'lib', 'runtime'); |
| 437 } | 452 } |
| 438 return null; | 453 return null; |
| 439 } | 454 } |
| OLD | NEW |