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

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
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | pkg/compiler/lib/src/mirrors/analyze.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (arguments.length > 1) { 404 if (arguments.length > 1) {
398 var extra = arguments.sublist(1); 405 var extra = arguments.sublist(1);
399 helpAndFail('Extra arguments: ${extra.join(" ")}'); 406 helpAndFail('Extra arguments: ${extra.join(" ")}');
400 } 407 }
401 408
402 if (checkedMode && trustTypeAnnotations) { 409 if (checkedMode && trustTypeAnnotations) {
403 helpAndFail("Option '--trust-type-annotations' may not be used in " 410 helpAndFail("Option '--trust-type-annotations' may not be used in "
404 "checked mode."); 411 "checked mode.");
405 } 412 }
406 413
407 Uri uri = currentDirectory.resolve(arguments[0]); 414 if (packageRoot != null && packageConfig != null) {
408 if (packageRoot == null) { 415 helpAndFail("Cannot specify both '--package-root' and '--packages.");
409 packageRoot = uri.resolve('./packages/');
410 } 416 }
411 417
412 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { 418 if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) {
413 if (!analyzeOnly) { 419 if (!analyzeOnly) {
414 diagnosticHandler.info( 420 diagnosticHandler.info(
415 "Option '--analyze-all' implies '--analyze-only'.", 421 "Option '--analyze-all' implies '--analyze-only'.",
416 api.Diagnostic.INFO); 422 api.Diagnostic.INFO);
417 } 423 }
418 diagnosticHandler.info( 424 diagnosticHandler.info(
419 "Options $optionsImplyCompilation indicate that output is expected, " 425 "Options $optionsImplyCompilation indicate that output is expected, "
420 "but compilation is turned off by the option '--analyze-only'.", 426 "but compilation is turned off by the option '--analyze-only'.",
421 api.Diagnostic.INFO); 427 api.Diagnostic.INFO);
422 } 428 }
423 if (analyzeAll) analyzeOnly = true; 429 if (analyzeAll) analyzeOnly = true;
424 if (!analyzeOnly) { 430 if (!analyzeOnly) {
425 if (allowNativeExtensions) { 431 if (allowNativeExtensions) {
426 helpAndFail("Option '--allow-native-extensions' is only supported in " 432 helpAndFail("Option '--allow-native-extensions' is only supported in "
427 "combination with the '--analyze-only' option."); 433 "combination with the '--analyze-only' option.");
428 } 434 }
429 } 435 }
430 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) { 436 if (dumpInfo && outputLanguage == OUTPUT_LANGUAGE_DART) {
431 helpAndFail("Option '--dump-info' is not supported in " 437 helpAndFail("Option '--dump-info' is not supported in "
432 "combination with the '--output-type=dart' option."); 438 "combination with the '--output-type=dart' option.");
433 } 439 }
434 440
435 diagnosticHandler.info('Package root is $packageRoot');
436
437 options.add('--out=$out'); 441 options.add('--out=$out');
438 options.add('--source-map=$sourceMapOut'); 442 options.add('--source-map=$sourceMapOut');
439 443
440 RandomAccessFileOutputProvider outputProvider = 444 RandomAccessFileOutputProvider outputProvider =
441 new RandomAccessFileOutputProvider( 445 new RandomAccessFileOutputProvider(
442 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail); 446 out, sourceMapOut, onInfo: diagnosticHandler.info, onFailure: fail);
443 447
444 api.CompilationResult compilationDone(api.CompilationResult result) { 448 api.CompilationResult compilationDone(api.CompilationResult result) {
445 if (analyzeOnly) return result; 449 if (analyzeOnly) return result;
446 if (!result.isSuccess) { 450 if (!result.isSuccess) {
(...skipping 14 matching lines...) Expand all
461 print(" $filename"); 465 print(" $filename");
462 } 466 }
463 } else if (!explicitOut) { 467 } else if (!explicitOut) {
464 String input = uriPathToNative(arguments[0]); 468 String input = uriPathToNative(arguments[0]);
465 String output = relativize(currentDirectory, out, Platform.isWindows); 469 String output = relativize(currentDirectory, out, Platform.isWindows);
466 print('Dart file ($input) compiled to $outputLanguage: $output'); 470 print('Dart file ($input) compiled to $outputLanguage: $output');
467 } 471 }
468 return result; 472 return result;
469 } 473 }
470 474
471 return compileFunc(uri, libraryRoot, packageRoot, 475 Uri uri = currentDirectory.resolve(arguments[0]);
472 inputProvider, diagnosticHandler, 476 return compileFunc(uri, libraryRoot, packageRoot, inputProvider,
473 options, outputProvider, environment) 477 diagnosticHandler, options, outputProvider, environment,
478 packageConfig, findPackages)
474 .then(compilationDone); 479 .then(compilationDone);
475 } 480 }
476 481
477 class AbortLeg { 482 class AbortLeg {
478 final message; 483 final message;
479 AbortLeg(this.message); 484 AbortLeg(this.message);
480 toString() => 'Aborted due to --throw-on-error: $message'; 485 toString() => 'Aborted due to --throw-on-error: $message';
481 } 486 }
482 487
483 void writeString(Uri uri, String text) { 488 void writeString(Uri uri, String text) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 -v, --verbose 550 -v, --verbose
546 Display verbose information. 551 Display verbose information.
547 552
548 -D<name>=<value> 553 -D<name>=<value>
549 Define an environment variable. 554 Define an environment variable.
550 555
551 --version 556 --version
552 Display version information. 557 Display version information.
553 558
554 -p<path>, --package-root=<path> 559 -p<path>, --package-root=<path>
555 Where to find packages, that is, "package:..." imports. 560 Where to find packages, that is, "package:..." imports. This option cannot
561 be used with --packages.
562
563 --packages=<path>
564 Path to the package resolution configuration file, which supplies a mapping
565 of package names to paths. This option cannot be used with --package-root.
556 566
557 --analyze-all 567 --analyze-all
558 Analyze all code. Without this option, the compiler only analyzes 568 Analyze all code. Without this option, the compiler only analyzes
559 code that is reachable from [main]. This option implies --analyze-only. 569 code that is reachable from [main]. This option implies --analyze-only.
560 570
561 --analyze-only 571 --analyze-only
562 Analyze but do not generate code. 572 Analyze but do not generate code.
563 573
564 --analyze-signatures-only 574 --analyze-signatures-only
565 Skip analysis of method bodies and field initializers. This option implies 575 Skip analysis of method bodies and field initializers. This option implies
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 } else if (exitCode == 253) { 755 } else if (exitCode == 253) {
746 print(">>> TEST CRASH"); 756 print(">>> TEST CRASH");
747 } else { 757 } else {
748 print(">>> TEST FAIL"); 758 print(">>> TEST FAIL");
749 } 759 }
750 stderr.writeln(">>> EOF STDERR"); 760 stderr.writeln(">>> EOF STDERR");
751 subscription.resume(); 761 subscription.resume();
752 }); 762 });
753 }); 763 });
754 } 764 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/apiimpl.dart ('k') | pkg/compiler/lib/src/mirrors/analyze.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698