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

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

Issue 10910006: Improve detection of when to use colors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 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 | « no previous file | dart/utils/compiler/build_helper.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
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 bool throwOnError = false; 69 bool throwOnError = false;
70 bool showWarnings = true; 70 bool showWarnings = true;
71 bool verbose = false; 71 bool verbose = false;
72 Uri libraryRoot = cwd; 72 Uri libraryRoot = cwd;
73 Uri out = cwd.resolve('out.js'); 73 Uri out = cwd.resolve('out.js');
74 Uri sourceMapOut = cwd.resolve('out.js.map'); 74 Uri sourceMapOut = cwd.resolve('out.js.map');
75 Uri packageRoot = null; 75 Uri packageRoot = null;
76 List<String> options = new List<String>(); 76 List<String> options = new List<String>();
77 bool explicitOut = false; 77 bool explicitOut = false;
78 bool wantHelp = false; 78 bool wantHelp = false;
79 bool enableColors = true; 79 bool enableColors = false;
80 80
81 passThrough(String argument) => options.add(argument); 81 passThrough(String argument) => options.add(argument);
82 82
83 setLibraryRoot(String argument) { 83 setLibraryRoot(String argument) {
84 libraryRoot = cwd.resolve(extractPath(argument)); 84 libraryRoot = cwd.resolve(extractPath(argument));
85 } 85 }
86 86
87 setPackageRoot(String argument) { 87 setPackageRoot(String argument) {
88 packageRoot = cwd.resolve(extractPath(argument)); 88 packageRoot = cwd.resolve(extractPath(argument));
89 } 89 }
(...skipping 28 matching lines...) Expand all
118 List<OptionHandler> handlers = <OptionHandler>[ 118 List<OptionHandler> handlers = <OptionHandler>[
119 new OptionHandler('-[chv?]+', handleShortOptions), 119 new OptionHandler('-[chv?]+', handleShortOptions),
120 new OptionHandler('--throw-on-error', (_) => throwOnError = true), 120 new OptionHandler('--throw-on-error', (_) => throwOnError = true),
121 new OptionHandler('--suppress-warnings', (_) => showWarnings = false), 121 new OptionHandler('--suppress-warnings', (_) => showWarnings = false),
122 new OptionHandler('--output-type=dart|--output-type=js', passThrough), 122 new OptionHandler('--output-type=dart|--output-type=js', passThrough),
123 new OptionHandler('--verbose', (_) => verbose = true), 123 new OptionHandler('--verbose', (_) => verbose = true),
124 new OptionHandler('--library-root=.+', setLibraryRoot), 124 new OptionHandler('--library-root=.+', setLibraryRoot),
125 new OptionHandler('--out=.+|-o.+', setOutput), 125 new OptionHandler('--out=.+|-o.+', setOutput),
126 new OptionHandler('--allow-mock-compilation', passThrough), 126 new OptionHandler('--allow-mock-compilation', passThrough),
127 new OptionHandler('--minify', passThrough), 127 new OptionHandler('--minify', passThrough),
128 // TODO(ahe): Remove the --no-colors option.
128 new OptionHandler('--no-colors', (_) => enableColors = false), 129 new OptionHandler('--no-colors', (_) => enableColors = false),
130 new OptionHandler('--colors', (_) => enableColors = true),
129 new OptionHandler('--enable[_-]checked[_-]mode|--checked', 131 new OptionHandler('--enable[_-]checked[_-]mode|--checked',
130 (_) => passThrough('--enable-checked-mode')), 132 (_) => passThrough('--enable-checked-mode')),
131 new OptionHandler(@'--help|/\?|/h', (_) => wantHelp = true), 133 new OptionHandler(@'--help|/\?|/h', (_) => wantHelp = true),
132 new OptionHandler(@'--package-root=.+|-p.+', setPackageRoot), 134 new OptionHandler(@'--package-root=.+|-p.+', setPackageRoot),
133 // The following two options must come last. 135 // The following two options must come last.
134 new OptionHandler('-.*', (String argument) { 136 new OptionHandler('-.*', (String argument) {
135 helpAndFail('Error: Unknown option "$argument".'); 137 helpAndFail('Error: Unknown option "$argument".');
136 }), 138 }),
137 new OptionHandler('.*', (String argument) { 139 new OptionHandler('.*', (String argument) {
138 arguments.add(nativeToUriPath(argument)); 140 arguments.add(nativeToUriPath(argument));
(...skipping 26 matching lines...) Expand all
165 throw 'Error: Cannot read "${relativize(cwd, uri)}" (${ex.osError}).'; 167 throw 'Error: Cannot read "${relativize(cwd, uri)}" (${ex.osError}).';
166 } 168 }
167 dartBytesRead += source.length; 169 dartBytesRead += source.length;
168 sourceFiles[uri.toString()] = 170 sourceFiles[uri.toString()] =
169 new SourceFile(relativize(cwd, uri), source); 171 new SourceFile(relativize(cwd, uri), source);
170 return new Future.immediate(source); 172 return new Future.immediate(source);
171 } 173 }
172 174
173 void info(var message, [api.Diagnostic kind = api.Diagnostic.VERBOSE_INFO]) { 175 void info(var message, [api.Diagnostic kind = api.Diagnostic.VERBOSE_INFO]) {
174 if (!verbose && kind === api.Diagnostic.VERBOSE_INFO) return; 176 if (!verbose && kind === api.Diagnostic.VERBOSE_INFO) return;
175 print('${colors.green("info:")} $message'); 177 if (enableColors) {
178 print('${colors.green("info:")} $message');
179 } else {
180 print('info: $message');
181 }
176 } 182 }
177 183
178 bool isAborting = false; 184 bool isAborting = false;
179 185
180 final int FATAL = api.Diagnostic.CRASH.ordinal | api.Diagnostic.ERROR.ordinal; 186 final int FATAL = api.Diagnostic.CRASH.ordinal | api.Diagnostic.ERROR.ordinal;
181 final int INFO = 187 final int INFO =
182 api.Diagnostic.INFO.ordinal | api.Diagnostic.VERBOSE_INFO.ordinal; 188 api.Diagnostic.INFO.ordinal | api.Diagnostic.VERBOSE_INFO.ordinal;
183 189
184 void handler(Uri uri, int begin, int end, String message, 190 void handler(Uri uri, int begin, int end, String message,
185 api.Diagnostic kind) { 191 api.Diagnostic kind) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 290 }
285 291
286 void compilerMain(Options options) { 292 void compilerMain(Options options) {
287 var root = uriPathToNative("/$LIBRARY_ROOT"); 293 var root = uriPathToNative("/$LIBRARY_ROOT");
288 List<String> argv = ['--library-root=${options.script}$root']; 294 List<String> argv = ['--library-root=${options.script}$root'];
289 argv.addAll(options.arguments); 295 argv.addAll(options.arguments);
290 compile(argv); 296 compile(argv);
291 } 297 }
292 298
293 void help() { 299 void help() {
294 // This message should be no longer than 22 lines. The default 300 // This message should be no longer than 20 lines. The default
295 // terminal size normally 80x24. Two lines are used for the prompts 301 // terminal size normally 80x24. Two lines are used for the prompts
296 // before and after running the compiler. 302 // before and after running the compiler. Another two lines may be
303 // used to print an error message.
297 print(''' 304 print('''
298 Usage: dart2js [options] dartfile 305 Usage: dart2js [options] dartfile
299 306
300 Compiles Dart to JavaScript. 307 Compiles Dart to JavaScript.
301 308
302 Common options: 309 Common options:
303 -o<file> Generate the output into <file>. 310 -o<file> Generate the output into <file>.
304 -c Insert runtime type checks and enable assertions (checked mode). 311 -c Insert runtime type checks and enable assertions (checked mode).
305 -h Display this message (add -v for information about all options).'''); 312 -h Display this message (add -v for information about all options).''');
306 } 313 }
(...skipping 19 matching lines...) Expand all
326 333
327 -p<path>, --package-root=<path> 334 -p<path>, --package-root=<path>
328 Where to find packages, that is, "package:..." imports. 335 Where to find packages, that is, "package:..." imports.
329 336
330 --minify 337 --minify
331 Generate minified output. 338 Generate minified output.
332 339
333 --suppress-warnings 340 --suppress-warnings
334 Do not display any warnings. 341 Do not display any warnings.
335 342
336 --no-colors 343 --colors
337 Do not add colors to diagnostic messages. 344 Add colors to diagnostic messages.
338 345
339 The following options are only used for compiler development and may 346 The following options are only used for compiler development and may
340 be removed in a future version: 347 be removed in a future version:
341 348
342 --output-type=dart 349 --output-type=dart
343 Output Dart code instead of JavaScript. 350 Output Dart code instead of JavaScript.
344 351
345 --throw-on-error 352 --throw-on-error
346 Throw an exception if a compile-time error is detected. 353 Throw an exception if a compile-time error is detected.
347 354
(...skipping 29 matching lines...) Expand all
377 } catch (ignored) { 384 } catch (ignored) {
378 print('Internal error: error while printing exception'); 385 print('Internal error: error while printing exception');
379 } 386 }
380 try { 387 try {
381 print(trace); 388 print(trace);
382 } finally { 389 } finally {
383 exit(253); // 253 is recognized as a crash by our test scripts. 390 exit(253); // 253 is recognized as a crash by our test scripts.
384 } 391 }
385 } 392 }
386 } 393 }
OLDNEW
« no previous file with comments | « no previous file | dart/utils/compiler/build_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698