OLD | NEW |
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 final String LIBRARY_ROOT = '../../../..'; |
| 18 |
17 void compile(List<String> argv) { | 19 void compile(List<String> argv) { |
18 Uri cwd = getCurrentDirectory(); | 20 Uri cwd = getCurrentDirectory(); |
19 bool throwOnError = false; | 21 bool throwOnError = false; |
20 bool showWarnings = true; | 22 bool showWarnings = true; |
21 bool verbose = false; | 23 bool verbose = false; |
22 Uri libraryRoot = cwd; | 24 Uri libraryRoot = cwd; |
23 Uri out = cwd.resolve('out.js'); | 25 Uri out = cwd.resolve('out.js'); |
24 List<String> options = new List<String>(); | 26 List<String> options = new List<String>(); |
25 | 27 |
26 List<String> arguments = <String>[]; | 28 List<String> arguments = <String>[]; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 var buffer = new List<int>(length); | 129 var buffer = new List<int>(length); |
128 var bytes = file.readListSync(buffer, 0, length); | 130 var bytes = file.readListSync(buffer, 0, length); |
129 file.closeSync(); | 131 file.closeSync(); |
130 return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest()); | 132 return new String.fromCharCodes(new Utf8Decoder(buffer).decodeRest()); |
131 } | 133 } |
132 | 134 |
133 void fail(String message) { | 135 void fail(String message) { |
134 print(message); | 136 print(message); |
135 exit(1); | 137 exit(1); |
136 } | 138 } |
| 139 |
| 140 void compilerMain(Options options) { |
| 141 List<String> argv = ['--library-root=${options.script}/$LIBRARY_ROOT']; |
| 142 argv.addAll(options.arguments); |
| 143 compile(argv); |
| 144 } |
| 145 |
| 146 void main() { |
| 147 try { |
| 148 compilerMain(new Options()); |
| 149 } catch (var exception, var trace) { |
| 150 try { |
| 151 print('Internal error: \$exception'); |
| 152 } catch (var ignored) { |
| 153 print('Internal error: error while printing exception'); |
| 154 } |
| 155 try { |
| 156 print(trace); |
| 157 } finally { |
| 158 exit(253); // 253 is recognized as a crash by our test scripts. |
| 159 } |
| 160 } |
| 161 } |
OLD | NEW |