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

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

Issue 10151014: Run dart2js directly from test.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 8 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
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('../compiler.dart', prefix: 'api'); 11 #import('../compiler.dart', prefix: 'api');
12 #import('colors.dart'); 12 #import('colors.dart');
13 #import('source_file.dart'); 13 #import('source_file.dart');
14 #import('filenames.dart'); 14 #import('filenames.dart');
15 #import('util/uri_extras.dart'); 15 #import('util/uri_extras.dart');
16 16
17 void compile(List<String> argv) { 17 void compile(List<String> argv) {
18 Uri cwd = getCurrentDirectory(); 18 Uri cwd = getCurrentDirectory();
19 bool throwOnError = false; 19 bool throwOnError = false;
20 bool showWarnings = true; 20 bool showWarnings = true;
21 bool verbose = false; 21 bool verbose = false;
22 Uri libraryRoot = cwd; 22 Uri libraryRoot = cwd;
23 Uri out = cwd.resolve('out.js'); 23 Uri out = cwd.resolve('out.js');
24 List<String> options = new List<String>();
24 25
25 List<String> arguments = <String>[]; 26 List<String> arguments = <String>[];
26 for (String argument in argv) { 27 for (String argument in argv) {
27 if ('--throw-on-error' == argument) { 28 if ('--throw-on-error' == argument) {
28 throwOnError = true; 29 throwOnError = true;
29 } else if ('--suppress-warnings' == argument) { 30 } else if ('--suppress-warnings' == argument) {
30 showWarnings = false; 31 showWarnings = false;
31 } else if ('--verbose' == argument) { 32 } else if ('--verbose' == argument) {
32 verbose = true; 33 verbose = true;
33 } else if (argument.startsWith('--library-root=')) { 34 } else if (argument.startsWith('--library-root=')) {
34 String path = 35 String path =
35 nativeToUriPath(argument.substring(argument.indexOf('=') + 1)); 36 nativeToUriPath(argument.substring(argument.indexOf('=') + 1));
36 if (!path.endsWith("/")) path = "$path/"; 37 if (!path.endsWith("/")) path = "$path/";
37 libraryRoot = cwd.resolve(path); 38 libraryRoot = cwd.resolve(path);
38 } else if (argument.startsWith('--out=')) { 39 } else if (argument.startsWith('--out=')) {
39 String path = 40 String path =
40 nativeToUriPath(argument.substring(argument.indexOf('=') + 1)); 41 nativeToUriPath(argument.substring(argument.indexOf('=') + 1));
41 out = cwd.resolve(path); 42 out = cwd.resolve(path);
43 } else if (argument == '--allow-mock-compilation') {
Bill Hesse 2012/04/25 12:46:26 constant on RHS of comparison disagrees with above
ahe 2012/04/25 13:49:41 Done.
44 options.add(argument);
42 } else if (argument.startsWith('-')) { 45 } else if (argument.startsWith('-')) {
43 throw new AbortLeg('unknown option $argument'); 46 fail('Unknown option $argument.');
44 } else { 47 } else {
45 arguments.add(nativeToUriPath(argument)); 48 arguments.add(nativeToUriPath(argument));
46 } 49 }
47 } 50 }
48 if (arguments.isEmpty()) { 51 if (arguments.isEmpty()) {
49 throw new AbortLeg('no files to compile'); 52 fail('No files to compile.');
ngeoffray 2012/04/25 12:24:54 No files -> No file
ahe 2012/04/25 13:49:41 Done.
50 } 53 }
51 if (arguments.length > 1) { 54 if (arguments.length > 1) {
52 var extra = arguments.getRange(1, arguments.length - 1); 55 var extra = arguments.getRange(1, arguments.length - 1);
53 throw new AbortLeg('extra arguments: $extra'); 56 fail('Extra arguments: $extra.');
54 } 57 }
55 58
56 Map<String, SourceFile> sourceFiles = <SourceFile>{}; 59 Map<String, SourceFile> sourceFiles = <SourceFile>{};
57 int dartBytesRead = 0; 60 int dartBytesRead = 0;
58 61
59 Future<String> provider(Uri uri) { 62 Future<String> provider(Uri uri) {
60 if (uri.scheme != 'file') { 63 if (uri.scheme != 'file') {
61 throw new IllegalArgumentException(uri); 64 throw new IllegalArgumentException(uri);
62 } 65 }
63 String source = readAll(uriPathToNative(uri.path)); 66 String source = readAll(uriPathToNative(uri.path));
(...skipping 22 matching lines...) Expand all
86 print(file.getLocationMessage(message, begin, end, true)); 89 print(file.getLocationMessage(message, begin, end, true));
87 } 90 }
88 if (fatal && throwOnError) throw new AbortLeg(message); 91 if (fatal && throwOnError) throw new AbortLeg(message);
89 } 92 }
90 93
91 Uri uri = cwd.resolve(arguments[0]); 94 Uri uri = cwd.resolve(arguments[0]);
92 info('compiling $uri'); 95 info('compiling $uri');
93 96
94 // TODO(ahe): We expect the future to be complete and call value 97 // TODO(ahe): We expect the future to be complete and call value
95 // directly. In effect, we don't support truly asynchronous API. 98 // directly. In effect, we don't support truly asynchronous API.
96 String code = api.compile(uri, libraryRoot, provider, handler).value; 99 String code = api.compile(uri, libraryRoot, provider, handler, options).value;
97 if (code === null) throw new AbortLeg('compilation failed'); 100 if (code === null) {
101 fail('Compilation failed.');
102 }
98 writeString(out, code); 103 writeString(out, code);
99 int jsBytesWritten = code.length; 104 int jsBytesWritten = code.length;
100 info('compiled $dartBytesRead bytes Dart -> $jsBytesWritten bytes JS ' 105 info('compiled $dartBytesRead bytes Dart -> $jsBytesWritten bytes JS '
101 + 'in ${relativize(cwd, out)}'); 106 + 'in ${relativize(cwd, out)}');
102 } 107 }
103 108
104 class AbortLeg { 109 class AbortLeg {
105 final message; 110 final message;
106 AbortLeg(this.message); 111 AbortLeg(this.message);
107 toString() => 'Aborted due to --throw-on-error: $message'; 112 toString() => 'Aborted due to --throw-on-error: $message';
108 } 113 }
109 114
110 void writeString(Uri uri, String text) { 115 void writeString(Uri uri, String text) {
111 if (uri.scheme != 'file') { 116 if (uri.scheme != 'file') {
112 throw new AbortLeg('unhandled scheme ${uri.scheme}'); 117 fail('Unhandled scheme ${uri.scheme}.');
113 } 118 }
114 var file = new File(uriPathToNative(uri.path)).openSync(FileMode.WRITE); 119 var file = new File(uriPathToNative(uri.path)).openSync(FileMode.WRITE);
115 file.writeStringSync(text); 120 file.writeStringSync(text);
116 file.closeSync(); 121 file.closeSync();
117 } 122 }
118 123
119 String readAll(String filename) { 124 String readAll(String filename) {
120 var file = (new File(filename)).openSync(FileMode.READ); 125 var file = (new File(filename)).openSync(FileMode.READ);
121 var length = file.lengthSync(); 126 var length = file.lengthSync();
122 var buffer = new List<int>(length); 127 var buffer = new List<int>(length);
123 var bytes = file.readListSync(buffer, 0, length); 128 var bytes = file.readListSync(buffer, 0, length);
124 file.closeSync(); 129 file.closeSync();
125 return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest()); 130 return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest());
126 } 131 }
132
133 void fail(String message) {
134 print(message);
135 exit(1);
136 }
OLDNEW
« no previous file with comments | « no previous file | dart/tools/testing/dart/test_suite.dart » ('j') | dart/tools/testing/dart/test_suite.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698