Chromium Code Reviews| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal FieldsDefault, | 211 this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinal FieldsDefault, |
| 212 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, | 212 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, |
| 213 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, | 213 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, |
| 214 this.emitSourceMaps: true, this.entryPointFile: null, | 214 this.emitSourceMaps: true, this.entryPointFile: null, |
| 215 this.serverMode: false, this.port: 8080, this.runtimeDir}); | 215 this.serverMode: false, this.port: 8080, this.runtimeDir}); |
| 216 } | 216 } |
| 217 | 217 |
| 218 /// Parses options from the command-line | 218 /// Parses options from the command-line |
| 219 CompilerOptions parseOptions(List<String> argv) { | 219 CompilerOptions parseOptions(List<String> argv) { |
| 220 ArgResults args = argParser.parse(argv); | 220 ArgResults args = argParser.parse(argv); |
| 221 var levelName = args['log'].toUpperCase(); | 221 var serverMode = args['server']; |
| 222 var logLevel = serverMode ? Level.ALL : Level.SEVERE; | |
| 223 var levelName = args['log']; | |
| 224 if (levelName != null) { | |
| 225 levelName = levelName.toUpperCase(); | |
| 226 logLevel = Level.LEVELS.firstWhere((l) => l.name == levelName, | |
| 227 orElse: () => logLevel); | |
| 228 } | |
| 222 var useColors = stdioType(stdout) == StdioType.TERMINAL; | 229 var useColors = stdioType(stdout) == StdioType.TERMINAL; |
| 223 var sdkPath = args['dart-sdk']; | 230 var sdkPath = args['dart-sdk']; |
| 224 if (sdkPath == null && !args['mock-sdk']) { | 231 if (sdkPath == null && !args['mock-sdk']) { |
| 225 sdkPath = getSdkDir(argv).path; | 232 sdkPath = getSdkDir(argv).path; |
| 226 } | 233 } |
| 227 var runtimeDir = args['runtime-dir']; | 234 var runtimeDir = args['runtime-dir']; |
| 228 if (runtimeDir == null) { | 235 if (runtimeDir == null) { |
| 229 runtimeDir = _computeRuntimeDir(); | 236 runtimeDir = _computeRuntimeDir(); |
| 230 } | 237 } |
| 238 var outputDir = args['out']; | |
| 239 if (outputDir == null && serverMode) { | |
| 240 outputDir = Directory.systemTemp.createTempSync("dev_compiler_out_").path; | |
| 241 } | |
| 231 return new CompilerOptions( | 242 return new CompilerOptions( |
| 232 allowConstCasts: args['allow-const-casts'], | 243 allowConstCasts: args['allow-const-casts'], |
| 233 checkSdk: args['sdk-check'], | 244 checkSdk: args['sdk-check'], |
| 234 dumpInfo: args['dump-info'], | 245 dumpInfo: args['dump-info'] || serverMode, |
| 235 dumpInfoFile: args['dump-info-file'], | 246 dumpInfoFile: args['dump-info-file'], |
| 236 dumpSrcDir: args['dump-src-to'], | 247 dumpSrcDir: args['dump-src-to'], |
| 237 forceCompile: args['force-compile'], | 248 forceCompile: args['force-compile'] || serverMode, |
| 238 formatOutput: args['dart-gen-fmt'], | 249 formatOutput: args['dart-gen-fmt'], |
| 239 ignoreTypes: args['ignore-types'], | 250 ignoreTypes: args['ignore-types'], |
| 240 outputDart: args['dart-gen'], | 251 outputDart: args['dart-gen'], |
| 241 outputDir: args['out'], | 252 outputDir: outputDir, |
| 242 covariantGenerics: args['covariant-generics'], | 253 covariantGenerics: args['covariant-generics'], |
| 243 relaxedCasts: args['relaxed-casts'], | 254 relaxedCasts: args['relaxed-casts'], |
| 244 useColors: useColors, | 255 useColors: useColors, |
| 245 useMultiPackage: args['use-multi-package'], | 256 useMultiPackage: args['use-multi-package'], |
| 246 packageRoot: args['package-root'], | 257 packageRoot: args['package-root'], |
| 247 packagePaths: args['package-paths'].split(','), | 258 packagePaths: args['package-paths'].split(','), |
| 248 inferFromOverrides: args['infer-from-overrides'], | 259 inferFromOverrides: args['infer-from-overrides'], |
| 249 inferTransitively: args['infer-transitively'], | 260 inferTransitively: args['infer-transitively'], |
| 250 onlyInferConstsAndFinalFields: args['infer-only-finals'], | 261 onlyInferConstsAndFinalFields: args['infer-only-finals'], |
| 251 nonnullableTypes: optionsToList(args['nonnullable'], | 262 nonnullableTypes: optionsToList(args['nonnullable'], |
| 252 defaultValue: TypeOptions.NONNULLABLE_TYPES), | 263 defaultValue: TypeOptions.NONNULLABLE_TYPES), |
| 253 help: args['help'], | 264 help: args['help'], |
| 254 useMockSdk: args['mock-sdk'], | 265 useMockSdk: args['mock-sdk'], |
| 255 dartSdkPath: sdkPath, | 266 dartSdkPath: sdkPath, |
| 256 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName, | 267 logLevel: logLevel, |
| 257 orElse: () => Level.SEVERE), | |
| 258 emitSourceMaps: args['source-maps'], | 268 emitSourceMaps: args['source-maps'], |
| 259 entryPointFile: args.rest.length == 0 ? null : args.rest.first, | 269 entryPointFile: args.rest.length == 0 ? null : args.rest.first, |
| 260 serverMode: args['server'], | 270 serverMode: serverMode, |
| 261 port: int.parse(args['port']), | 271 port: int.parse(args['port']), |
| 262 runtimeDir: runtimeDir); | 272 runtimeDir: runtimeDir); |
| 263 } | 273 } |
| 264 | 274 |
| 265 final ArgParser argParser = new ArgParser() | 275 final ArgParser argParser = new ArgParser() |
| 266 // resolver/checker options | 276 // resolver/checker options |
| 267 ..addFlag('allow-const-casts', | 277 ..addFlag('allow-const-casts', |
| 268 help: 'Allow casts in const contexts', defaultsTo: true) | 278 help: 'Allow casts in const contexts', defaultsTo: true) |
| 269 ..addFlag('sdk-check', | 279 ..addFlag('sdk-check', |
| 270 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) | 280 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 help: 'Where to find dev_compiler\'s runtime files', defaultsTo: null) | 324 help: 'Where to find dev_compiler\'s runtime files', defaultsTo: null) |
| 315 | 325 |
| 316 // general options | 326 // general options |
| 317 ..addFlag('help', abbr: 'h', help: 'Display this message') | 327 ..addFlag('help', abbr: 'h', help: 'Display this message') |
| 318 ..addFlag('server', help: 'Run as a development server.', defaultsTo: false) | 328 ..addFlag('server', help: 'Run as a development server.', defaultsTo: false) |
| 319 ..addOption('port', | 329 ..addOption('port', |
| 320 help: 'Port where to serve files from (used only when --serve is on)', | 330 help: 'Port where to serve files from (used only when --serve is on)', |
| 321 defaultsTo: '8080') | 331 defaultsTo: '8080') |
| 322 ..addFlag('force-compile', | 332 ..addFlag('force-compile', |
| 323 help: 'Compile code with static errors', defaultsTo: false) | 333 help: 'Compile code with static errors', defaultsTo: false) |
| 324 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe') | 334 ..addOption('log', abbr: 'l', help: 'Logging level (defaults to severe)') |
| 325 ..addFlag('dump-info', | 335 ..addFlag('dump-info', |
| 326 abbr: 'i', help: 'Dump summary information', defaultsTo: false) | 336 abbr: 'i', help: 'Dump summary information', defaultsTo: false) |
|
Jennifer Messerly
2015/03/19 22:32:22
do we need to fix this option to?
Siggi Cherem (dart-lang)
2015/03/19 22:44:50
Unfortunately we can't with 'flags'. Boolean flags
Jennifer Messerly
2015/03/19 22:47:59
just have --server imply it?
Siggi Cherem (dart-lang)
2015/03/19 22:50:12
Done.
| |
| 327 ..addOption('dump-info-file', | 337 ..addOption('dump-info-file', |
| 328 abbr: 'f', | 338 abbr: 'f', |
| 329 help: 'Dump info json file (requires dump-info)', | 339 help: 'Dump info json file (requires dump-info)', |
| 330 defaultsTo: null); | 340 defaultsTo: null); |
| 331 | 341 |
| 332 /// Tries to find the `lib/runtime/` directory of the dev_compiler package. This | 342 /// Tries to find the `lib/runtime/` directory of the dev_compiler package. This |
| 333 /// works when running devc from it's sources or from a snapshot that is | 343 /// works when running devc from it's sources or from a snapshot that is |
| 334 /// activated via `pub global activate`. | 344 /// activated via `pub global activate`. |
| 335 String _computeRuntimeDir() { | 345 String _computeRuntimeDir() { |
| 336 var scriptUri = Platform.script; | 346 var scriptUri = Platform.script; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 // The pub-cache directory is two levels up, but we verify that the layout | 382 // The pub-cache directory is two levels up, but we verify that the layout |
| 373 // looks correct. | 383 // looks correct. |
| 374 if (path.basename(dir) != 'dev_compiler') return null; | 384 if (path.basename(dir) != 'dev_compiler') return null; |
| 375 dir = path.dirname(dir); | 385 dir = path.dirname(dir); |
| 376 if (path.basename(dir) != 'global_packages') return null; | 386 if (path.basename(dir) != 'global_packages') return null; |
| 377 dir = path.dirname(dir); | 387 dir = path.dirname(dir); |
| 378 return path.join(dir, cacheDir, 'lib', 'runtime'); | 388 return path.join(dir, cacheDir, 'lib', 'runtime'); |
| 379 } | 389 } |
| 380 return null; | 390 return null; |
| 381 } | 391 } |
| OLD | NEW |