| 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 ddc.src.options; | 6 library ddc.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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 /// Whether to inject casts between Dart assignable types. | 72 /// Whether to inject casts between Dart assignable types. |
| 73 final bool relaxedCasts; | 73 final bool relaxedCasts; |
| 74 | 74 |
| 75 /// Whether to use static types for code generation. | 75 /// Whether to use static types for code generation. |
| 76 final bool ignoreTypes; | 76 final bool ignoreTypes; |
| 77 | 77 |
| 78 RulesOptions({this.allowConstCasts: true, this.covariantGenerics: true, | 78 RulesOptions({this.allowConstCasts: true, this.covariantGenerics: true, |
| 79 this.relaxedCasts: true, this.ignoreTypes: false}); | 79 this.relaxedCasts: true, this.ignoreTypes: false}); |
| 80 } | 80 } |
| 81 | 81 |
| 82 class JSCodeOptions { |
| 83 /// Whether to emit the source map files. |
| 84 final bool emitSourceMaps; |
| 85 |
| 86 JSCodeOptions({this.emitSourceMaps: true}); |
| 87 } |
| 88 |
| 82 /// General options used by the dev compiler. | 89 /// General options used by the dev compiler. |
| 83 class CompilerOptions implements RulesOptions, ResolverOptions { | 90 class CompilerOptions implements RulesOptions, ResolverOptions, JSCodeOptions { |
| 84 /// Whether to check the sdk libraries. | 91 /// Whether to check the sdk libraries. |
| 85 final bool checkSdk; | 92 final bool checkSdk; |
| 86 | 93 |
| 87 /// Whether to dump summary information on the console. | 94 /// Whether to dump summary information on the console. |
| 88 final bool dumpInfo; | 95 final bool dumpInfo; |
| 89 | 96 |
| 90 /// If not null, path to a file that will store a json representation of the | 97 /// If not null, path to a file that will store a json representation of the |
| 91 /// summary information (only used if [dumpInfo] is true). | 98 /// summary information (only used if [dumpInfo] is true). |
| 92 final String dumpInfoFile; | 99 final String dumpInfoFile; |
| 93 | 100 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 final bool onlyInferConstsAndFinalFields; | 180 final bool onlyInferConstsAndFinalFields; |
| 174 | 181 |
| 175 /// List of non-nullable types. | 182 /// List of non-nullable types. |
| 176 @override | 183 @override |
| 177 final List<String> nonnullableTypes; | 184 final List<String> nonnullableTypes; |
| 178 | 185 |
| 179 /// Whether to use static types for code generation. | 186 /// Whether to use static types for code generation. |
| 180 @override | 187 @override |
| 181 final bool ignoreTypes; | 188 final bool ignoreTypes; |
| 182 | 189 |
| 190 /// Whether to emit the source map files. |
| 191 @override |
| 192 final bool emitSourceMaps; |
| 193 |
| 183 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, | 194 CompilerOptions({this.allowConstCasts: true, this.checkSdk: false, |
| 184 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir, | 195 this.dumpInfo: false, this.dumpInfoFile, this.dumpSrcDir, |
| 185 this.forceCompile: false, this.formatOutput: false, | 196 this.forceCompile: false, this.formatOutput: false, |
| 186 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir, | 197 this.cheapTestFormat: false, this.ignoreTypes: false, this.outputDir, |
| 187 this.outputDart: false, this.useColors: true, | 198 this.outputDart: false, this.useColors: true, |
| 188 this.covariantGenerics: true, this.relaxedCasts: true, | 199 this.covariantGenerics: true, this.relaxedCasts: true, |
| 189 this.useMultiPackage: false, this.packageRoot: 'packages/', | 200 this.useMultiPackage: false, this.packageRoot: 'packages/', |
| 190 this.packagePaths: const <String>[], this.inferFromOverrides: true, | 201 this.packagePaths: const <String>[], this.inferFromOverrides: true, |
| 191 this.inferStaticsFromIdentifiers: false, | 202 this.inferStaticsFromIdentifiers: false, |
| 192 this.inferInNonStableOrder: false, | 203 this.inferInNonStableOrder: false, |
| 193 this.onlyInferConstsAndFinalFields: false, | 204 this.onlyInferConstsAndFinalFields: false, |
| 194 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, | 205 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false, |
| 195 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, | 206 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE, |
| 196 this.entryPointFile: null}); | 207 this.emitSourceMaps: true, this.entryPointFile: null}); |
| 197 } | 208 } |
| 198 | 209 |
| 199 /// Parses options from the command-line | 210 /// Parses options from the command-line |
| 200 CompilerOptions parseOptions(List<String> argv) { | 211 CompilerOptions parseOptions(List<String> argv) { |
| 201 ArgResults args = argParser.parse(argv); | 212 ArgResults args = argParser.parse(argv); |
| 202 var levelName = args['log'].toUpperCase(); | 213 var levelName = args['log'].toUpperCase(); |
| 203 var useColors = stdioType(stdout) == StdioType.TERMINAL; | 214 var useColors = stdioType(stdout) == StdioType.TERMINAL; |
| 204 var sdkPath = args['dart-sdk']; | 215 var sdkPath = args['dart-sdk']; |
| 205 if (sdkPath == null && !args['mock-sdk']) { | 216 if (sdkPath == null && !args['mock-sdk']) { |
| 206 sdkPath = getSdkDir(argv).path; | 217 sdkPath = getSdkDir(argv).path; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 226 inferStaticsFromIdentifiers: args['infer-transitively'], | 237 inferStaticsFromIdentifiers: args['infer-transitively'], |
| 227 inferInNonStableOrder: args['infer-eagerly'], | 238 inferInNonStableOrder: args['infer-eagerly'], |
| 228 onlyInferConstsAndFinalFields: args['infer-only-finals'], | 239 onlyInferConstsAndFinalFields: args['infer-only-finals'], |
| 229 nonnullableTypes: optionsToList(args['nonnullable'], | 240 nonnullableTypes: optionsToList(args['nonnullable'], |
| 230 defaultValue: TypeOptions.NONNULLABLE_TYPES), | 241 defaultValue: TypeOptions.NONNULLABLE_TYPES), |
| 231 help: args['help'], | 242 help: args['help'], |
| 232 useMockSdk: args['mock-sdk'], | 243 useMockSdk: args['mock-sdk'], |
| 233 dartSdkPath: sdkPath, | 244 dartSdkPath: sdkPath, |
| 234 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName, | 245 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName, |
| 235 orElse: () => Level.SEVERE), | 246 orElse: () => Level.SEVERE), |
| 247 emitSourceMaps: args['source-maps'], |
| 236 entryPointFile: args.rest.length == 0 ? null : args.rest.first); | 248 entryPointFile: args.rest.length == 0 ? null : args.rest.first); |
| 237 } | 249 } |
| 238 | 250 |
| 239 final ArgParser argParser = new ArgParser() | 251 final ArgParser argParser = new ArgParser() |
| 240 // resolver/checker options | 252 // resolver/checker options |
| 241 ..addFlag('allow-const-casts', | 253 ..addFlag('allow-const-casts', |
| 242 help: 'Allow casts in const contexts', defaultsTo: true) | 254 help: 'Allow casts in const contexts', defaultsTo: true) |
| 243 ..addFlag('sdk-check', | 255 ..addFlag('sdk-check', |
| 244 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) | 256 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) |
| 245 ..addFlag('mock-sdk', | 257 ..addFlag('mock-sdk', |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null) | 289 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null) |
| 278 ..addOption('package-root', | 290 ..addOption('package-root', |
| 279 abbr: 'p', | 291 abbr: 'p', |
| 280 help: 'Package root to resolve "package:" imports', | 292 help: 'Package root to resolve "package:" imports', |
| 281 defaultsTo: 'packages/') | 293 defaultsTo: 'packages/') |
| 282 ..addFlag('use-multi-package', | 294 ..addFlag('use-multi-package', |
| 283 help: 'Whether to use the multi-package resolver for "package:" imports', | 295 help: 'Whether to use the multi-package resolver for "package:" imports', |
| 284 defaultsTo: false) | 296 defaultsTo: false) |
| 285 ..addOption('package-paths', help: 'if using the multi-package resolver, ' | 297 ..addOption('package-paths', help: 'if using the multi-package resolver, ' |
| 286 'the list of directories where to look for packages.', defaultsTo: '') | 298 'the list of directories where to look for packages.', defaultsTo: '') |
| 299 ..addFlag('source-maps', |
| 300 help: 'Whether to emit source map files', defaultsTo: true) |
| 287 | 301 |
| 288 // general options | 302 // general options |
| 289 ..addFlag('help', abbr: 'h', help: 'Display this message') | 303 ..addFlag('help', abbr: 'h', help: 'Display this message') |
| 290 ..addFlag('force-compile', | 304 ..addFlag('force-compile', |
| 291 help: 'Compile code with static errors', defaultsTo: false) | 305 help: 'Compile code with static errors', defaultsTo: false) |
| 292 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe') | 306 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe') |
| 293 ..addFlag('dump-info', | 307 ..addFlag('dump-info', |
| 294 abbr: 'i', help: 'Dump summary information', defaultsTo: false) | 308 abbr: 'i', help: 'Dump summary information', defaultsTo: false) |
| 295 ..addOption('dump-info-file', | 309 ..addOption('dump-info-file', |
| 296 abbr: 'f', | 310 abbr: 'f', |
| 297 help: 'Dump info json file (requires dump-info)', | 311 help: 'Dump info json file (requires dump-info)', |
| 298 defaultsTo: null); | 312 defaultsTo: null); |
| OLD | NEW |