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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart2js.dart

Issue 48323003: Implement fromEnvironment on bool, int, String in dart2js. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
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 import 'dart:io' 8 import 'dart:io'
9 show exit, File, FileMode, Platform, RandomAccessFile; 9 show exit, File, FileMode, Platform, RandomAccessFile;
10 import 'dart:math' as math; 10 import 'dart:math' as math;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 bool explicitOut = false; 105 bool explicitOut = false;
106 bool wantHelp = false; 106 bool wantHelp = false;
107 bool wantVersion = false; 107 bool wantVersion = false;
108 String outputLanguage = 'JavaScript'; 108 String outputLanguage = 'JavaScript';
109 bool stripArgumentSet = false; 109 bool stripArgumentSet = false;
110 bool analyzeOnly = false; 110 bool analyzeOnly = false;
111 bool hasDisallowUnsafeEval = false; 111 bool hasDisallowUnsafeEval = false;
112 // TODO(johnniwinther): Measure time for reading files. 112 // TODO(johnniwinther): Measure time for reading files.
113 SourceFileProvider inputProvider = new CompilerSourceFileProvider(); 113 SourceFileProvider inputProvider = new CompilerSourceFileProvider();
114 diagnosticHandler = new FormattingDiagnosticHandler(inputProvider); 114 diagnosticHandler = new FormattingDiagnosticHandler(inputProvider);
115 Map<String, dynamic> environment = new Map<String, dynamic>();
115 116
116 passThrough(String argument) => options.add(argument); 117 passThrough(String argument) => options.add(argument);
117 118
118 if (BUILD_ID != null) { 119 if (BUILD_ID != null) {
119 passThrough("--build-id=$BUILD_ID"); 120 passThrough("--build-id=$BUILD_ID");
120 } 121 }
121 122
122 setLibraryRoot(String argument) { 123 setLibraryRoot(String argument) {
123 libraryRoot = currentDirectory.resolve(extractPath(argument)); 124 libraryRoot = currentDirectory.resolve(extractPath(argument));
124 } 125 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 setAnalyzeOnly(String argument) { 168 setAnalyzeOnly(String argument) {
168 analyzeOnly = true; 169 analyzeOnly = true;
169 passThrough(argument); 170 passThrough(argument);
170 } 171 }
171 172
172 setVerbose(_) { 173 setVerbose(_) {
173 diagnosticHandler.verbose = true; 174 diagnosticHandler.verbose = true;
174 passThrough('--verbose'); 175 passThrough('--verbose');
175 } 176 }
176 177
178 addInEnvironment(String argument) {
179 int eqIndex = argument.indexOf('=');
180 String name = argument.substring(2, eqIndex);
181 String value = argument.substring(eqIndex + 1);
182 environment[name] = value;
183 }
184
177 setCategories(String argument) { 185 setCategories(String argument) {
178 List<String> categories = extractParameter(argument).split(','); 186 List<String> categories = extractParameter(argument).split(',');
179 Set<String> allowedCategories = 187 Set<String> allowedCategories =
180 LIBRARIES.values.map((x) => x.category).toSet(); 188 LIBRARIES.values.map((x) => x.category).toSet();
181 allowedCategories.remove('Shared'); 189 allowedCategories.remove('Shared');
182 allowedCategories.remove('Internal'); 190 allowedCategories.remove('Internal');
183 List<String> allowedCategoriesList = 191 List<String> allowedCategoriesList =
184 new List<String>.from(allowedCategories); 192 new List<String>.from(allowedCategories);
185 allowedCategoriesList.sort(); 193 allowedCategoriesList.sort();
186 if (categories.contains('all')) { 194 if (categories.contains('all')) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 new OptionHandler('--analyze-all', passThrough), 276 new OptionHandler('--analyze-all', passThrough),
269 new OptionHandler('--analyze-only', setAnalyzeOnly), 277 new OptionHandler('--analyze-only', setAnalyzeOnly),
270 new OptionHandler('--analyze-signatures-only', passThrough), 278 new OptionHandler('--analyze-signatures-only', passThrough),
271 new OptionHandler('--disable-native-live-type-analysis', passThrough), 279 new OptionHandler('--disable-native-live-type-analysis', passThrough),
272 new OptionHandler('--categories=.*', setCategories), 280 new OptionHandler('--categories=.*', setCategories),
273 new OptionHandler('--global-js-name=.*', checkGlobalName), 281 new OptionHandler('--global-js-name=.*', checkGlobalName),
274 new OptionHandler('--disable-type-inference', passThrough), 282 new OptionHandler('--disable-type-inference', passThrough),
275 new OptionHandler('--terse', passThrough), 283 new OptionHandler('--terse', passThrough),
276 new OptionHandler('--disallow-unsafe-eval', 284 new OptionHandler('--disallow-unsafe-eval',
277 (_) => hasDisallowUnsafeEval = true), 285 (_) => hasDisallowUnsafeEval = true),
286 new OptionHandler('-D.+=.*', addInEnvironment),
278 287
279 // The following two options must come last. 288 // The following two options must come last.
280 new OptionHandler('-.*', (String argument) { 289 new OptionHandler('-.*', (String argument) {
281 helpAndFail('Error: Unknown option "$argument".'); 290 helpAndFail('Error: Unknown option "$argument".');
282 }), 291 }),
283 new OptionHandler('.*', (String argument) { 292 new OptionHandler('.*', (String argument) {
284 arguments.add(nativeToUriPath(argument)); 293 arguments.add(nativeToUriPath(argument));
285 }) 294 })
286 ]; 295 ];
287 296
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 if (isPrimaryOutput) { 413 if (isPrimaryOutput) {
405 totalCharactersWritten += charactersWritten; 414 totalCharactersWritten += charactersWritten;
406 } 415 }
407 } 416 }
408 417
409 return new EventSinkWrapper(writeStringSync, onDone); 418 return new EventSinkWrapper(writeStringSync, onDone);
410 } 419 }
411 420
412 return api.compile(uri, libraryRoot, packageRoot, 421 return api.compile(uri, libraryRoot, packageRoot,
413 inputProvider, diagnosticHandler, 422 inputProvider, diagnosticHandler,
414 options, outputProvider) 423 options, outputProvider, environment)
415 .then(compilationDone); 424 .then(compilationDone);
416 } 425 }
417 426
418 class EventSinkWrapper extends EventSink<String> { 427 class EventSinkWrapper extends EventSink<String> {
419 var onAdd, onClose; 428 var onAdd, onClose;
420 429
421 EventSinkWrapper(this.onAdd, this.onClose); 430 EventSinkWrapper(this.onAdd, this.onClose);
422 431
423 void add(String data) => onAdd(data); 432 void add(String data) => onAdd(data);
424 433
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 496
488 -c, --enable-checked-mode, --checked 497 -c, --enable-checked-mode, --checked
489 Insert runtime type checks and enable assertions (checked mode). 498 Insert runtime type checks and enable assertions (checked mode).
490 499
491 -h, /h, /?, --help 500 -h, /h, /?, --help
492 Display this message (add -v for information about all options). 501 Display this message (add -v for information about all options).
493 502
494 -v, --verbose 503 -v, --verbose
495 Display verbose information. 504 Display verbose information.
496 505
506 -D<name>=<value>
507 Define an environment variable.
508
497 --version 509 --version
498 Display version information. 510 Display version information.
499 511
500 -p<path>, --package-root=<path> 512 -p<path>, --package-root=<path>
501 Where to find packages, that is, "package:..." imports. 513 Where to find packages, that is, "package:..." imports.
502 514
503 --analyze-all 515 --analyze-all
504 Analyze all code. Without this option, the compiler only analyzes 516 Analyze all code. Without this option, the compiler only analyzes
505 code that is reachable from [main]. This option is useful for 517 code that is reachable from [main]. This option is useful for
506 finding errors in libraries, but using it can result in bigger and 518 finding errors in libraries, but using it can result in bigger and
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 611
600 try { 612 try {
601 if (trace != null) { 613 if (trace != null) {
602 print(trace); 614 print(trace);
603 } 615 }
604 } finally { 616 } finally {
605 exit(253); // 253 is recognized as a crash by our test scripts. 617 exit(253); // 253 is recognized as a crash by our test scripts.
606 } 618 }
607 }); 619 });
608 } 620 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698