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

Side by Side Diff: pkg/compiler/lib/src/dart2js.dart

Issue 1162363004: Support Package Resolution Configuration files. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
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' 7 import 'dart:async'
8 show Future, EventSink; 8 show Future, EventSink;
9 import 'dart:convert' show UTF8, LineSplitter; 9 import 'dart:convert' show UTF8, LineSplitter;
10 import 'dart:io' 10 import 'dart:io'
11 show exit, File, FileMode, Platform, RandomAccessFile, FileSystemException, 11 show exit, File, FileMode, Platform, RandomAccessFile, FileSystemException,
12 stdin, stderr; 12 stdin, stderr;
13 13
14 import '../compiler.dart' as api; 14 import '../compiler.dart' as api;
15 import 'io/source_file.dart'; 15 import 'io/source_file.dart';
16 import 'source_file_provider.dart'; 16 import 'source_file_provider.dart';
17 import 'filenames.dart'; 17 import 'filenames.dart';
18 import 'util/uri_extras.dart'; 18 import 'util/uri_extras.dart';
19 import 'util/util.dart' show stackTraceFilePrefix; 19 import 'util/util.dart' show stackTraceFilePrefix;
20 import 'util/command_line.dart'; 20 import 'util/command_line.dart';
21 import 'package:_internal/libraries.dart'; 21 import 'package:_internal/libraries.dart';
22 import 'package:package_config/discovery.dart' show findPackages;
22 23
23 const String LIBRARY_ROOT = '../../../../../sdk'; 24 const String LIBRARY_ROOT = '../../../../../sdk';
24 const String OUTPUT_LANGUAGE_DART = 'Dart'; 25 const String OUTPUT_LANGUAGE_DART = 'Dart';
25 26
26 /** 27 /**
27 * A string to identify the revision or build. 28 * A string to identify the revision or build.
28 * 29 *
29 * This ID is displayed if the compiler crashes and in verbose mode, and is 30 * This ID is displayed if the compiler crashes and in verbose mode, and is
30 * an aid in reproducing bug reports. 31 * an aid in reproducing bug reports.
31 * 32 *
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 99 }
99 } 100 }
100 101
101 FormattingDiagnosticHandler diagnosticHandler; 102 FormattingDiagnosticHandler diagnosticHandler;
102 103
103 Future<api.CompilationResult> compile(List<String> argv) { 104 Future<api.CompilationResult> compile(List<String> argv) {
104 stackTraceFilePrefix = '$currentDirectory'; 105 stackTraceFilePrefix = '$currentDirectory';
105 Uri libraryRoot = currentDirectory; 106 Uri libraryRoot = currentDirectory;
106 Uri out = currentDirectory.resolve('out.js'); 107 Uri out = currentDirectory.resolve('out.js');
107 Uri sourceMapOut = currentDirectory.resolve('out.js.map'); 108 Uri sourceMapOut = currentDirectory.resolve('out.js.map');
109 Uri packageConfig = null;
108 Uri packageRoot = null; 110 Uri packageRoot = null;
109 List<String> options = new List<String>(); 111 List<String> options = new List<String>();
110 bool explicitOut = false; 112 bool explicitOut = false;
111 bool wantHelp = false; 113 bool wantHelp = false;
112 bool wantVersion = false; 114 bool wantVersion = false;
113 String outputLanguage = 'JavaScript'; 115 String outputLanguage = 'JavaScript';
114 bool stripArgumentSet = false; 116 bool stripArgumentSet = false;
115 bool analyzeOnly = false; 117 bool analyzeOnly = false;
116 bool analyzeAll = false; 118 bool analyzeAll = false;
117 bool dumpInfo = false; 119 bool dumpInfo = false;
(...skipping 15 matching lines...) Expand all
133 } 135 }
134 136
135 setLibraryRoot(String argument) { 137 setLibraryRoot(String argument) {
136 libraryRoot = currentDirectory.resolve(extractPath(argument)); 138 libraryRoot = currentDirectory.resolve(extractPath(argument));
137 } 139 }
138 140
139 setPackageRoot(String argument) { 141 setPackageRoot(String argument) {
140 packageRoot = currentDirectory.resolve(extractPath(argument)); 142 packageRoot = currentDirectory.resolve(extractPath(argument));
141 } 143 }
142 144
145 setPackageConfig(String argument) {
146 packageConfig = currentDirectory.resolve(extractPath(argument));
147 }
148
143 setOutput(Iterator<String> arguments) { 149 setOutput(Iterator<String> arguments) {
144 optionsImplyCompilation.add(arguments.current); 150 optionsImplyCompilation.add(arguments.current);
145 String path; 151 String path;
146 if (arguments.current == '-o') { 152 if (arguments.current == '-o') {
147 if (!arguments.moveNext()) { 153 if (!arguments.moveNext()) {
148 helpAndFail('Error: Missing file after -o option.'); 154 helpAndFail('Error: Missing file after -o option.');
149 } 155 }
150 path = arguments.current; 156 path = arguments.current;
151 } else { 157 } else {
152 path = extractParameter(arguments.current); 158 path = extractParameter(arguments.current);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 new OptionHandler('--enable-concrete-type-inference', 328 new OptionHandler('--enable-concrete-type-inference',
323 (_) => implyCompilation( 329 (_) => implyCompilation(
324 '--enable-concrete-type-inference')), 330 '--enable-concrete-type-inference')),
325 new OptionHandler('--trust-type-annotations', 331 new OptionHandler('--trust-type-annotations',
326 (_) => setTrustTypeAnnotations( 332 (_) => setTrustTypeAnnotations(
327 '--trust-type-annotations')), 333 '--trust-type-annotations')),
328 new OptionHandler('--trust-primitives', 334 new OptionHandler('--trust-primitives',
329 (_) => setTrustPrimitives( 335 (_) => setTrustPrimitives(
330 '--trust-primitives')), 336 '--trust-primitives')),
331 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), 337 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true),
338 new OptionHandler('--packages=.+', setPackageConfig),
332 new OptionHandler('--package-root=.+|-p.+', setPackageRoot), 339 new OptionHandler('--package-root=.+|-p.+', setPackageRoot),
333 new OptionHandler('--analyze-all', setAnalyzeAll), 340 new OptionHandler('--analyze-all', setAnalyzeAll),
334 new OptionHandler('--analyze-only', setAnalyzeOnly), 341 new OptionHandler('--analyze-only', setAnalyzeOnly),
335 new OptionHandler('--no-source-maps', passThrough), 342 new OptionHandler('--no-source-maps', passThrough),
336 new OptionHandler('--analyze-signatures-only', setAnalyzeOnly), 343 new OptionHandler('--analyze-signatures-only', setAnalyzeOnly),
337 new OptionHandler('--disable-native-live-type-analysis', passThrough), 344 new OptionHandler('--disable-native-live-type-analysis', passThrough),
338 new OptionHandler('--categories=.*', setCategories), 345 new OptionHandler('--categories=.*', setCategories),
339 new OptionHandler('--disable-type-inference', implyCompilation), 346 new OptionHandler('--disable-type-inference', implyCompilation),
340 new OptionHandler('--terse', passThrough), 347 new OptionHandler('--terse', passThrough),
341 new OptionHandler('--deferred-map=.+', implyCompilation), 348 new OptionHandler('--deferred-map=.+', implyCompilation),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 if (arguments.length > 1) { 403 if (arguments.length > 1) {
397 var extra = arguments.sublist(1); 404 var extra = arguments.sublist(1);
398 helpAndFail('Extra arguments: ${extra.join(" ")}'); 405 helpAndFail('Extra arguments: ${extra.join(" ")}');
399 } 406 }
400 407
401 if (checkedMode && trustTypeAnnotations) { 408 if (checkedMode && trustTypeAnnotations) {
402 helpAndFail("Option '--trust-type-annotations' may not be used in " 409 helpAndFail("Option '--trust-type-annotations' may not be used in "
403 "checked mode."); 410 "checked mode.");
404 } 411 }
405 412
406 Uri uri = currentDirectory.resolve(arguments[0]); 413 if (packageRoot != null && packageConfig != null) {
407 if (packageRoot == null) { 414 helpAndFail("Cannot specify both '--package-root' and '--packages.");
408 packageRoot = uri.resolve('./packages/');
409 } 415 }
410 416
411 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { 417 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) {
412 if (!analyzeOnly) { 418 if (!analyzeOnly) {
413 diagnosticHandler.info( 419 diagnosticHandler.info(
414 "Option '--analyze-all' implies '--analyze-only'.", 420 "Option '--analyze-all' implies '--analyze-only'.",
415 api.Diagnostic.INFO); 421 api.Diagnostic.INFO);
416 } 422 }
417 diagnosticHandler.info( 423 diagnosticHandler.info(
418 "Options $optionsImplyCompilation indicate that output is expected, " 424 "Options $optionsImplyCompilation indicate that output is expected, "
419 "but compilation is turned off by the option '--analyze-only'.", 425 "but compilation is turned off by the option '--analyze-only'.",
420 api.Diagnostic.INFO); 426 api.Diagnostic.INFO);
421 } 427 }
422 if (analyzeAll) analyzeOnly = true; 428 if (analyzeAll) analyzeOnly = true;
423 if (!analyzeOnly) { 429 if (!analyzeOnly) {
424 if (allowNativeExtensions) { 430 if (allowNativeExtensions) {
425 helpAndFail("Option '--allow-native-extensions' is only supported in " 431 helpAndFail("Option '--allow-native-extensions' is only supported in "
426 "combination with the '--analyze-only' option."); 432 "combination with the '--analyze-only' option.");
427 } 433 }
428 } 434 }
429 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { 435 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) {
430 helpAndFail("Option '--dump-info' is not supported in " 436 helpAndFail("Option '--dump-info' is not supported in "
431 "combination with the '--output-type=dart' option."); 437 "combination with the '--output-type=dart' option.");
432 } 438 }
433 439
434 diagnosticHandler.info('Package root is $packageRoot');
435
436 options.add('--out=$out'); 440 options.add('--out=$out');
437 options.add('--source-map=$sourceMapOut'); 441 options.add('--source-map=$sourceMapOut');
438 442
439 RandomAccessFileOutputProvider outputProvider = 443 RandomAccessFileOutputProvider outputProvider =
440 new RandomAccessFileOutputProvider( 444 new RandomAccessFileOutputProvider(
441 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail); 445 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail);
442 446
443 api.CompilationResult compilationDone(api.CompilationResult result) { 447 api.CompilationResult compilationDone(api.CompilationResult result) {
444 if (analyzeOnly) return result; 448 if (analyzeOnly) return result;
445 if (!result.isSuccess) { 449 if (!result.isSuccess) {
(...skipping 14 matching lines...) Expand all
460 print(" $filename"); 464 print(" $filename");
461 } 465 }
462 } else if (!explicitOut) { 466 } else if (!explicitOut) {
463 String input = uriPathToNative(arguments[0]); 467 String input = uriPathToNative(arguments[0]);
464 String output = relativize(currentDirectory, out, Platform.isWindows); 468 String output = relativize(currentDirectory, out, Platform.isWindows);
465 print('Dart file ($input) compiled to $outputLanguage: $output'); 469 print('Dart file ($input) compiled to $outputLanguage: $output');
466 } 470 }
467 return result; 471 return result;
468 } 472 }
469 473
470 return compileFunc(uri, libraryRoot, packageRoot, 474 Uri uri = currentDirectory.resolve(arguments[0]);
471 inputProvider, diagnosticHandler, 475 return compileFunc(uri, libraryRoot, packageRoot, inputProvider,
472 options, outputProvider, environment) 476 diagnosticHandler, options, outputProvider, environment,
477 packageConfig, findPackages)
473 .then(compilationDone); 478 .then(compilationDone);
474 } 479 }
475 480
476 class AbortLeg { 481 class AbortLeg {
477 final message; 482 final message;
478 AbortLeg(this.message); 483 AbortLeg(this.message);
479 toString() => 'Aborted due to --throw-on-error: $message'; 484 toString() => 'Aborted due to --throw-on-error: $message';
480 } 485 }
481 486
482 void writeString(Uri uri, String text) { 487 void writeString(Uri uri, String text) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 -v, --verbose 549 -v, --verbose
545 Display verbose information. 550 Display verbose information.
546 551
547 -D<name>=<value> 552 -D<name>=<value>
548 Define an environment variable. 553 Define an environment variable.
549 554
550 --version 555 --version
551 Display version information. 556 Display version information.
552 557
553 -p<path>, --package-root=<path> 558 -p<path>, --package-root=<path>
554 Where to find packages, that is, "package:..." imports. 559 Where to find packages, that is, "package:..." imports. This option cannot
560 be used with --packages.
561
562 --packages=<path>
563 Path to the package resolution configuration file, which supplies a mapping
564 of package names to paths. This option cannot be used with --package-root.
555 565
556 --analyze-all 566 --analyze-all
557 Analyze all code. Without this option, the compiler only analyzes 567 Analyze all code. Without this option, the compiler only analyzes
558 code that is reachable from [main]. This option implies --analyze-only. 568 code that is reachable from [main]. This option implies --analyze-only.
559 569
560 --analyze-only 570 --analyze-only
561 Analyze but do not generate code. 571 Analyze but do not generate code.
562 572
563 --analyze-signatures-only 573 --analyze-signatures-only
564 Skip analysis of method bodies and field initializers. This option implies 574 Skip analysis of method bodies and field initializers. This option implies
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 } else if (exitCode == 253) { 754 } else if (exitCode == 253) {
745 print(">>> TEST CRASH"); 755 print(">>> TEST CRASH");
746 } else { 756 } else {
747 print(">>> TEST FAIL"); 757 print(">>> TEST FAIL");
748 } 758 }
749 stderr.writeln(">>> EOF STDERR"); 759 stderr.writeln(">>> EOF STDERR");
750 subscription.resume(); 760 subscription.resume();
751 }); 761 });
752 }); 762 });
753 } 763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698