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

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

Issue 10961019: [dart2js] if --output-type=dart make output file out.dart and print correct info message. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
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 | no next file » | 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 bool showWarnings = true; 71 bool showWarnings = true;
72 bool verbose = false; 72 bool verbose = false;
73 Uri libraryRoot = cwd; 73 Uri libraryRoot = cwd;
74 Uri out = cwd.resolve('out.js'); 74 Uri out = cwd.resolve('out.js');
75 Uri sourceMapOut = cwd.resolve('out.js.map'); 75 Uri sourceMapOut = cwd.resolve('out.js.map');
76 Uri packageRoot = null; 76 Uri packageRoot = null;
77 List<String> options = new List<String>(); 77 List<String> options = new List<String>();
78 bool explicitOut = false; 78 bool explicitOut = false;
79 bool wantHelp = false; 79 bool wantHelp = false;
80 bool enableColors = false; 80 bool enableColors = false;
81 bool isOutputTypeDart = false;
81 82
82 passThrough(String argument) => options.add(argument); 83 passThrough(String argument) => options.add(argument);
83 84
84 setLibraryRoot(String argument) { 85 setLibraryRoot(String argument) {
85 libraryRoot = cwd.resolve(extractPath(argument)); 86 libraryRoot = cwd.resolve(extractPath(argument));
86 } 87 }
87 88
88 setPackageRoot(String argument) { 89 setPackageRoot(String argument) {
89 packageRoot = cwd.resolve(extractPath(argument)); 90 packageRoot = cwd.resolve(extractPath(argument));
90 } 91 }
91 92
92 setOutput(String argument) { 93 setOutput(String argument) {
93 explicitOut = true; 94 explicitOut = true;
94 out = cwd.resolve(nativeToUriPath(extractParameter(argument))); 95 out = cwd.resolve(nativeToUriPath(extractParameter(argument)));
95 sourceMapOut = new Uri.fromString('$out.map'); 96 sourceMapOut = new Uri.fromString('$out.map');
96 } 97 }
97 98
99 setOutputType(String argument) {
100 if (argument == '--output-type=dart') {
101 isOutputTypeDart = true;
102 out = cwd.resolve('out.dart');
ahe 2012/09/21 14:38:46 This isn't right. You will overwrite user-specifie
Roman 2012/09/21 16:36:07 added a check for explicitOut set.
103 sourceMapOut = cwd.resolve('out.dart.map');
104 }
105 passThrough(argument);
106 }
107
98 handleShortOptions(String argument) { 108 handleShortOptions(String argument) {
99 var shortOptions = argument.substring(1).splitChars(); 109 var shortOptions = argument.substring(1).splitChars();
100 for (var shortOption in shortOptions) { 110 for (var shortOption in shortOptions) {
101 switch (shortOption) { 111 switch (shortOption) {
102 case 'v': 112 case 'v':
103 verbose = true; 113 verbose = true;
104 break; 114 break;
105 case 'h': 115 case 'h':
106 case '?': 116 case '?':
107 wantHelp = true; 117 wantHelp = true;
108 break; 118 break;
109 case 'c': 119 case 'c':
110 passThrough('--enable-checked-mode'); 120 passThrough('--enable-checked-mode');
111 break; 121 break;
112 default: 122 default:
113 throw 'Internal error: "$shortOption" did not match'; 123 throw 'Internal error: "$shortOption" did not match';
114 } 124 }
115 } 125 }
116 } 126 }
117 127
118 List<String> arguments = <String>[]; 128 List<String> arguments = <String>[];
119 List<OptionHandler> handlers = <OptionHandler>[ 129 List<OptionHandler> handlers = <OptionHandler>[
120 new OptionHandler('-[chv?]+', handleShortOptions), 130 new OptionHandler('-[chv?]+', handleShortOptions),
121 new OptionHandler('--throw-on-error', (_) => throwOnError = true), 131 new OptionHandler('--throw-on-error', (_) => throwOnError = true),
122 new OptionHandler('--suppress-warnings', (_) => showWarnings = false), 132 new OptionHandler('--suppress-warnings', (_) => showWarnings = false),
123 new OptionHandler('--output-type=dart|--output-type=js', passThrough), 133 new OptionHandler('--output-type=dart|--output-type=js', setOutputType),
124 new OptionHandler('--verbose', (_) => verbose = true), 134 new OptionHandler('--verbose', (_) => verbose = true),
125 new OptionHandler('--library-root=.+', setLibraryRoot), 135 new OptionHandler('--library-root=.+', setLibraryRoot),
126 new OptionHandler('--out=.+|-o.+', setOutput), 136 new OptionHandler('--out=.+|-o.+', setOutput),
127 new OptionHandler('--allow-mock-compilation', passThrough), 137 new OptionHandler('--allow-mock-compilation', passThrough),
128 new OptionHandler('--minify', passThrough), 138 new OptionHandler('--minify', passThrough),
129 new OptionHandler('--force-cut-declaration-types', passThrough), 139 new OptionHandler('--force-cut-declaration-types', passThrough),
130 // TODO(ahe): Remove the --no-colors option. 140 // TODO(ahe): Remove the --no-colors option.
131 new OptionHandler('--disable-diagnostic-colors', (_) => enableColors = false ), 141 new OptionHandler('--disable-diagnostic-colors', (_) => enableColors = false ),
132 new OptionHandler('--enable-diagnostic-colors', (_) => enableColors = true), 142 new OptionHandler('--enable-diagnostic-colors', (_) => enableColors = true),
133 new OptionHandler('--enable[_-]checked[_-]mode|--checked', 143 new OptionHandler('--enable[_-]checked[_-]mode|--checked',
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // directly. In effect, we don't support truly asynchronous API. 257 // directly. In effect, we don't support truly asynchronous API.
248 String code = api.compile(uri, libraryRoot, packageRoot, provider, handler, 258 String code = api.compile(uri, libraryRoot, packageRoot, provider, handler,
249 options).value; 259 options).value;
250 if (code === null) { 260 if (code === null) {
251 fail('Error: Compilation failed.'); 261 fail('Error: Compilation failed.');
252 } 262 }
253 String sourceMapFileName = 263 String sourceMapFileName =
254 sourceMapOut.path.substring(sourceMapOut.path.lastIndexOf('/') + 1); 264 sourceMapOut.path.substring(sourceMapOut.path.lastIndexOf('/') + 1);
255 code = '$code\n//@ sourceMappingURL=${sourceMapFileName}'; 265 code = '$code\n//@ sourceMappingURL=${sourceMapFileName}';
256 writeString(out, code); 266 writeString(out, code);
257 int jsBytesWritten = code.length; 267 int bytesWritten = code.length;
258 info('compiled $dartBytesRead bytes Dart -> $jsBytesWritten bytes JS ' 268 String outputLang = isOutputTypeDart ? 'Dart' : 'Javascript';
Anton Muhin 2012/09/20 18:31:44 nit: Java<S>cript
ahe 2012/09/21 14:38:46 Please don't abbreviate, that is, use "language" i
Roman 2012/09/21 16:36:07 Done.
Roman 2012/09/21 16:36:07 Done.
269 info('compiled $dartBytesRead bytes Dart -> $bytesWritten bytes $outputLang '
259 'in ${relativize(cwd, out, isWindows)}'); 270 'in ${relativize(cwd, out, isWindows)}');
260 if (!explicitOut) { 271 if (!explicitOut) {
261 String input = uriPathToNative(arguments[0]); 272 String input = uriPathToNative(arguments[0]);
262 String output = relativize(cwd, out, isWindows); 273 String output = relativize(cwd, out, isWindows);
263 print('Dart file $input compiled to JavaScript: $output'); 274 print('Dart file $input compiled to $outputLang: $output');
264 } 275 }
265 } 276 }
266 277
267 class AbortLeg { 278 class AbortLeg {
268 final message; 279 final message;
269 AbortLeg(this.message); 280 AbortLeg(this.message);
270 toString() => 'Aborted due to --throw-on-error: $message'; 281 toString() => 'Aborted due to --throw-on-error: $message';
271 } 282 }
272 283
273 void writeString(Uri uri, String text) { 284 void writeString(Uri uri, String text) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } catch (ignored) { 399 } catch (ignored) {
389 print('Internal error: error while printing exception'); 400 print('Internal error: error while printing exception');
390 } 401 }
391 try { 402 try {
392 print(trace); 403 print(trace);
393 } finally { 404 } finally {
394 exit(253); // 253 is recognized as a crash by our test scripts. 405 exit(253); // 253 is recognized as a crash by our test scripts.
395 } 406 }
396 } 407 }
397 } 408 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698