Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection' show Queue, LinkedHashMap; | 8 import 'dart:collection' show Queue, LinkedHashMap; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 handlers[i].handle(argument); | 63 handlers[i].handle(argument); |
| 64 continue OUTER; | 64 continue OUTER; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 throw 'Internal error: "$argument" did not match'; | 67 throw 'Internal error: "$argument" did not match'; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 void compile(List<String> argv) { | 71 void compile(List<String> argv) { |
| 72 bool isWindows = (Platform.operatingSystem == 'windows'); | 72 bool isWindows = (Platform.operatingSystem == 'windows'); |
| 73 Uri cwd = getCurrentDirectory(); | 73 Uri libraryRoot = currentDirectory; |
|
ahe
2013/04/09 08:28:44
This change is unrelated to the mirror system chan
Johnni Winther
2013/04/22 13:00:02
Sorry for the pollution.
| |
| 74 Uri libraryRoot = cwd; | 74 Uri out = currentDirectory.resolve('out.js'); |
| 75 Uri out = cwd.resolve('out.js'); | 75 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); |
| 76 Uri sourceMapOut = cwd.resolve('out.js.map'); | |
| 77 Uri packageRoot = null; | 76 Uri packageRoot = null; |
| 78 List<String> options = new List<String>(); | 77 List<String> options = new List<String>(); |
| 79 bool explicitOut = false; | 78 bool explicitOut = false; |
| 80 bool wantHelp = false; | 79 bool wantHelp = false; |
| 81 String outputLanguage = 'JavaScript'; | 80 String outputLanguage = 'JavaScript'; |
| 82 bool stripArgumentSet = false; | 81 bool stripArgumentSet = false; |
| 83 bool analyzeOnly = false; | 82 bool analyzeOnly = false; |
| 84 SourceFileProvider inputProvider = new SourceFileProvider(); | 83 SourceFileProvider inputProvider = new SourceFileProvider(); |
| 85 FormattingDiagnosticHandler diagnosticHandler = | 84 FormattingDiagnosticHandler diagnosticHandler = |
| 86 new FormattingDiagnosticHandler(inputProvider); | 85 new FormattingDiagnosticHandler(inputProvider); |
| 87 | 86 |
| 88 passThrough(String argument) => options.add(argument); | 87 passThrough(String argument) => options.add(argument); |
| 89 | 88 |
| 90 setLibraryRoot(String argument) { | 89 setLibraryRoot(String argument) { |
| 91 libraryRoot = cwd.resolve(extractPath(argument)); | 90 libraryRoot = currentDirectory.resolve(extractPath(argument)); |
| 92 } | 91 } |
| 93 | 92 |
| 94 setPackageRoot(String argument) { | 93 setPackageRoot(String argument) { |
| 95 packageRoot = cwd.resolve(extractPath(argument)); | 94 packageRoot = currentDirectory.resolve(extractPath(argument)); |
| 96 } | 95 } |
| 97 | 96 |
| 98 setOutput(String argument) { | 97 setOutput(String argument) { |
| 99 explicitOut = true; | 98 explicitOut = true; |
| 100 out = cwd.resolve(nativeToUriPath(extractParameter(argument))); | 99 out = currentDirectory.resolve(nativeToUriPath(extractParameter(argument))); |
| 101 sourceMapOut = Uri.parse('$out.map'); | 100 sourceMapOut = Uri.parse('$out.map'); |
| 102 } | 101 } |
| 103 | 102 |
| 104 setOutputType(String argument) { | 103 setOutputType(String argument) { |
| 105 if (argument == '--output-type=dart') { | 104 if (argument == '--output-type=dart') { |
| 106 outputLanguage = OUTPUT_LANGUAGE_DART; | 105 outputLanguage = OUTPUT_LANGUAGE_DART; |
| 107 if (!explicitOut) { | 106 if (!explicitOut) { |
| 108 out = cwd.resolve('out.dart'); | 107 out = currentDirectory.resolve('out.dart'); |
| 109 sourceMapOut = cwd.resolve('out.dart.map'); | 108 sourceMapOut = currentDirectory.resolve('out.dart.map'); |
| 110 } | 109 } |
| 111 } | 110 } |
| 112 passThrough(argument); | 111 passThrough(argument); |
| 113 } | 112 } |
| 114 | 113 |
| 115 String getDepsOutput(Map<String, SourceFile> sourceFiles) { | 114 String getDepsOutput(Map<String, SourceFile> sourceFiles) { |
| 116 var filenames = new List.from(sourceFiles.keys); | 115 var filenames = new List.from(sourceFiles.keys); |
| 117 filenames.sort(); | 116 filenames.sort(); |
| 118 return filenames.join("\n"); | 117 return filenames.join("\n"); |
| 119 } | 118 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 if (arguments.length > 1) { | 232 if (arguments.length > 1) { |
| 234 var extra = arguments.sublist(1); | 233 var extra = arguments.sublist(1); |
| 235 helpAndFail('Error: Extra arguments: ${extra.join(" ")}'); | 234 helpAndFail('Error: Extra arguments: ${extra.join(" ")}'); |
| 236 } | 235 } |
| 237 | 236 |
| 238 void handler(Uri uri, int begin, int end, String message, | 237 void handler(Uri uri, int begin, int end, String message, |
| 239 api.Diagnostic kind) { | 238 api.Diagnostic kind) { |
| 240 diagnosticHandler.diagnosticHandler(uri, begin, end, message, kind); | 239 diagnosticHandler.diagnosticHandler(uri, begin, end, message, kind); |
| 241 } | 240 } |
| 242 | 241 |
| 243 Uri uri = cwd.resolve(arguments[0]); | 242 Uri uri = currentDirectory.resolve(arguments[0]); |
| 244 if (packageRoot == null) { | 243 if (packageRoot == null) { |
| 245 packageRoot = uri.resolve('./packages/'); | 244 packageRoot = uri.resolve('./packages/'); |
| 246 } | 245 } |
| 247 | 246 |
| 248 diagnosticHandler.info('package root is $packageRoot'); | 247 diagnosticHandler.info('package root is $packageRoot'); |
| 249 | 248 |
| 250 int charactersWritten = 0; | 249 int charactersWritten = 0; |
| 251 | 250 |
| 252 compilationDone(String code) { | 251 compilationDone(String code) { |
| 253 if (analyzeOnly) return; | 252 if (analyzeOnly) return; |
| 254 if (code == null) { | 253 if (code == null) { |
| 255 fail('Error: Compilation failed.'); | 254 fail('Error: Compilation failed.'); |
| 256 } | 255 } |
| 257 writeString(Uri.parse('$out.deps'), | 256 writeString(Uri.parse('$out.deps'), |
| 258 getDepsOutput(inputProvider.sourceFiles)); | 257 getDepsOutput(inputProvider.sourceFiles)); |
| 259 diagnosticHandler.info( | 258 diagnosticHandler.info( |
| 260 'compiled ${inputProvider.dartCharactersRead} characters Dart ' | 259 'compiled ${inputProvider.dartCharactersRead} characters Dart ' |
| 261 '-> $charactersWritten characters $outputLanguage ' | 260 '-> $charactersWritten characters $outputLanguage ' |
| 262 'in ${relativize(cwd, out, isWindows)}'); | 261 'in ${relativize(currentDirectory, out, isWindows)}'); |
| 263 if (!explicitOut) { | 262 if (!explicitOut) { |
| 264 String input = uriPathToNative(arguments[0]); | 263 String input = uriPathToNative(arguments[0]); |
| 265 String output = relativize(cwd, out, isWindows); | 264 String output = relativize(currentDirectory, out, isWindows); |
| 266 print('Dart file $input compiled to $outputLanguage: $output'); | 265 print('Dart file $input compiled to $outputLanguage: $output'); |
| 267 } | 266 } |
| 268 } | 267 } |
| 269 | 268 |
| 270 EventSink<String> outputProvider(String name, String extension) { | 269 EventSink<String> outputProvider(String name, String extension) { |
| 271 Uri uri; | 270 Uri uri; |
| 272 String sourceMapFileName; | 271 String sourceMapFileName; |
| 273 bool isPrimaryOutput = false; | 272 bool isPrimaryOutput = false; |
| 274 if (name == '') { | 273 if (name == '') { |
| 275 if (extension == 'js' || extension == 'dart') { | 274 if (extension == 'js' || extension == 'dart') { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 } catch (ignored) { | 494 } catch (ignored) { |
| 496 print('Internal error: error while printing exception'); | 495 print('Internal error: error while printing exception'); |
| 497 } | 496 } |
| 498 try { | 497 try { |
| 499 print(trace); | 498 print(trace); |
| 500 } finally { | 499 } finally { |
| 501 exit(253); // 253 is recognized as a crash by our test scripts. | 500 exit(253); // 253 is recognized as a crash by our test scripts. |
| 502 } | 501 } |
| 503 } | 502 } |
| 504 } | 503 } |
| OLD | NEW |