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

Side by Side Diff: lib/compiler/implementation/dart2js.dart

Issue 10377023: Using arg parsing lib for dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update with review feedback. Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « lib/args/args.dart ('k') | tests/lib/args/args_test.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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #library('dart2js'); 5 #library('dart2js');
6 6
7 #import('dart:io'); 7 #import('dart:io');
8 #import('dart:uri'); 8 #import('dart:uri');
9 #import('dart:utf'); 9 #import('dart:utf');
10 10
11 #import('../../args/args.dart');
11 #import('../compiler.dart', prefix: 'api'); 12 #import('../compiler.dart', prefix: 'api');
12 #import('colors.dart', prefix: 'colors'); 13 #import('colors.dart', prefix: 'colors');
13 #import('source_file.dart'); 14 #import('source_file.dart');
14 #import('filenames.dart'); 15 #import('filenames.dart');
15 #import('util/uri_extras.dart'); 16 #import('util/uri_extras.dart');
16 17
17 final String LIBRARY_ROOT = '../../../..'; 18 final String LIBRARY_ROOT = '../../../..';
18 19
19 void compile(List<String> argv) { 20 ArgResults parseCommandLine(List<String> argv) {
21 // Set up and parse the command line arguments.
22 ArgParser parser = new ArgParser(usage: 'dart2js [options...] <dart file>');
23 parser.addFlag('throw-on-error',
24 help: 'Throw an exception if a fatal error occurs.');
25 parser.addFlag('suppress-warnings',
26 help: 'Display static warnings');
27 parser.addFlag('verbose', abbr: 'v',
28 help: 'Display verbose output');
29 parser.addFlag('allow-mock-compilation');
30 parser.addFlag('colors', defaultsTo: true,
31 help: 'Use color when displaying output');
32 parser.addOption('library-root',
33 help: 'Path to core lib directory');
34 parser.addOption('out', abbr: 'o',
35 help: 'Output JavaScript file to create',
36 defaultsTo: 'out.js');
37
38 return parser.process(argv);
39 }
40
41 void compile(ArgResults args) {
42 colors.enabled = args['colors'];
43 bool throwOnError = args['throw-on-error'];
44 bool showWarnings = !args['suppress-warnings'];
45 bool verbose = args['verbose'];
46
20 Uri cwd = getCurrentDirectory(); 47 Uri cwd = getCurrentDirectory();
21 bool throwOnError = false;
22 bool showWarnings = true;
23 bool verbose = false;
24 Uri libraryRoot = cwd; 48 Uri libraryRoot = cwd;
25 Uri out = cwd.resolve('out.js'); 49 if (args['library-root'] != null) {
50 String path = nativeToUriPath(args['library-root']);
51 if (!path.endsWith("/")) path = "$path/";
52 libraryRoot = cwd.resolve(path);
53 }
54
55 Uri out = cwd.resolve(args['out']);
56
26 List<String> options = new List<String>(); 57 List<String> options = new List<String>();
58 if (args['allow-mock-compilation']) {
59 options.add('--allow-mock-compilation');
60 }
27 61
28 List<String> arguments = <String>[]; 62 List<String> arguments = args.rest.map(nativeToUriPath);
29 for (String argument in argv) { 63
30 if ('--throw-on-error' == argument) {
31 throwOnError = true;
32 } else if ('--suppress-warnings' == argument) {
33 showWarnings = false;
34 } else if ('--verbose' == argument) {
35 verbose = true;
36 } else if (argument.startsWith('--library-root=')) {
37 String path =
38 nativeToUriPath(argument.substring(argument.indexOf('=') + 1));
39 if (!path.endsWith("/")) path = "$path/";
40 libraryRoot = cwd.resolve(path);
41 } else if (argument.startsWith('--out=')) {
42 String path =
43 nativeToUriPath(argument.substring(argument.indexOf('=') + 1));
44 out = cwd.resolve(path);
45 } else if ('--allow-mock-compilation' == argument) {
46 options.add(argument);
47 } else if ('--no-colors' == argument) {
48 colors.enabled = false;
49 } else if ('--enable-checked-mode' == argument) {
50 options.add(argument);
51 } else if (argument.startsWith('-')) {
52 fail('Unknown option $argument.');
53 } else {
54 arguments.add(nativeToUriPath(argument));
55 }
56 }
57 if (arguments.isEmpty()) { 64 if (arguments.isEmpty()) {
58 fail('No file to compile.'); 65 fail('No file to compile.');
59 } 66 }
67
60 if (arguments.length > 1) { 68 if (arguments.length > 1) {
61 var extra = arguments.getRange(1, arguments.length - 1); 69 var extra = arguments.getRange(1, arguments.length - 1);
62 fail('Extra arguments: $extra.'); 70 fail('Extra arguments: $extra.');
63 } 71 }
64 72
65 Map<String, SourceFile> sourceFiles = <SourceFile>{}; 73 Map<String, SourceFile> sourceFiles = <SourceFile>{};
66 int dartBytesRead = 0; 74 int dartBytesRead = 0;
67 75
68 Future<String> provider(Uri uri) { 76 Future<String> provider(Uri uri) {
69 if (uri.scheme != 'file') { 77 if (uri.scheme != 'file') {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 146
139 void fail(String message) { 147 void fail(String message) {
140 print(message); 148 print(message);
141 exit(1); 149 exit(1);
142 } 150 }
143 151
144 void compilerMain(Options options) { 152 void compilerMain(Options options) {
145 var root = uriPathToNative("/$LIBRARY_ROOT"); 153 var root = uriPathToNative("/$LIBRARY_ROOT");
146 List<String> argv = ['--library-root=${options.script}$root']; 154 List<String> argv = ['--library-root=${options.script}$root'];
147 argv.addAll(options.arguments); 155 argv.addAll(options.arguments);
148 compile(argv); 156 ArgResults results = parseCommandLine(argv);
157 compile(results);
149 } 158 }
150 159
151 void main() { 160 void main() {
152 try { 161 try {
153 compilerMain(new Options()); 162 compilerMain(new Options());
154 } catch (var exception, var trace) { 163 } catch (var exception, var trace) {
155 try { 164 try {
156 print('Internal error: $exception'); 165 print('Internal error: $exception');
157 } catch (var ignored) { 166 } catch (var ignored) {
158 print('Internal error: error while printing exception'); 167 print('Internal error: error while printing exception');
159 } 168 }
160 try { 169 try {
161 print(trace); 170 print(trace);
162 } finally { 171 } finally {
163 exit(253); // 253 is recognized as a crash by our test scripts. 172 exit(253); // 253 is recognized as a crash by our test scripts.
164 } 173 }
165 } 174 }
166 } 175 }
OLDNEW
« no previous file with comments | « lib/args/args.dart ('k') | tests/lib/args/args_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698