Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: lib/src/options.dart

Issue 961503002: Move argument parsing, add fields for missing flags (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bin/devc.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
9
10 import 'package:args/args.dart';
11 import 'package:cli_util/cli_util.dart' show getSdkDir;
8 import 'package:dev_compiler/config.dart'; 12 import 'package:dev_compiler/config.dart';
13 import 'package:logging/logging.dart' show Level;
9 14
10 /// Options used by ddc's TypeResolver. 15 /// Options used by ddc's TypeResolver.
11 class ResolverOptions { 16 class ResolverOptions {
12 /// Whether to resolve 'package:' uris using the multi-package resolver. 17 /// Whether to resolve 'package:' uris using the multi-package resolver.
13 final bool useMultiPackage; 18 final bool useMultiPackage;
14 19
15 /// Package root when resolving 'package:' urls the standard way. 20 /// Package root when resolving 'package:' urls the standard way.
16 final String packageRoot; 21 final String packageRoot;
17 22
18 /// List of paths used for the multi-package resolver. 23 /// List of paths used for the multi-package resolver.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 100
96 /// Output directory for generated code. 101 /// Output directory for generated code.
97 final String outputDir; 102 final String outputDir;
98 103
99 /// Whether to emit Dart output (false means to emit JS output). 104 /// Whether to emit Dart output (false means to emit JS output).
100 final bool outputDart; 105 final bool outputDart;
101 106
102 /// Whether to use colors when interacting on the console. 107 /// Whether to use colors when interacting on the console.
103 final bool useColors; 108 final bool useColors;
104 109
110 /// Whether the user asked for help.
111 final bool help;
112
113 /// Whether to use a mock-sdk during compilation.
114 final bool useMockSdk;
115
116 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't
117 /// be determined
118 final String dartSdkPath;
119
120 /// Minimum log-level reported on the command-line.
121 final Level logLevel;
122
123 /// File where to start compilation from.
124 final String entryPointFile;
125
105 /// Whether to use covariant generics 126 /// Whether to use covariant generics
106 @override 127 @override
107 final bool covariantGenerics; 128 final bool covariantGenerics;
108 129
109 /// Whether to inject casts between Dart assignable types. 130 /// Whether to inject casts between Dart assignable types.
110 @override 131 @override
111 final bool relaxedCasts; 132 final bool relaxedCasts;
112 133
113 /// Whether to resolve 'package:' uris using the multi-package resolver. 134 /// Whether to resolve 'package:' uris using the multi-package resolver.
114 @override 135 @override
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 CompilerOptions({this.checkSdk: false, this.dumpInfo: false, 172 CompilerOptions({this.checkSdk: false, this.dumpInfo: false,
152 this.dumpInfoFile, this.dumpSrcDir, this.forceCompile: false, 173 this.dumpInfoFile, this.dumpSrcDir, this.forceCompile: false,
153 this.formatOutput: false, this.ignoreTypes: false, this.outputDir, 174 this.formatOutput: false, this.ignoreTypes: false, this.outputDir,
154 this.outputDart: false, this.useColors: true, 175 this.outputDart: false, this.useColors: true,
155 this.covariantGenerics: true, this.relaxedCasts: true, 176 this.covariantGenerics: true, this.relaxedCasts: true,
156 this.useMultiPackage: false, this.packageRoot: 'packages/', 177 this.useMultiPackage: false, this.packageRoot: 'packages/',
157 this.packagePaths: const [], this.inferFromOverrides: true, 178 this.packagePaths: const [], this.inferFromOverrides: true,
158 this.inferStaticsFromIdentifiers: false, 179 this.inferStaticsFromIdentifiers: false,
159 this.inferInNonStableOrder: false, 180 this.inferInNonStableOrder: false,
160 this.onlyInferConstsAndFinalFields: false, 181 this.onlyInferConstsAndFinalFields: false,
161 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES}); 182 this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false,
183 this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE,
184 this.entryPointFile: null});
162 } 185 }
186
187 /// Parses options from the command-line
188 CompilerOptions parseOptions(List<String> argv) {
189 ArgResults args = argParser.parse(argv);
190 var levelName = args['log'].toUpperCase();
191 var useColors = stdioType(stdout) == StdioType.TERMINAL;
192 var sdkPath = args['dart-sdk'];
193 if (sdkPath == null && !args['mock-sdk']) {
194 sdkPath = getSdkDir(argv).path;
195 }
196 return new CompilerOptions(
197 checkSdk: args['sdk-check'],
198 dumpInfo: args['dump-info'],
199 dumpInfoFile: args['dump-info-file'],
200 dumpSrcDir: args['dump-src-to'],
201 forceCompile: args['force-compile'],
202 formatOutput: args['dart-gen-fmt'],
203 ignoreTypes: args['ignore-types'],
204 outputDart: args['dart-gen'],
205 outputDir: args['out'],
206 covariantGenerics: args['covariant-generics'],
207 relaxedCasts: args['relaxed-casts'],
208 useColors: useColors,
209 useMultiPackage: args['use-multi-package'],
210 packageRoot: args['package-root'],
211 packagePaths: args['package-paths'].split(','),
212 inferFromOverrides: args['infer-from-overrides'],
213 inferStaticsFromIdentifiers: args['infer-transitively'],
214 inferInNonStableOrder: args['infer-eagerly'],
215 onlyInferConstsAndFinalFields: args['infer-only-finals'],
216 nonnullableTypes: optionsToList(args['nonnullable'],
217 defaultValue: TypeOptions.NONNULLABLE_TYPES),
218 help: args['help'],
219 useMockSdk: args['mock-sdk'],
220 dartSdkPath: sdkPath,
221 logLevel: Level.LEVELS.firstWhere((Level l) => l.name == levelName,
222 orElse: () => Level.SEVERE),
223 entryPointFile: args.rest.length == 0 ? null : args.rest.first);
224 }
225
226 final ArgParser argParser = new ArgParser()
227 // resolver/checker options
228 ..addFlag(
229 'sdk-check', abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false)
230 ..addFlag('mock-sdk',
231 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false)
232 ..addFlag('covariant-generics',
233 help: 'Use covariant generics', defaultsTo: true)
234 ..addFlag('ignore-types',
235 help: 'Ignore types during codegen', defaultsTo: false)
236 ..addFlag('relaxed-casts',
237 help: 'Cast between Dart assignable types', defaultsTo: true)
238 ..addOption('nonnullable',
239 abbr: 'n',
240 help: 'Comma separated string of non-nullable types',
241 defaultsTo: null)
242 ..addFlag('infer-from-overrides',
243 help: 'Infer unspecified types of fields and return types from '
244 'definitions in supertypes', defaultsTo: true)
245 ..addFlag('infer-transitively',
246 help: 'Infer consts/fields from definitions in other libraries',
247 defaultsTo: false)
248 ..addFlag('infer-only-finals',
249 help: 'Do not infer non-const or non-final fields', defaultsTo: false)
250 ..addFlag('infer-eagerly',
251 help: 'experimental: allows a non-stable order of transitive inference on'
252 ' consts and fields. This is used to test for possible inference with a '
253 'proper implementation in the future.', defaultsTo: false)
254
255 // input/output options
256 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null)
257 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null)
258 ..addFlag('dart-gen',
259 abbr: 'd', help: 'Generate dart output', defaultsTo: false)
260 ..addFlag('dart-gen-fmt',
261 help: 'Generate readable dart output', defaultsTo: true)
262 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null)
263 ..addOption('package-root',
264 abbr: 'p',
265 help: 'Package root to resolve "package:" imports',
266 defaultsTo: 'packages/')
267 ..addFlag('use-multi-package',
268 help: 'Whether to use the multi-package resolver for "package:" imports',
269 defaultsTo: false)
270 ..addOption('package-paths', help: 'if using the multi-package resolver, '
271 'the list of directories where to look for packages.', defaultsTo: '')
272
273 // general options
274 ..addFlag('help', abbr: 'h', help: 'Display this message')
275 ..addFlag('force-compile',
276 help: 'Compile code with static errors', defaultsTo: false)
277 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe')
278 ..addFlag('dump-info',
279 abbr: 'i', help: 'Dump summary information', defaultsTo: false)
280 ..addOption('dump-info-file',
281 abbr: 'f',
282 help: 'Dump info json file (requires dump-info)',
283 defaultsTo: null);
OLDNEW
« no previous file with comments | « bin/devc.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698