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

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

Issue 10383049: Revert "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');
12 #import('../compiler.dart', prefix: 'api'); 11 #import('../compiler.dart', prefix: 'api');
13 #import('colors.dart', prefix: 'colors'); 12 #import('colors.dart', prefix: 'colors');
14 #import('source_file.dart'); 13 #import('source_file.dart');
15 #import('filenames.dart'); 14 #import('filenames.dart');
16 #import('util/uri_extras.dart'); 15 #import('util/uri_extras.dart');
17 16
18 final String LIBRARY_ROOT = '../../../..'; 17 final String LIBRARY_ROOT = '../../../..';
19 18
20 ArgResults parseCommandLine(List<String> argv) { 19 void compile(List<String> argv) {
21 // Set up and parse the command line arguments. 20 Uri cwd = getCurrentDirectory();
22 ArgParser parser = new ArgParser(usage: 'dart2js [options...] <dart file>'); 21 bool throwOnError = false;
23 parser.addFlag('throw-on-error', 22 bool showWarnings = true;
24 help: 'Throw an exception if a fatal error occurs.'); 23 bool verbose = false;
25 parser.addFlag('suppress-warnings', 24 Uri libraryRoot = cwd;
26 help: 'Display static warnings'); 25 Uri out = cwd.resolve('out.js');
27 parser.addFlag('verbose', abbr: 'v', 26 List<String> options = new List<String>();
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 27
38 return parser.process(argv); 28 List<String> arguments = <String>[];
39 } 29 for (String argument in argv) {
40 30 if ('--throw-on-error' == argument) {
41 void compile(ArgResults args) { 31 throwOnError = true;
42 colors.enabled = args['colors']; 32 } else if ('--suppress-warnings' == argument) {
43 bool throwOnError = args['throw-on-error']; 33 showWarnings = false;
44 bool showWarnings = !args['suppress-warnings']; 34 } else if ('--verbose' == argument) {
45 bool verbose = args['verbose']; 35 verbose = true;
46 36 } else if (argument.startsWith('--library-root=')) {
47 Uri cwd = getCurrentDirectory(); 37 String path =
48 Uri libraryRoot = cwd; 38 nativeToUriPath(argument.substring(argument.indexOf('=') + 1));
49 if (args['library-root'] != null) { 39 if (!path.endsWith("/")) path = "$path/";
50 String path = nativeToUriPath(args['library-root']); 40 libraryRoot = cwd.resolve(path);
51 if (!path.endsWith("/")) path = "$path/"; 41 } else if (argument.startsWith('--out=')) {
52 libraryRoot = cwd.resolve(path); 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 }
53 } 56 }
54
55 Uri out = cwd.resolve(args['out']);
56
57 List<String> options = new List<String>();
58 if (args['allow-mock-compilation']) {
59 options.add('--allow-mock-compilation');
60 }
61
62 List<String> arguments = args.rest.map(nativeToUriPath);
63
64 if (arguments.isEmpty()) { 57 if (arguments.isEmpty()) {
65 fail('No file to compile.'); 58 fail('No file to compile.');
66 } 59 }
67
68 if (arguments.length > 1) { 60 if (arguments.length > 1) {
69 var extra = arguments.getRange(1, arguments.length - 1); 61 var extra = arguments.getRange(1, arguments.length - 1);
70 fail('Extra arguments: $extra.'); 62 fail('Extra arguments: $extra.');
71 } 63 }
72 64
73 Map<String, SourceFile> sourceFiles = <SourceFile>{}; 65 Map<String, SourceFile> sourceFiles = <SourceFile>{};
74 int dartBytesRead = 0; 66 int dartBytesRead = 0;
75 67
76 Future<String> provider(Uri uri) { 68 Future<String> provider(Uri uri) {
77 if (uri.scheme != 'file') { 69 if (uri.scheme != 'file') {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 138
147 void fail(String message) { 139 void fail(String message) {
148 print(message); 140 print(message);
149 exit(1); 141 exit(1);
150 } 142 }
151 143
152 void compilerMain(Options options) { 144 void compilerMain(Options options) {
153 var root = uriPathToNative("/$LIBRARY_ROOT"); 145 var root = uriPathToNative("/$LIBRARY_ROOT");
154 List<String> argv = ['--library-root=${options.script}$root']; 146 List<String> argv = ['--library-root=${options.script}$root'];
155 argv.addAll(options.arguments); 147 argv.addAll(options.arguments);
156 ArgResults results = parseCommandLine(argv); 148 compile(argv);
157 compile(results);
158 } 149 }
159 150
160 void main() { 151 void main() {
161 try { 152 try {
162 compilerMain(new Options()); 153 compilerMain(new Options());
163 } catch (var exception, var trace) { 154 } catch (var exception, var trace) {
164 try { 155 try {
165 print('Internal error: $exception'); 156 print('Internal error: $exception');
166 } catch (var ignored) { 157 } catch (var ignored) {
167 print('Internal error: error while printing exception'); 158 print('Internal error: error while printing exception');
168 } 159 }
169 try { 160 try {
170 print(trace); 161 print(trace);
171 } finally { 162 } finally {
172 exit(253); // 253 is recognized as a crash by our test scripts. 163 exit(253); // 253 is recognized as a crash by our test scripts.
173 } 164 }
174 } 165 }
175 } 166 }
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