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

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 String outputLanguage = 'JavaScript';
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 outputLanguage = 'Dart';
102 if (!explicitOut) {
103 out = cwd.resolve('out.dart');
104 sourceMapOut = cwd.resolve('out.dart.map');
105 }
106 }
107 passThrough(argument);
108 }
109
98 handleShortOptions(String argument) { 110 handleShortOptions(String argument) {
99 var shortOptions = argument.substring(1).splitChars(); 111 var shortOptions = argument.substring(1).splitChars();
100 for (var shortOption in shortOptions) { 112 for (var shortOption in shortOptions) {
101 switch (shortOption) { 113 switch (shortOption) {
102 case 'v': 114 case 'v':
103 verbose = true; 115 verbose = true;
104 break; 116 break;
105 case 'h': 117 case 'h':
106 case '?': 118 case '?':
107 wantHelp = true; 119 wantHelp = true;
108 break; 120 break;
109 case 'c': 121 case 'c':
110 passThrough('--enable-checked-mode'); 122 passThrough('--enable-checked-mode');
111 break; 123 break;
112 default: 124 default:
113 throw 'Internal error: "$shortOption" did not match'; 125 throw 'Internal error: "$shortOption" did not match';
114 } 126 }
115 } 127 }
116 } 128 }
117 129
118 List<String> arguments = <String>[]; 130 List<String> arguments = <String>[];
119 List<OptionHandler> handlers = <OptionHandler>[ 131 List<OptionHandler> handlers = <OptionHandler>[
120 new OptionHandler('-[chv?]+', handleShortOptions), 132 new OptionHandler('-[chv?]+', handleShortOptions),
121 new OptionHandler('--throw-on-error', (_) => throwOnError = true), 133 new OptionHandler('--throw-on-error', (_) => throwOnError = true),
122 new OptionHandler('--suppress-warnings', (_) => showWarnings = false), 134 new OptionHandler('--suppress-warnings', (_) => showWarnings = false),
123 new OptionHandler('--output-type=dart|--output-type=js', passThrough), 135 new OptionHandler('--output-type=dart|--output-type=js', setOutputType),
124 new OptionHandler('--verbose', (_) => verbose = true), 136 new OptionHandler('--verbose', (_) => verbose = true),
125 new OptionHandler('--library-root=.+', setLibraryRoot), 137 new OptionHandler('--library-root=.+', setLibraryRoot),
126 new OptionHandler('--out=.+|-o.+', setOutput), 138 new OptionHandler('--out=.+|-o.+', setOutput),
127 new OptionHandler('--allow-mock-compilation', passThrough), 139 new OptionHandler('--allow-mock-compilation', passThrough),
128 new OptionHandler('--minify', passThrough), 140 new OptionHandler('--minify', passThrough),
129 new OptionHandler('--force-cut-declaration-types', passThrough), 141 new OptionHandler('--force-cut-declaration-types', passThrough),
130 // TODO(ahe): Remove the --no-colors option. 142 // TODO(ahe): Remove the --no-colors option.
131 new OptionHandler('--disable-diagnostic-colors', (_) => enableColors = false ), 143 new OptionHandler('--disable-diagnostic-colors', (_) => enableColors = false ),
132 new OptionHandler('--enable-diagnostic-colors', (_) => enableColors = true), 144 new OptionHandler('--enable-diagnostic-colors', (_) => enableColors = true),
133 new OptionHandler('--enable[_-]checked[_-]mode|--checked', 145 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. 259 // directly. In effect, we don't support truly asynchronous API.
248 String code = api.compile(uri, libraryRoot, packageRoot, provider, handler, 260 String code = api.compile(uri, libraryRoot, packageRoot, provider, handler,
249 options).value; 261 options).value;
250 if (code === null) { 262 if (code === null) {
251 fail('Error: Compilation failed.'); 263 fail('Error: Compilation failed.');
252 } 264 }
253 String sourceMapFileName = 265 String sourceMapFileName =
254 sourceMapOut.path.substring(sourceMapOut.path.lastIndexOf('/') + 1); 266 sourceMapOut.path.substring(sourceMapOut.path.lastIndexOf('/') + 1);
255 code = '$code\n//@ sourceMappingURL=${sourceMapFileName}'; 267 code = '$code\n//@ sourceMappingURL=${sourceMapFileName}';
256 writeString(out, code); 268 writeString(out, code);
257 int jsBytesWritten = code.length; 269 int bytesWritten = code.length;
258 info('compiled $dartBytesRead bytes Dart -> $jsBytesWritten bytes JS ' 270 info('compiled $dartBytesRead bytes Dart -> $bytesWritten bytes '
259 'in ${relativize(cwd, out, isWindows)}'); 271 '$outputLanguage in ${relativize(cwd, out, isWindows)}');
260 if (!explicitOut) { 272 if (!explicitOut) {
261 String input = uriPathToNative(arguments[0]); 273 String input = uriPathToNative(arguments[0]);
262 String output = relativize(cwd, out, isWindows); 274 String output = relativize(cwd, out, isWindows);
263 print('Dart file $input compiled to JavaScript: $output'); 275 print('Dart file $input compiled to $outputLanguage: $output');
264 } 276 }
265 } 277 }
266 278
267 class AbortLeg { 279 class AbortLeg {
268 final message; 280 final message;
269 AbortLeg(this.message); 281 AbortLeg(this.message);
270 toString() => 'Aborted due to --throw-on-error: $message'; 282 toString() => 'Aborted due to --throw-on-error: $message';
271 } 283 }
272 284
273 void writeString(Uri uri, String text) { 285 void writeString(Uri uri, String text) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } catch (ignored) { 400 } catch (ignored) {
389 print('Internal error: error while printing exception'); 401 print('Internal error: error while printing exception');
390 } 402 }
391 try { 403 try {
392 print(trace); 404 print(trace);
393 } finally { 405 } finally {
394 exit(253); // 253 is recognized as a crash by our test scripts. 406 exit(253); // 253 is recognized as a crash by our test scripts.
395 } 407 }
396 } 408 }
397 } 409 }
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