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.cmdline; | 5 library dart2js.cmdline; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 import 'dart:convert' show UTF8, LineSplitter; | 8 import 'dart:convert' show UTF8, LineSplitter; |
9 import 'dart:io' show exit, File, FileMode, Platform, stdin, stderr; | 9 import 'dart:io' show exit, File, FileMode, Platform, stdin, stderr; |
10 | 10 |
11 import 'package:package_config/discovery.dart' show findPackages; | 11 import 'package:package_config/discovery.dart' show findPackages; |
12 | 12 |
13 import '../compiler.dart' as api; | 13 import '../compiler_new.dart' as api; |
14 import 'commandline_options.dart'; | 14 import 'commandline_options.dart'; |
15 import 'filenames.dart'; | 15 import 'filenames.dart'; |
16 import 'io/source_file.dart'; | 16 import 'io/source_file.dart'; |
17 import 'options.dart' show CompilerOptions; | |
17 import 'source_file_provider.dart'; | 18 import 'source_file_provider.dart'; |
18 import 'util/command_line.dart'; | 19 import 'util/command_line.dart'; |
19 import 'util/uri_extras.dart'; | 20 import 'util/uri_extras.dart'; |
20 import 'util/util.dart' show stackTraceFilePrefix; | 21 import 'util/util.dart' show stackTraceFilePrefix; |
21 | 22 |
22 const String LIBRARY_ROOT = '../../../../../sdk'; | 23 const String LIBRARY_ROOT = '../../../../../sdk'; |
23 const String OUTPUT_LANGUAGE_DART = 'Dart'; | 24 const String OUTPUT_LANGUAGE_DART = 'Dart'; |
24 | 25 |
25 /** | 26 /** |
26 * A string to identify the revision or build. | 27 * A string to identify the revision or build. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
100 FormattingDiagnosticHandler diagnosticHandler; | 101 FormattingDiagnosticHandler diagnosticHandler; |
101 | 102 |
102 Future<api.CompilationResult> compile(List<String> argv) { | 103 Future<api.CompilationResult> compile(List<String> argv) { |
103 stackTraceFilePrefix = '$currentDirectory'; | 104 stackTraceFilePrefix = '$currentDirectory'; |
104 Uri libraryRoot = currentDirectory; | 105 Uri libraryRoot = currentDirectory; |
105 Uri out = currentDirectory.resolve('out.js'); | 106 Uri out = currentDirectory.resolve('out.js'); |
106 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); | 107 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); |
108 Uri serializationSource; | |
109 Uri serializationTarget; | |
107 Uri packageConfig = null; | 110 Uri packageConfig = null; |
108 Uri packageRoot = null; | 111 Uri packageRoot = null; |
109 List<String> options = new List<String>(); | 112 List<String> options = new List<String>(); |
110 bool explicitOut = false; | 113 bool explicitOut = false; |
111 bool wantHelp = false; | 114 bool wantHelp = false; |
112 bool wantVersion = false; | 115 bool wantVersion = false; |
113 String outputLanguage = 'JavaScript'; | 116 String outputLanguage = 'JavaScript'; |
114 bool stripArgumentSet = false; | 117 bool stripArgumentSet = false; |
115 bool analyzeOnly = false; | 118 bool analyzeOnly = false; |
116 bool analyzeAll = false; | 119 bool analyzeAll = false; |
117 bool dumpInfo = false; | 120 bool dumpInfo = false; |
118 bool allowNativeExtensions = false; | 121 bool allowNativeExtensions = false; |
119 bool trustTypeAnnotations = false; | 122 bool trustTypeAnnotations = false; |
120 bool trustJSInteropTypeAnnotations = false; | 123 bool trustJSInteropTypeAnnotations = false; |
121 bool checkedMode = false; | 124 bool checkedMode = false; |
122 // List of provided options that imply that output is expected. | 125 // List of provided options that imply that output is expected. |
123 List<String> optionsImplyCompilation = <String>[]; | 126 List<String> optionsImplyCompilation = <String>[]; |
124 bool hasDisallowUnsafeEval = false; | 127 bool hasDisallowUnsafeEval = false; |
125 // TODO(johnniwinther): Measure time for reading files. | 128 // TODO(johnniwinther): Measure time for reading files. |
126 SourceFileProvider inputProvider = new CompilerSourceFileProvider(); | 129 SourceFileProvider inputProvider = new CompilerSourceFileProvider(); |
127 diagnosticHandler = new FormattingDiagnosticHandler(inputProvider); | 130 diagnosticHandler = new FormattingDiagnosticHandler(inputProvider); |
128 Map<String, dynamic> environment = new Map<String, dynamic>(); | 131 Map<String, dynamic> environment = new Map<String, dynamic>(); |
129 | 132 |
130 passThrough(String argument) => options.add(argument); | 133 void passThrough(String argument) => options.add(argument); |
131 | 134 |
132 if (BUILD_ID != null) { | 135 if (BUILD_ID != null) { |
133 passThrough("--build-id=$BUILD_ID"); | 136 passThrough("--build-id=$BUILD_ID"); |
134 } | 137 } |
135 | 138 |
136 setLibraryRoot(String argument) { | 139 void setLibraryRoot(String argument) { |
137 libraryRoot = currentDirectory.resolve(extractPath(argument)); | 140 libraryRoot = currentDirectory.resolve(extractPath(argument)); |
138 } | 141 } |
139 | 142 |
140 setPackageRoot(String argument) { | 143 void setPackageRoot(String argument) { |
141 packageRoot = currentDirectory.resolve(extractPath(argument)); | 144 packageRoot = currentDirectory.resolve(extractPath(argument)); |
142 } | 145 } |
143 | 146 |
144 setPackageConfig(String argument) { | 147 void setPackageConfig(String argument) { |
145 packageConfig = | 148 packageConfig = |
146 currentDirectory.resolve(extractPath(argument, isDirectory: false)); | 149 currentDirectory.resolve(extractPath(argument, isDirectory: false)); |
147 } | 150 } |
148 | 151 |
149 setOutput(Iterator<String> arguments) { | 152 void setOutput(Iterator<String> arguments) { |
150 optionsImplyCompilation.add(arguments.current); | 153 optionsImplyCompilation.add(arguments.current); |
151 String path; | 154 String path; |
152 if (arguments.current == '-o') { | 155 if (arguments.current == '-o') { |
153 if (!arguments.moveNext()) { | 156 if (!arguments.moveNext()) { |
154 helpAndFail('Error: Missing file after -o option.'); | 157 helpAndFail('Error: Missing file after -o option.'); |
155 } | 158 } |
156 path = arguments.current; | 159 path = arguments.current; |
157 } else { | 160 } else { |
158 path = extractParameter(arguments.current); | 161 path = extractParameter(arguments.current); |
159 } | 162 } |
160 explicitOut = true; | 163 explicitOut = true; |
161 out = currentDirectory.resolve(nativeToUriPath(path)); | 164 out = currentDirectory.resolve(nativeToUriPath(path)); |
162 sourceMapOut = Uri.parse('$out.map'); | 165 sourceMapOut = Uri.parse('$out.map'); |
163 } | 166 } |
164 | 167 |
165 setOutputType(String argument) { | 168 void setOutputType(String argument) { |
166 optionsImplyCompilation.add(argument); | 169 optionsImplyCompilation.add(argument); |
167 if (argument == '--output-type=dart' || | 170 if (argument == '--output-type=dart' || |
168 argument == '--output-type=dart-multi') { | 171 argument == '--output-type=dart-multi') { |
169 outputLanguage = OUTPUT_LANGUAGE_DART; | 172 outputLanguage = OUTPUT_LANGUAGE_DART; |
170 if (!explicitOut) { | 173 if (!explicitOut) { |
171 out = currentDirectory.resolve('out.dart'); | 174 out = currentDirectory.resolve('out.dart'); |
172 sourceMapOut = currentDirectory.resolve('out.dart.map'); | 175 sourceMapOut = currentDirectory.resolve('out.dart.map'); |
173 } | 176 } |
174 diagnosticHandler( | 177 diagnosticHandler( |
175 null, | 178 null, |
176 null, | 179 null, |
177 null, | 180 null, |
178 "--output-type=dart is deprecated. It will remain available " | 181 "--output-type=dart is deprecated. It will remain available " |
179 "in Dart 1.11, but will be removed in Dart 1.12.", | 182 "in Dart 1.11, but will be removed in Dart 1.12.", |
180 api.Diagnostic.WARNING); | 183 api.Diagnostic.WARNING); |
181 } | 184 } |
182 passThrough(argument); | 185 passThrough(argument); |
183 } | 186 } |
184 | 187 |
188 void setSerializationSource(String argument) { | |
189 serializationSource = | |
190 currentDirectory.resolve(extractPath(argument, isDirectory: false)); | |
191 } | |
192 | |
193 void setSerializationTarget(String argument) { | |
194 serializationTarget = | |
195 currentDirectory.resolve(extractPath(argument, isDirectory: false)); | |
196 } | |
197 | |
185 String getDepsOutput(Map<Uri, SourceFile> sourceFiles) { | 198 String getDepsOutput(Map<Uri, SourceFile> sourceFiles) { |
186 var filenames = sourceFiles.keys.map((uri) => '$uri').toList(); | 199 var filenames = sourceFiles.keys.map((uri) => '$uri').toList(); |
187 filenames.sort(); | 200 filenames.sort(); |
188 return filenames.join("\n"); | 201 return filenames.join("\n"); |
189 } | 202 } |
190 | 203 |
191 setStrip(String argument) { | 204 void setStrip(String argument) { |
192 optionsImplyCompilation.add(argument); | 205 optionsImplyCompilation.add(argument); |
193 stripArgumentSet = true; | 206 stripArgumentSet = true; |
194 passThrough(argument); | 207 passThrough(argument); |
195 } | 208 } |
196 | 209 |
197 setAnalyzeOnly(String argument) { | 210 void setAnalyzeOnly(String argument) { |
198 analyzeOnly = true; | 211 analyzeOnly = true; |
199 passThrough(argument); | 212 passThrough(argument); |
200 } | 213 } |
201 | 214 |
202 setAnalyzeAll(String argument) { | 215 void setAnalyzeAll(String argument) { |
203 analyzeAll = true; | 216 analyzeAll = true; |
204 passThrough(argument); | 217 passThrough(argument); |
205 } | 218 } |
206 | 219 |
207 setAllowNativeExtensions(String argument) { | 220 void setAllowNativeExtensions(String argument) { |
208 allowNativeExtensions = true; | 221 allowNativeExtensions = true; |
209 passThrough(argument); | 222 passThrough(argument); |
210 } | 223 } |
211 | 224 |
212 setVerbose(_) { | 225 void setVerbose(_) { |
213 diagnosticHandler.verbose = true; | 226 diagnosticHandler.verbose = true; |
214 passThrough('--verbose'); | 227 passThrough('--verbose'); |
215 } | 228 } |
216 | 229 |
217 implyCompilation(String argument) { | 230 void implyCompilation(String argument) { |
218 optionsImplyCompilation.add(argument); | 231 optionsImplyCompilation.add(argument); |
219 passThrough(argument); | 232 passThrough(argument); |
220 } | 233 } |
221 | 234 |
222 setDumpInfo(String argument) { | 235 void setDumpInfo(String argument) { |
223 implyCompilation(argument); | 236 implyCompilation(argument); |
224 dumpInfo = true; | 237 dumpInfo = true; |
225 } | 238 } |
226 | 239 |
227 setTrustTypeAnnotations(String argument) { | 240 void setTrustTypeAnnotations(String argument) { |
228 trustTypeAnnotations = true; | 241 trustTypeAnnotations = true; |
229 implyCompilation(argument); | 242 implyCompilation(argument); |
230 } | 243 } |
231 | 244 |
232 setTrustJSInteropTypeAnnotations(String argument) { | 245 void setTrustJSInteropTypeAnnotations(String argument) { |
233 trustJSInteropTypeAnnotations = true; | 246 trustJSInteropTypeAnnotations = true; |
234 implyCompilation(argument); | 247 implyCompilation(argument); |
235 } | 248 } |
236 | 249 |
237 setTrustPrimitives(String argument) { | 250 void setTrustPrimitives(String argument) { |
238 implyCompilation(argument); | 251 implyCompilation(argument); |
239 } | 252 } |
240 | 253 |
241 setCheckedMode(String argument) { | 254 void setCheckedMode(String argument) { |
242 checkedMode = true; | 255 checkedMode = true; |
243 passThrough(argument); | 256 passThrough(argument); |
244 } | 257 } |
245 | 258 |
246 addInEnvironment(String argument) { | 259 void addInEnvironment(String argument) { |
247 int eqIndex = argument.indexOf('='); | 260 int eqIndex = argument.indexOf('='); |
248 String name = argument.substring(2, eqIndex); | 261 String name = argument.substring(2, eqIndex); |
249 String value = argument.substring(eqIndex + 1); | 262 String value = argument.substring(eqIndex + 1); |
250 environment[name] = value; | 263 environment[name] = value; |
251 } | 264 } |
252 | 265 |
253 setCategories(String argument) { | 266 void setCategories(String argument) { |
254 List<String> categories = extractParameter(argument).split(','); | 267 List<String> categories = extractParameter(argument).split(','); |
255 if (categories.contains('all')) { | 268 if (categories.contains('all')) { |
256 categories = ["Client", "Server"]; | 269 categories = ["Client", "Server"]; |
257 } else { | 270 } else { |
258 for (String category in categories) { | 271 for (String category in categories) { |
259 if (!["Client", "Server"].contains(category)) { | 272 if (!["Client", "Server"].contains(category)) { |
260 fail('Unsupported library category "$category", ' | 273 fail('Unsupported library category "$category", ' |
261 'supported categories are: Client, Server, all'); | 274 'supported categories are: Client, Server, all'); |
262 } | 275 } |
263 } | 276 } |
264 } | 277 } |
265 passThrough('--categories=${categories.join(",")}'); | 278 passThrough('--categories=${categories.join(",")}'); |
266 } | 279 } |
267 | 280 |
268 void handleThrowOnError(String argument) { | 281 void handleThrowOnError(String argument) { |
269 diagnosticHandler.throwOnError = true; | 282 diagnosticHandler.throwOnError = true; |
270 String parameter = extractParameter(argument, isOptionalArgument: true); | 283 String parameter = extractParameter(argument, isOptionalArgument: true); |
271 if (parameter != null) { | 284 if (parameter != null) { |
272 diagnosticHandler.throwOnErrorCount = int.parse(parameter); | 285 diagnosticHandler.throwOnErrorCount = int.parse(parameter); |
273 } | 286 } |
274 } | 287 } |
275 | 288 |
276 handleShortOptions(String argument) { | 289 void handleShortOptions(String argument) { |
277 var shortOptions = argument.substring(1).split(""); | 290 var shortOptions = argument.substring(1).split(""); |
278 for (var shortOption in shortOptions) { | 291 for (var shortOption in shortOptions) { |
279 switch (shortOption) { | 292 switch (shortOption) { |
280 case 'v': | 293 case 'v': |
281 setVerbose(null); | 294 setVerbose(null); |
282 break; | 295 break; |
283 case 'h': | 296 case 'h': |
284 case '?': | 297 case '?': |
285 wantHelp = true; | 298 wantHelp = true; |
286 break; | 299 break; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 new OptionHandler( | 348 new OptionHandler( |
336 Flags.trustJSInteropTypeAnnotations, | 349 Flags.trustJSInteropTypeAnnotations, |
337 (_) => setTrustJSInteropTypeAnnotations( | 350 (_) => setTrustJSInteropTypeAnnotations( |
338 Flags.trustJSInteropTypeAnnotations)), | 351 Flags.trustJSInteropTypeAnnotations)), |
339 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), | 352 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), |
340 new OptionHandler('--packages=.+', setPackageConfig), | 353 new OptionHandler('--packages=.+', setPackageConfig), |
341 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), | 354 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), |
342 new OptionHandler(Flags.analyzeAll, setAnalyzeAll), | 355 new OptionHandler(Flags.analyzeAll, setAnalyzeAll), |
343 new OptionHandler(Flags.analyzeOnly, setAnalyzeOnly), | 356 new OptionHandler(Flags.analyzeOnly, setAnalyzeOnly), |
344 new OptionHandler(Flags.noSourceMaps, passThrough), | 357 new OptionHandler(Flags.noSourceMaps, passThrough), |
358 new OptionHandler(Option.serializationSource, setSerializationSource), | |
359 new OptionHandler(Option.serializationTarget, setSerializationTarget), | |
345 new OptionHandler(Flags.analyzeSignaturesOnly, setAnalyzeOnly), | 360 new OptionHandler(Flags.analyzeSignaturesOnly, setAnalyzeOnly), |
346 new OptionHandler(Flags.disableNativeLiveTypeAnalysis, passThrough), | 361 new OptionHandler(Flags.disableNativeLiveTypeAnalysis, passThrough), |
347 new OptionHandler('--categories=.*', setCategories), | 362 new OptionHandler('--categories=.*', setCategories), |
348 new OptionHandler(Flags.disableTypeInference, implyCompilation), | 363 new OptionHandler(Flags.disableTypeInference, implyCompilation), |
349 new OptionHandler(Flags.terse, passThrough), | 364 new OptionHandler(Flags.terse, passThrough), |
350 new OptionHandler('--deferred-map=.+', implyCompilation), | 365 new OptionHandler('--deferred-map=.+', implyCompilation), |
351 new OptionHandler(Flags.dumpInfo, setDumpInfo), | 366 new OptionHandler(Flags.dumpInfo, setDumpInfo), |
352 new OptionHandler( | 367 new OptionHandler( |
353 '--disallow-unsafe-eval', (_) => hasDisallowUnsafeEval = true), | 368 '--disallow-unsafe-eval', (_) => hasDisallowUnsafeEval = true), |
354 new OptionHandler(Option.showPackageWarnings, passThrough), | 369 new OptionHandler(Option.showPackageWarnings, passThrough), |
355 new OptionHandler(Flags.useContentSecurityPolicy, passThrough), | 370 new OptionHandler(Flags.useContentSecurityPolicy, passThrough), |
356 new OptionHandler(Flags.enableExperimentalMirrors, passThrough), | 371 new OptionHandler(Flags.enableExperimentalMirrors, passThrough), |
357 new OptionHandler(Flags.enableAssertMessage, passThrough), | 372 new OptionHandler(Flags.enableAssertMessage, passThrough), |
373 | |
358 // TODO(floitsch): remove conditional directives flag. | 374 // TODO(floitsch): remove conditional directives flag. |
359 // We don't provide the info-message yet, since we haven't publicly | 375 // We don't provide the info-message yet, since we haven't publicly |
360 // launched the feature yet. | 376 // launched the feature yet. |
361 new OptionHandler(Flags.conditionalDirectives, (_) {}), | 377 new OptionHandler(Flags.conditionalDirectives, (_) {}), |
362 new OptionHandler('--enable-async', (_) { | 378 new OptionHandler('--enable-async', (_) { |
363 diagnosticHandler.info( | 379 diagnosticHandler.info( |
364 "Option '--enable-async' is no longer needed. " | 380 "Option '--enable-async' is no longer needed. " |
365 "Async-await is supported by default.", | 381 "Async-await is supported by default.", |
366 api.Diagnostic.HINT); | 382 api.Diagnostic.HINT); |
367 }), | 383 }), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 | 436 |
421 if (checkedMode && trustTypeAnnotations) { | 437 if (checkedMode && trustTypeAnnotations) { |
422 helpAndFail("Option '${Flags.trustTypeAnnotations}' may not be used in " | 438 helpAndFail("Option '${Flags.trustTypeAnnotations}' may not be used in " |
423 "checked mode."); | 439 "checked mode."); |
424 } | 440 } |
425 | 441 |
426 if (packageRoot != null && packageConfig != null) { | 442 if (packageRoot != null && packageConfig != null) { |
427 helpAndFail("Cannot specify both '--package-root' and '--packages."); | 443 helpAndFail("Cannot specify both '--package-root' and '--packages."); |
428 } | 444 } |
429 | 445 |
430 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { | 446 if ((analyzeOnly || analyzeAll || serializationTarget != null) && |
431 if (!analyzeOnly) { | 447 !optionsImplyCompilation.isEmpty) { |
448 if (serializationTarget != null) { | |
449 if (!analyzeAll) { | |
450 diagnosticHandler.info( | |
451 "Option '${Option.serializationTarget}' implies " | |
452 "'${Flags.analyzeAll}'.", | |
453 api.Diagnostic.INFO); | |
454 analyzeAll = true; | |
455 } | |
Siggi Cherem (dart-lang)
2016/05/17 21:54:25
maybe set analyzeOnly here too?
That way we don't
Johnni Winther
2016/05/18 09:52:41
Done.
| |
456 } | |
457 if (analyzeAll && !analyzeOnly) { | |
432 diagnosticHandler.info( | 458 diagnosticHandler.info( |
433 "Option '${Flags.analyzeAll}' implies '${Flags.analyzeOnly}'.", | 459 "Option '${Flags.analyzeAll}' implies '${Flags.analyzeOnly}'.", |
434 api.Diagnostic.INFO); | 460 api.Diagnostic.INFO); |
435 } | 461 } |
436 diagnosticHandler.info( | 462 diagnosticHandler.info( |
437 "Options $optionsImplyCompilation indicate that output is expected, " | 463 "Options $optionsImplyCompilation indicate that output is expected, " |
438 "but compilation is turned off by the option '${Flags.analyzeOnly}'.", | 464 "but compilation is turned off by the option '${Flags.analyzeOnly}'.", |
439 api.Diagnostic.INFO); | 465 api.Diagnostic.INFO); |
440 } | 466 } |
441 if (analyzeAll) analyzeOnly = true; | 467 if (analyzeAll) analyzeOnly = true; |
442 if (!analyzeOnly) { | 468 if (!analyzeOnly) { |
443 if (allowNativeExtensions) { | 469 if (allowNativeExtensions) { |
444 helpAndFail("Option '${Flags.allowNativeExtensions}' is only supported " | 470 helpAndFail("Option '${Flags.allowNativeExtensions}' is only supported " |
445 "in combination with the '${Flags.analyzeOnly}' option."); | 471 "in combination with the '${Flags.analyzeOnly}' option."); |
446 } | 472 } |
447 } | 473 } |
448 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { | 474 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { |
449 helpAndFail("Option '${Flags.dumpInfo}' is not supported in " | 475 helpAndFail("Option '${Flags.dumpInfo}' is not supported in " |
450 "combination with the '--output-type=dart' option."); | 476 "combination with the '--output-type=dart' option."); |
451 } | 477 } |
452 | 478 |
453 options.add('--out=$out'); | 479 options.add('--out=$out'); |
454 options.add('--source-map=$sourceMapOut'); | 480 options.add('--source-map=$sourceMapOut'); |
455 | 481 |
456 RandomAccessFileOutputProvider outputProvider = | 482 RandomAccessFileOutputProvider outputProvider = |
457 new RandomAccessFileOutputProvider(out, sourceMapOut, | 483 new RandomAccessFileOutputProvider(out, sourceMapOut, |
458 onInfo: diagnosticHandler.info, onFailure: fail); | 484 onInfo: diagnosticHandler.info, |
485 onFailure: fail, | |
486 serializationTarget: serializationTarget); | |
459 | 487 |
460 api.CompilationResult compilationDone(api.CompilationResult result) { | 488 api.CompilationResult compilationDone(api.CompilationResult result) { |
461 if (analyzeOnly) return result; | 489 if (analyzeOnly) return result; |
462 if (!result.isSuccess) { | 490 if (!result.isSuccess) { |
463 fail('Compilation failed.'); | 491 fail('Compilation failed.'); |
464 } | 492 } |
465 writeString( | 493 writeString( |
466 Uri.parse('$out.deps'), getDepsOutput(inputProvider.sourceFiles)); | 494 Uri.parse('$out.deps'), getDepsOutput(inputProvider.sourceFiles)); |
467 diagnosticHandler | 495 diagnosticHandler |
468 .info('Compiled ${inputProvider.dartCharactersRead} characters Dart ' | 496 .info('Compiled ${inputProvider.dartCharactersRead} characters Dart ' |
469 '-> ${outputProvider.totalCharactersWritten} characters ' | 497 '-> ${outputProvider.totalCharactersWritten} characters ' |
470 '$outputLanguage in ' | 498 '$outputLanguage in ' |
471 '${relativize(currentDirectory, out, Platform.isWindows)}'); | 499 '${relativize(currentDirectory, out, Platform.isWindows)}'); |
472 if (diagnosticHandler.verbose) { | 500 if (diagnosticHandler.verbose) { |
473 String input = uriPathToNative(arguments[0]); | 501 String input = uriPathToNative(arguments[0]); |
474 print('Dart file ($input) compiled to $outputLanguage.'); | 502 print('Dart file ($input) compiled to $outputLanguage.'); |
475 print('Wrote the following files:'); | 503 print('Wrote the following files:'); |
476 for (String filename in outputProvider.allOutputFiles) { | 504 for (String filename in outputProvider.allOutputFiles) { |
477 print(" $filename"); | 505 print(" $filename"); |
478 } | 506 } |
479 } else if (!explicitOut) { | 507 } else if (!explicitOut) { |
480 String input = uriPathToNative(arguments[0]); | 508 String input = uriPathToNative(arguments[0]); |
481 String output = relativize(currentDirectory, out, Platform.isWindows); | 509 String output = relativize(currentDirectory, out, Platform.isWindows); |
482 print('Dart file ($input) compiled to $outputLanguage: $output'); | 510 print('Dart file ($input) compiled to $outputLanguage: $output'); |
483 } | 511 } |
484 return result; | 512 return result; |
485 } | 513 } |
486 | 514 |
487 Uri uri = currentDirectory.resolve(arguments[0]); | 515 Uri script = currentDirectory.resolve(arguments[0]); |
516 CompilerOptions compilerOptions = new CompilerOptions.parse( | |
517 entryPoint: script, | |
518 libraryRoot: libraryRoot, | |
519 packageRoot: packageRoot, | |
520 packageConfig: packageConfig, | |
521 packagesDiscoveryProvider: findPackages, | |
522 serializationSource: serializationSource, | |
523 serializationTarget: serializationTarget, | |
524 options: options, | |
525 environment: environment); | |
488 return compileFunc( | 526 return compileFunc( |
489 uri, | 527 compilerOptions, inputProvider, diagnosticHandler, outputProvider) |
490 libraryRoot, | |
491 packageRoot, | |
492 inputProvider, | |
493 diagnosticHandler, | |
494 options, | |
495 outputProvider, | |
496 environment, | |
497 packageConfig, | |
498 findPackages) | |
499 .then(compilationDone); | 528 .then(compilationDone); |
500 } | 529 } |
501 | 530 |
502 class AbortLeg { | 531 class AbortLeg { |
503 final message; | 532 final message; |
504 AbortLeg(this.message); | 533 AbortLeg(this.message); |
505 toString() => 'Aborted due to --throw-on-error: $message'; | 534 toString() => 'Aborted due to --throw-on-error: $message'; |
506 } | 535 } |
507 | 536 |
508 void writeString(Uri uri, String text) { | 537 void writeString(Uri uri, String text) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 void main(List<String> arguments) { | 728 void main(List<String> arguments) { |
700 // Since the sdk/bin/dart2js script adds its own arguments in front of | 729 // Since the sdk/bin/dart2js script adds its own arguments in front of |
701 // user-supplied arguments we search for '--batch' at the end of the list. | 730 // user-supplied arguments we search for '--batch' at the end of the list. |
702 if (arguments.length > 0 && arguments.last == "--batch") { | 731 if (arguments.length > 0 && arguments.last == "--batch") { |
703 batchMain(arguments.sublist(0, arguments.length - 1)); | 732 batchMain(arguments.sublist(0, arguments.length - 1)); |
704 return; | 733 return; |
705 } | 734 } |
706 internalMain(arguments); | 735 internalMain(arguments); |
707 } | 736 } |
708 | 737 |
709 var exitFunc = exit; | 738 typedef void ExitFunc(int exitCode); |
710 var compileFunc = api.compile; | 739 typedef Future<api.CompilationResult> CompileFunc( |
740 CompilerOptions compilerOptions, | |
741 api.CompilerInput compilerInput, | |
742 api.CompilerDiagnostics compilerDiagnostics, | |
743 api.CompilerOutput compilerOutput); | |
744 | |
745 ExitFunc exitFunc = exit; | |
746 CompileFunc compileFunc = api.compile; | |
711 | 747 |
712 Future<api.CompilationResult> internalMain(List<String> arguments) { | 748 Future<api.CompilationResult> internalMain(List<String> arguments) { |
713 Future onError(exception, trace) { | 749 Future onError(exception, trace) { |
714 // If we are already trying to exit, just continue exiting. | 750 // If we are already trying to exit, just continue exiting. |
715 if (exception == _EXIT_SIGNAL) throw exception; | 751 if (exception == _EXIT_SIGNAL) throw exception; |
716 | 752 |
717 try { | 753 try { |
718 print('The compiler crashed: $exception'); | 754 print('The compiler crashed: $exception'); |
719 } catch (ignored) { | 755 } catch (ignored) { |
720 print('The compiler crashed: error while printing exception'); | 756 print('The compiler crashed: error while printing exception'); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 } else if (exitCode == 253) { | 813 } else if (exitCode == 253) { |
778 print(">>> TEST CRASH"); | 814 print(">>> TEST CRASH"); |
779 } else { | 815 } else { |
780 print(">>> TEST FAIL"); | 816 print(">>> TEST FAIL"); |
781 } | 817 } |
782 stderr.writeln(">>> EOF STDERR"); | 818 stderr.writeln(">>> EOF STDERR"); |
783 subscription.resume(); | 819 subscription.resume(); |
784 }); | 820 }); |
785 }); | 821 }); |
786 } | 822 } |
OLD | NEW |