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

Side by Side Diff: bin/devc.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, 10 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 | « no previous file | lib/src/options.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 2 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
3 // for details. All rights reserved. Use of this source code is governed by a 3 // for details. All rights reserved. Use of this source code is governed by a
4 // BSD-style license that can be found in the LICENSE file. 4 // BSD-style license that can be found in the LICENSE file.
5 5
6 /// Command line tool to run the checker on a Dart program. 6 /// Command line tool to run the checker on a Dart program.
7 library ddc.bin.checker; 7 library ddc.bin.checker;
8 8
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:args/args.dart';
12 import 'package:cli_util/cli_util.dart' show getSdkDir;
13 import 'package:logging/logging.dart' show Logger, Level;
14
15 import 'package:dev_compiler/config.dart';
16 import 'package:dev_compiler/devc.dart'; 11 import 'package:dev_compiler/devc.dart';
17 import 'package:dev_compiler/src/checker/dart_sdk.dart' show mockSdkSources; 12 import 'package:dev_compiler/src/checker/dart_sdk.dart' show mockSdkSources;
18 import 'package:dev_compiler/src/checker/resolver.dart' show TypeResolver; 13 import 'package:dev_compiler/src/checker/resolver.dart' show TypeResolver;
19 import 'package:dev_compiler/src/options.dart'; 14 import 'package:dev_compiler/src/options.dart';
20 15
21 final ArgParser argParser = new ArgParser()
22 ..addFlag(
23 'covariant-generics', help: 'Use covariant generics', defaultsTo: true)
24 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null)
25 ..addFlag('dart-gen',
26 abbr: 'd', help: 'Generate dart output', defaultsTo: false)
27 ..addFlag('dart-gen-fmt',
28 help: 'Generate readable dart output', defaultsTo: true)
29 ..addFlag('dump-info',
30 abbr: 'i', help: 'Dump summary information', defaultsTo: false)
31 ..addOption('dump-info-file',
32 abbr: 'f',
33 help: 'Dump info json file (requires dump-info)',
34 defaultsTo: null)
35 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null)
36 ..addFlag('force-compile',
37 help: 'Compile code with static errors', defaultsTo: false)
38 ..addFlag('help', abbr: 'h', help: 'Display this message')
39 ..addFlag('ignore-types',
40 help: 'Ignore types during codegen', defaultsTo: false)
41 ..addOption('log', abbr: 'l', help: 'Logging level', defaultsTo: 'severe')
42 ..addFlag('mock-sdk',
43 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false)
44 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null)
45 ..addFlag('relaxed-casts',
46 help: 'Cast between Dart assignable types', defaultsTo: true)
47 ..addOption('package-root',
48 abbr: 'p',
49 help: 'Package root to resolve "package:" imports',
50 defaultsTo: 'packages/')
51 ..addFlag('use-multi-package',
52 help: 'Whether to use the multi-package resolver for "package:" imports',
53 defaultsTo: false)
54 ..addOption('nonnullable',
55 abbr: 'n',
56 help: 'Comma separated string of non-nullable types',
57 defaultsTo: null)
58 ..addOption('package-paths', help: 'if using the multi-package resolver, '
59 'the list of directories where to look for packages.', defaultsTo: '')
60 ..addFlag('sdk-check',
61 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false)
62 ..addFlag('infer-from-overrides',
63 help: 'Infer unspecified types of fields and return types from '
64 'definitions in supertypes', defaultsTo: true)
65 ..addFlag('infer-transitively',
66 help: 'Infer consts/fields from definitions in other libraries',
67 defaultsTo: false)
68 ..addFlag('infer-only-finals',
69 help: 'Do not infer non-const or non-final fields', defaultsTo: false)
70 ..addFlag('infer-eagerly',
71 help: 'experimental: allows a non-stable order of transitive inference on'
72 ' consts and fields. This is used to test for possible inference with a '
73 'proper implementation in the future.', defaultsTo: false);
74
75 void _showUsageAndExit() { 16 void _showUsageAndExit() {
76 print('usage: dartdevc [<options>] <file.dart>\n'); 17 print('usage: dartdevc [<options>] <file.dart>\n');
77 print('<file.dart> is a single Dart file to process.\n'); 18 print('<file.dart> is a single Dart file to process.\n');
78 print('<options> include:\n'); 19 print('<options> include:\n');
79 print(argParser.usage); 20 print(argParser.usage);
80 exit(1); 21 exit(1);
81 } 22 }
82 23
83 void main(List<String> argv) { 24 void main(List<String> args) {
84 ArgResults args = argParser.parse(argv); 25 var options = parseOptions(args);
85 if (args['help']) _showUsageAndExit(); 26 if (options.help) _showUsageAndExit();
86 27
87 bool shouldMockSdk = args['mock-sdk']; 28 if (!options.useMockSdk && options.dartSdkPath == null) {
88 String dartSdkPath; 29 print('Could not automatically find dart sdk path.');
89 if (!shouldMockSdk) { 30 print('Please pass in explicitly: --dart-sdk <path>');
90 var sdkDir = getSdkDir(argv); 31 exit(1);
91 if (sdkDir == null) {
92 print('Could not automatically find dart sdk path.');
93 print('Please pass in explicitly: --dart-sdk <path>');
94 exit(1);
95 }
96 dartSdkPath = sdkDir.path;
97 } 32 }
98 33
99 if (args.rest.length == 0) { 34 if (options.entryPointFile == null) {
100 print('Expected filename.'); 35 print('Expected filename.');
101 _showUsageAndExit(); 36 _showUsageAndExit();
102 } 37 }
103 38
104 String levelName = args['log'].toUpperCase(); 39 if (!options.dumpInfo) setupLogger(options.logLevel, print);
105 Level level = Level.LEVELS.firstWhere((Level l) => l.name == levelName,
106 orElse: () => Level.SEVERE);
107 var useColors = stdioType(stdout) == StdioType.TERMINAL;
108 if (!args['dump-info']) setupLogger(level, print);
109 40
110 var options = new CompilerOptions( 41 var typeResolver = options.useMockSdk
111 checkSdk: args['sdk-check'],
112 dumpInfo: args['dump-info'],
113 dumpInfoFile: args['dump-info-file'],
114 dumpSrcDir: args['dump-src-to'],
115 forceCompile: args['force-compile'],
116 formatOutput: args['dart-gen-fmt'],
117 ignoreTypes: args['ignore-types'],
118 outputDart: args['dart-gen'],
119 outputDir: args['out'],
120 covariantGenerics: args['covariant-generics'],
121 relaxedCasts: args['relaxed-casts'],
122 useColors: useColors,
123 useMultiPackage: args['use-multi-package'],
124 packageRoot: args['package-root'],
125 packagePaths: args['package-paths'].split(','),
126 inferFromOverrides: args['infer-from-overrides'],
127 inferStaticsFromIdentifiers: args['infer-transitively'],
128 inferInNonStableOrder: args['infer-eagerly'],
129 onlyInferConstsAndFinalFields: args['infer-only-finals'],
130 nonnullableTypes: optionsToList(args['nonnullable'],
131 defaultValue: TypeOptions.NONNULLABLE_TYPES));
132
133 var typeResolver = shouldMockSdk
134 ? new TypeResolver.fromMock(mockSdkSources, options) 42 ? new TypeResolver.fromMock(mockSdkSources, options)
135 : new TypeResolver.fromDir(dartSdkPath, options); 43 : new TypeResolver.fromDir(options.dartSdkPath, options);
136 var filename = args.rest.first; 44 var result = compile(options.entryPointFile, typeResolver, options);
137 var result = compile(filename, typeResolver, options);
138 exit(result.failure ? 1 : 0); 45 exit(result.failure ? 1 : 0);
139 } 46 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698