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 EventSink, Future; | 7 import 'dart:async' show EventSink, 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 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 Uri libraryRoot = currentDirectory; | 108 Uri libraryRoot = currentDirectory; |
109 Uri out = currentDirectory.resolve('out.js'); | 109 Uri out = currentDirectory.resolve('out.js'); |
110 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); | 110 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); |
111 List<Uri> resolutionInputs; | 111 List<Uri> resolutionInputs; |
112 Uri packageConfig = null; | 112 Uri packageConfig = null; |
113 Uri packageRoot = null; | 113 Uri packageRoot = null; |
114 List<String> options = new List<String>(); | 114 List<String> options = new List<String>(); |
115 List<String> explicitOutputArguments = <String>[]; | 115 List<String> explicitOutputArguments = <String>[]; |
116 bool wantHelp = false; | 116 bool wantHelp = false; |
117 bool wantVersion = false; | 117 bool wantVersion = false; |
118 String outputLanguage = 'JavaScript'; | |
119 bool stripArgumentSet = false; | |
120 bool analyzeOnly = false; | 118 bool analyzeOnly = false; |
121 bool analyzeAll = false; | 119 bool analyzeAll = false; |
122 bool resolveOnly = false; | 120 bool resolveOnly = false; |
123 Uri resolutionOutput = currentDirectory.resolve('out.data'); | 121 Uri resolutionOutput = currentDirectory.resolve('out.data'); |
124 bool dumpInfo = false; | 122 bool dumpInfo = false; |
125 bool allowNativeExtensions = false; | 123 bool allowNativeExtensions = false; |
126 bool trustTypeAnnotations = false; | 124 bool trustTypeAnnotations = false; |
127 bool trustJSInteropTypeAnnotations = false; | 125 bool trustJSInteropTypeAnnotations = false; |
128 bool checkedMode = false; | 126 bool checkedMode = false; |
129 // List of provided options that imply that output is expected. | 127 // List of provided options that imply that output is expected. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 path = extractParameter(arguments.current); | 164 path = extractParameter(arguments.current); |
167 } | 165 } |
168 resolutionOutput = out = currentDirectory.resolve(nativeToUriPath(path)); | 166 resolutionOutput = out = currentDirectory.resolve(nativeToUriPath(path)); |
169 sourceMapOut = Uri.parse('$out.map'); | 167 sourceMapOut = Uri.parse('$out.map'); |
170 } | 168 } |
171 | 169 |
172 void setOutputType(String argument) { | 170 void setOutputType(String argument) { |
173 optionsImplyCompilation.add(argument); | 171 optionsImplyCompilation.add(argument); |
174 if (argument == '--output-type=dart' || | 172 if (argument == '--output-type=dart' || |
175 argument == '--output-type=dart-multi') { | 173 argument == '--output-type=dart-multi') { |
176 outputLanguage = OUTPUT_LANGUAGE_DART; | 174 helpAndFail( |
177 if (explicitOutputArguments.isNotEmpty) { | 175 "--output-type=dart is no longer supported. It was deprecated " |
178 out = currentDirectory.resolve('out.dart'); | 176 "since Dart 1.11 and removed in Dart 1.19."); |
179 sourceMapOut = currentDirectory.resolve('out.dart.map'); | |
180 } | |
181 diagnosticHandler( | |
182 null, | |
183 null, | |
184 null, | |
185 "--output-type=dart is deprecated. It will remain available " | |
186 "in Dart 1.11, but will be removed in Dart 1.12.", | |
187 api.Diagnostic.WARNING); | |
188 } | 177 } |
189 passThrough(argument); | |
190 } | 178 } |
191 | 179 |
192 void setResolutionInput(String argument) { | 180 void setResolutionInput(String argument) { |
193 resolutionInputs = <Uri>[]; | 181 resolutionInputs = <Uri>[]; |
194 String parts = extractParameter(argument); | 182 String parts = extractParameter(argument); |
195 for (String part in parts.split(',')) { | 183 for (String part in parts.split(',')) { |
196 resolutionInputs.add(currentDirectory.resolve(nativeToUriPath(part))); | 184 resolutionInputs.add(currentDirectory.resolve(nativeToUriPath(part))); |
197 } | 185 } |
198 } | 186 } |
199 | 187 |
200 void setResolveOnly(String argument) { | 188 void setResolveOnly(String argument) { |
201 resolveOnly = true; | 189 resolveOnly = true; |
202 passThrough(argument); | 190 passThrough(argument); |
203 } | 191 } |
204 | 192 |
205 String getDepsOutput(Map<Uri, SourceFile> sourceFiles) { | 193 String getDepsOutput(Map<Uri, SourceFile> sourceFiles) { |
206 var filenames = sourceFiles.keys.map((uri) => '$uri').toList(); | 194 var filenames = sourceFiles.keys.map((uri) => '$uri').toList(); |
207 filenames.sort(); | 195 filenames.sort(); |
208 return filenames.join("\n"); | 196 return filenames.join("\n"); |
209 } | 197 } |
210 | 198 |
211 void implyCompilation(String argument) { | 199 implyCompilation(String argument) { |
212 optionsImplyCompilation.add(argument); | 200 optionsImplyCompilation.add(argument); |
213 passThrough(argument); | 201 passThrough(argument); |
214 } | 202 } |
215 | 203 |
216 void setStrip(String argument) { | 204 setStrip(String argument) { |
217 stripArgumentSet = true; | 205 helpAndFail("Option '--force-strip' is not in use now that" |
218 implyCompilation(argument); | 206 "--output-type=dart is no longer supported."); |
219 } | 207 } |
220 | 208 |
221 void setAnalyzeOnly(String argument) { | 209 void setAnalyzeOnly(String argument) { |
222 analyzeOnly = true; | 210 analyzeOnly = true; |
223 passThrough(argument); | 211 passThrough(argument); |
224 } | 212 } |
225 | 213 |
226 void setAnalyzeAll(String argument) { | 214 void setAnalyzeAll(String argument) { |
227 analyzeAll = true; | 215 analyzeAll = true; |
228 passThrough(argument); | 216 passThrough(argument); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 List<OptionHandler> handlers = <OptionHandler>[ | 307 List<OptionHandler> handlers = <OptionHandler>[ |
320 new OptionHandler('-[chvm?]+', handleShortOptions), | 308 new OptionHandler('-[chvm?]+', handleShortOptions), |
321 new OptionHandler('--throw-on-error(?:=[0-9]+)?', handleThrowOnError), | 309 new OptionHandler('--throw-on-error(?:=[0-9]+)?', handleThrowOnError), |
322 new OptionHandler(Flags.suppressWarnings, (_) { | 310 new OptionHandler(Flags.suppressWarnings, (_) { |
323 diagnosticHandler.showWarnings = false; | 311 diagnosticHandler.showWarnings = false; |
324 passThrough(Flags.suppressWarnings); | 312 passThrough(Flags.suppressWarnings); |
325 }), | 313 }), |
326 new OptionHandler(Flags.fatalWarnings, passThrough), | 314 new OptionHandler(Flags.fatalWarnings, passThrough), |
327 new OptionHandler( | 315 new OptionHandler( |
328 Flags.suppressHints, (_) => diagnosticHandler.showHints = false), | 316 Flags.suppressHints, (_) => diagnosticHandler.showHints = false), |
| 317 // TODO(sigmund): remove entirely after Dart 1.20 |
329 new OptionHandler( | 318 new OptionHandler( |
330 '--output-type=dart|--output-type=dart-multi|--output-type=js', | 319 '--output-type=dart|--output-type=dart-multi|--output-type=js', |
331 setOutputType), | 320 setOutputType), |
332 new OptionHandler(Flags.useCpsIr, passThrough), | 321 new OptionHandler(Flags.useCpsIr, passThrough), |
333 new OptionHandler(Flags.noFrequencyBasedMinification, passThrough), | 322 new OptionHandler(Flags.noFrequencyBasedMinification, passThrough), |
334 new OptionHandler(Flags.verbose, setVerbose), | 323 new OptionHandler(Flags.verbose, setVerbose), |
335 new OptionHandler(Flags.version, (_) => wantVersion = true), | 324 new OptionHandler(Flags.version, (_) => wantVersion = true), |
336 new OptionHandler('--library-root=.+', setLibraryRoot), | 325 new OptionHandler('--library-root=.+', setLibraryRoot), |
337 new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true), | 326 new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true), |
338 new OptionHandler(Flags.allowMockCompilation, passThrough), | 327 new OptionHandler(Flags.allowMockCompilation, passThrough), |
(...skipping 24 matching lines...) Expand all Loading... |
363 new OptionHandler(Flags.analyzeOnly, setAnalyzeOnly), | 352 new OptionHandler(Flags.analyzeOnly, setAnalyzeOnly), |
364 new OptionHandler(Flags.noSourceMaps, passThrough), | 353 new OptionHandler(Flags.noSourceMaps, passThrough), |
365 new OptionHandler(Option.resolutionInput, setResolutionInput), | 354 new OptionHandler(Option.resolutionInput, setResolutionInput), |
366 new OptionHandler(Flags.resolveOnly, setResolveOnly), | 355 new OptionHandler(Flags.resolveOnly, setResolveOnly), |
367 new OptionHandler(Flags.analyzeSignaturesOnly, setAnalyzeOnly), | 356 new OptionHandler(Flags.analyzeSignaturesOnly, setAnalyzeOnly), |
368 new OptionHandler(Flags.disableNativeLiveTypeAnalysis, passThrough), | 357 new OptionHandler(Flags.disableNativeLiveTypeAnalysis, passThrough), |
369 new OptionHandler('--categories=.*', setCategories), | 358 new OptionHandler('--categories=.*', setCategories), |
370 new OptionHandler(Flags.disableTypeInference, implyCompilation), | 359 new OptionHandler(Flags.disableTypeInference, implyCompilation), |
371 new OptionHandler(Flags.terse, passThrough), | 360 new OptionHandler(Flags.terse, passThrough), |
372 new OptionHandler('--deferred-map=.+', implyCompilation), | 361 new OptionHandler('--deferred-map=.+', implyCompilation), |
373 new OptionHandler(Flags.dumpInfo, setDumpInfo), | 362 new OptionHandler(Flags.dumpInfo, implyCompilation), |
374 new OptionHandler( | 363 new OptionHandler( |
375 '--disallow-unsafe-eval', (_) => hasDisallowUnsafeEval = true), | 364 '--disallow-unsafe-eval', (_) => hasDisallowUnsafeEval = true), |
376 new OptionHandler(Option.showPackageWarnings, passThrough), | 365 new OptionHandler(Option.showPackageWarnings, passThrough), |
377 new OptionHandler(Flags.useContentSecurityPolicy, passThrough), | 366 new OptionHandler(Flags.useContentSecurityPolicy, passThrough), |
378 new OptionHandler(Flags.enableExperimentalMirrors, passThrough), | 367 new OptionHandler(Flags.enableExperimentalMirrors, passThrough), |
379 new OptionHandler(Flags.enableAssertMessage, passThrough), | 368 new OptionHandler(Flags.enableAssertMessage, passThrough), |
380 | 369 |
381 // TODO(floitsch): remove conditional directives flag. | 370 // TODO(floitsch): remove conditional directives flag. |
382 // We don't provide the info-message yet, since we haven't publicly | 371 // We don't provide the info-message yet, since we haven't publicly |
383 // launched the feature yet. | 372 // launched the feature yet. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 if (hasDisallowUnsafeEval) { | 411 if (hasDisallowUnsafeEval) { |
423 String precompiledName = relativize( | 412 String precompiledName = relativize( |
424 currentDirectory, | 413 currentDirectory, |
425 RandomAccessFileOutputProvider.computePrecompiledUri(out), | 414 RandomAccessFileOutputProvider.computePrecompiledUri(out), |
426 Platform.isWindows); | 415 Platform.isWindows); |
427 helpAndFail("Option '--disallow-unsafe-eval' has been removed." | 416 helpAndFail("Option '--disallow-unsafe-eval' has been removed." |
428 " Instead, the compiler generates a file named" | 417 " Instead, the compiler generates a file named" |
429 " '$precompiledName'."); | 418 " '$precompiledName'."); |
430 } | 419 } |
431 | 420 |
432 if (outputLanguage != OUTPUT_LANGUAGE_DART && stripArgumentSet) { | |
433 helpAndFail("Option '--force-strip' may only be used with " | |
434 "'--output-type=dart'."); | |
435 } | |
436 if (arguments.isEmpty) { | 421 if (arguments.isEmpty) { |
437 helpAndFail('No Dart file specified.'); | 422 helpAndFail('No Dart file specified.'); |
438 } | 423 } |
439 if (arguments.length > 1) { | 424 if (arguments.length > 1) { |
440 var extra = arguments.sublist(1); | 425 var extra = arguments.sublist(1); |
441 helpAndFail('Extra arguments: ${extra.join(" ")}'); | 426 helpAndFail('Extra arguments: ${extra.join(" ")}'); |
442 } | 427 } |
443 | 428 |
444 if (checkedMode && trustTypeAnnotations) { | 429 if (checkedMode && trustTypeAnnotations) { |
445 helpAndFail("Option '${Flags.trustTypeAnnotations}' may not be used in " | 430 helpAndFail("Option '${Flags.trustTypeAnnotations}' may not be used in " |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 analyzeOnly = analyzeAll = true; | 465 analyzeOnly = analyzeAll = true; |
481 } else if (analyzeAll) { | 466 } else if (analyzeAll) { |
482 analyzeOnly = true; | 467 analyzeOnly = true; |
483 } | 468 } |
484 if (!analyzeOnly) { | 469 if (!analyzeOnly) { |
485 if (allowNativeExtensions) { | 470 if (allowNativeExtensions) { |
486 helpAndFail("Option '${Flags.allowNativeExtensions}' is only supported " | 471 helpAndFail("Option '${Flags.allowNativeExtensions}' is only supported " |
487 "in combination with the '${Flags.analyzeOnly}' option."); | 472 "in combination with the '${Flags.analyzeOnly}' option."); |
488 } | 473 } |
489 } | 474 } |
490 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { | |
491 helpAndFail("Option '${Flags.dumpInfo}' is not supported in " | |
492 "combination with the '--output-type=dart' option."); | |
493 } | |
494 | 475 |
495 options.add('--out=$out'); | 476 options.add('--out=$out'); |
496 options.add('--source-map=$sourceMapOut'); | 477 options.add('--source-map=$sourceMapOut'); |
497 | 478 |
498 RandomAccessFileOutputProvider outputProvider = | 479 RandomAccessFileOutputProvider outputProvider = |
499 new RandomAccessFileOutputProvider(out, sourceMapOut, | 480 new RandomAccessFileOutputProvider(out, sourceMapOut, |
500 onInfo: diagnosticHandler.info, | 481 onInfo: diagnosticHandler.info, |
501 onFailure: fail, | 482 onFailure: fail, |
502 resolutionOutput: resolveOnly ? resolutionOutput : null); | 483 resolutionOutput: resolveOnly ? resolutionOutput : null); |
503 | 484 |
504 api.CompilationResult compilationDone(api.CompilationResult result) { | 485 api.CompilationResult compilationDone(api.CompilationResult result) { |
505 if (analyzeOnly) return result; | 486 if (analyzeOnly) return result; |
506 if (!result.isSuccess) { | 487 if (!result.isSuccess) { |
507 fail('Compilation failed.'); | 488 fail('Compilation failed.'); |
508 } | 489 } |
509 writeString( | 490 writeString( |
510 Uri.parse('$out.deps'), getDepsOutput(inputProvider.sourceFiles)); | 491 Uri.parse('$out.deps'), getDepsOutput(inputProvider.sourceFiles)); |
511 diagnosticHandler | 492 diagnosticHandler |
512 .info('Compiled ${inputProvider.dartCharactersRead} characters Dart ' | 493 .info('Compiled ${inputProvider.dartCharactersRead} characters Dart ' |
513 '-> ${outputProvider.totalCharactersWritten} characters ' | 494 '-> ${outputProvider.totalCharactersWritten} characters ' |
514 '$outputLanguage in ' | 495 'JavaScript in ' |
515 '${relativize(currentDirectory, out, Platform.isWindows)}'); | 496 '${relativize(currentDirectory, out, Platform.isWindows)}'); |
516 if (diagnosticHandler.verbose) { | 497 if (diagnosticHandler.verbose) { |
517 String input = uriPathToNative(arguments[0]); | 498 String input = uriPathToNative(arguments[0]); |
518 print('Dart file ($input) compiled to $outputLanguage.'); | 499 print('Dart file ($input) compiled to JavaScript.'); |
519 print('Wrote the following files:'); | 500 print('Wrote the following files:'); |
520 for (String filename in outputProvider.allOutputFiles) { | 501 for (String filename in outputProvider.allOutputFiles) { |
521 print(" $filename"); | 502 print(" $filename"); |
522 } | 503 } |
523 } else if (explicitOutputArguments.isNotEmpty) { | 504 } else if (explicitOutputArguments.isNotEmpty) { |
524 String input = uriPathToNative(arguments[0]); | 505 String input = uriPathToNative(arguments[0]); |
525 String output = relativize(currentDirectory, out, Platform.isWindows); | 506 String output = relativize(currentDirectory, out, Platform.isWindows); |
526 print('Dart file ($input) compiled to $outputLanguage: $output'); | 507 print('Dart file ($input) compiled to JavaScript: $output'); |
527 } | 508 } |
528 return result; | 509 return result; |
529 } | 510 } |
530 | 511 |
531 Uri script = currentDirectory.resolve(arguments[0]); | 512 Uri script = currentDirectory.resolve(arguments[0]); |
532 CompilerOptions compilerOptions = new CompilerOptions.parse( | 513 CompilerOptions compilerOptions = new CompilerOptions.parse( |
533 entryPoint: script, | 514 entryPoint: script, |
534 libraryRoot: libraryRoot, | 515 libraryRoot: libraryRoot, |
535 packageRoot: packageRoot, | 516 packageRoot: packageRoot, |
536 packageConfig: packageConfig, | 517 packageConfig: packageConfig, |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 @override | 1000 @override |
1020 void close() { | 1001 void close() { |
1021 // Do nothing. | 1002 // Do nothing. |
1022 } | 1003 } |
1023 | 1004 |
1024 @override | 1005 @override |
1025 void addError(errorEvent, [StackTrace stackTrace]) { | 1006 void addError(errorEvent, [StackTrace stackTrace]) { |
1026 // Ignore | 1007 // Ignore |
1027 } | 1008 } |
1028 } | 1009 } |
OLD | NEW |