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

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: 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 void compile(List<String> argv) {
21 // Set up and parse the command line arguments.
ahe 2012/05/07 12:49:06 Could you move the parser construction into a sepa
Bob Nystrom 2012/05/07 18:22:05 Done.
22 ArgParser parser = new ArgParser(usage: 'dart2js [options...] <entrypoint>');
kasperl 2012/05/07 11:49:35 <entrypoint> -> <input>?
ahe 2012/05/07 12:49:06 How about <dart file> or <file>?
Bob Nystrom 2012/05/07 18:22:05 <input entrypoint dart file>? ;) Changed to <dart
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',
kasperl 2012/05/07 11:49:35 I'd prefer it if abbr wasn't abbreviated (feedback
Bob Nystrom 2012/05/07 18:22:05 I'm not crazy about it either. I think I'll change
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');
kasperl 2012/05/07 11:49:35 Indentation.
Bob Nystrom 2012/05/07 18:22:05 Done.
37
38 ArgResults results = parser.process(argv);
39
40 colors.enabled = results['colors'];
41 bool throwOnError = results['throw-on-error'];
42 bool showWarnings = !results['suppress-warnings'];
43 bool verbose = results['verbose'];
44
20 Uri cwd = getCurrentDirectory(); 45 Uri cwd = getCurrentDirectory();
21 bool throwOnError = false;
22 bool showWarnings = true;
23 bool verbose = false;
24 Uri libraryRoot = cwd; 46 Uri libraryRoot = cwd;
25 Uri out = cwd.resolve('out.js'); 47 if (results['library-root'] != null) {
48 String path = nativeToUriPath(results['library-root']);
49 if (!path.endsWith("/")) path = "$path/";
50 libraryRoot = cwd.resolve(path);
51 }
52
53 Uri out = cwd.resolve(results['out']);
54
26 List<String> options = new List<String>(); 55 List<String> options = new List<String>();
56 if (results['allow-mock-compilation']) {
57 options.add('--allow-mock-compilation');
58 }
27 59
28 List<String> arguments = <String>[]; 60 List<String> arguments = results.rest.map(nativeToUriPath);
29 for (String argument in argv) { 61
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 (argument.startsWith('-')) {
50 fail('Unknown option $argument.');
51 } else {
52 arguments.add(nativeToUriPath(argument));
53 }
54 }
55 if (arguments.isEmpty()) { 62 if (arguments.isEmpty()) {
56 fail('No file to compile.'); 63 fail('No file to compile.');
57 } 64 }
65
58 if (arguments.length > 1) { 66 if (arguments.length > 1) {
59 var extra = arguments.getRange(1, arguments.length - 1); 67 var extra = arguments.getRange(1, arguments.length - 1);
60 fail('Extra arguments: $extra.'); 68 fail('Extra arguments: $extra.');
61 } 69 }
62 70
63 Map<String, SourceFile> sourceFiles = <SourceFile>{}; 71 Map<String, SourceFile> sourceFiles = <SourceFile>{};
64 int dartBytesRead = 0; 72 int dartBytesRead = 0;
65 73
66 Future<String> provider(Uri uri) { 74 Future<String> provider(Uri uri) {
67 if (uri.scheme != 'file') { 75 if (uri.scheme != 'file') {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } catch (var ignored) { 163 } catch (var ignored) {
156 print('Internal error: error while printing exception'); 164 print('Internal error: error while printing exception');
157 } 165 }
158 try { 166 try {
159 print(trace); 167 print(trace);
160 } finally { 168 } finally {
161 exit(253); // 253 is recognized as a crash by our test scripts. 169 exit(253); // 253 is recognized as a crash by our test scripts.
162 } 170 }
163 } 171 }
164 } 172 }
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