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

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

Issue 1404183002: Add support for 'dart.library.X' environment variables in dart2js. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Use sdkLibraries. Created 4 years, 11 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 | « no previous file | tests/compiler/dart2js/library_env_test.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 leg_apiimpl; 5 library leg_apiimpl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:package_config/packages.dart'; 10 import 'package:package_config/packages.dart';
(...skipping 15 matching lines...) Expand all
26 import 'diagnostics/messages.dart' show 26 import 'diagnostics/messages.dart' show
27 Message; 27 Message;
28 import 'elements/elements.dart' as elements; 28 import 'elements/elements.dart' as elements;
29 import 'io/source_file.dart'; 29 import 'io/source_file.dart';
30 import 'platform_configuration.dart' as platform_configuration; 30 import 'platform_configuration.dart' as platform_configuration;
31 import 'script.dart'; 31 import 'script.dart';
32 32
33 const bool forceIncrementalSupport = 33 const bool forceIncrementalSupport =
34 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT'); 34 const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT');
35 35
36 /// For every 'dart:' library, a corresponding environment variable is set
37 /// to "true". The environment variable's name is the concatenation of
38 /// this prefix and the name (without the 'dart:'.
39 ///
40 /// For example 'dart:html' has the environment variable 'dart.library.html' set
41 /// to "true".
42 const String dartLibraryEnvironmentPrefix = 'dart.library.';
43
36 /// Locations of the platform descriptor files relative to the library root. 44 /// Locations of the platform descriptor files relative to the library root.
37 const String _clientPlatform = "lib/dart_client.platform"; 45 const String _clientPlatform = "lib/dart_client.platform";
38 const String _serverPlatform = "lib/dart_server.platform"; 46 const String _serverPlatform = "lib/dart_server.platform";
39 const String _sharedPlatform = "lib/dart_shared.platform"; 47 const String _sharedPlatform = "lib/dart_shared.platform";
40 const String _dart2dartPlatform = "lib/dart2dart.platform"; 48 const String _dart2dartPlatform = "lib/dart2dart.platform";
41 49
42 /// Implements the [Compiler] using a [api.CompilerInput] for supplying the 50 /// Implements the [Compiler] using a [api.CompilerInput] for supplying the
43 /// sources. 51 /// sources.
44 class CompilerImpl extends Compiler { 52 class CompilerImpl extends Compiler {
45 api.CompilerInput provider; 53 api.CompilerInput provider;
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 Future<Packages> callUserPackagesDiscovery(Uri uri) { 581 Future<Packages> callUserPackagesDiscovery(Uri uri) {
574 try { 582 try {
575 return userPackagesDiscoveryTask.measure( 583 return userPackagesDiscoveryTask.measure(
576 () => packagesDiscoveryProvider(uri)); 584 () => packagesDiscoveryProvider(uri));
577 } catch (ex, s) { 585 } catch (ex, s) {
578 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s); 586 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s);
579 rethrow; 587 rethrow;
580 } 588 }
581 } 589 }
582 590
583 fromEnvironment(String name) => environment[name]; 591 fromEnvironment(String name) {
592 assert(invariant(NO_LOCATION_SPANNABLE,
593 sdkLibraries != null, message: "setupSdk() has not been run"));
594 var result = environment[name];
595 if (result == null && !environment.containsKey(name) &&
sigurdm 2016/01/08 09:45:11 The logic is a bit convoluted. It might be easier
floitsch 2016/01/08 15:51:01 Refactored so that we have early returns.
596 name.startsWith(dartLibraryEnvironmentPrefix)) {
597 String libraryName = name.substring(dartLibraryEnvironmentPrefix.length);
598 if (sdkLibraries.containsKey(libraryName)) {
599 // Dart2js always "supports" importing 'dart:mirrors' but will abort
600 // the compilation at a later point if the backend doesn't support
601 // mirrors. In this case 'mirrors' should not be in the environment.
602 if (name == dartLibraryEnvironmentPrefix + 'mirrors') {
603 return backend.supportsReflection ? "true" : null;
604 }
605 return "true";
606 }
607 }
608 return result;
609 }
584 610
585 Uri lookupLibraryUri(String libraryName) { 611 Uri lookupLibraryUri(String libraryName) {
586 assert(invariant(NO_LOCATION_SPANNABLE, 612 assert(invariant(NO_LOCATION_SPANNABLE,
587 sdkLibraries != null, message: "setupSdk() has not been run")); 613 sdkLibraries != null, message: "setupSdk() has not been run"));
588 return sdkLibraries[libraryName]; 614 return sdkLibraries[libraryName];
589 } 615 }
590 616
591 Uri resolvePatchUri(String libraryName) { 617 Uri resolvePatchUri(String libraryName) {
592 return backend.resolvePatchUri(libraryName, platformConfigUri); 618 return backend.resolvePatchUri(libraryName, platformConfigUri);
593 } 619 }
594 } 620 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/library_env_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698