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

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: Adapt test. 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
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
595 var result = environment[name];
596 if (result != null || environment.containsKey(name)) return result;
597 if (!name.startsWith(dartLibraryEnvironmentPrefix)) return null;
598
599 String libraryName = name.substring(dartLibraryEnvironmentPrefix.length);
600 if (sdkLibraries.containsKey(libraryName)) {
601 // Dart2js always "supports" importing 'dart:mirrors' but will abort
602 // the compilation at a later point if the backend doesn't support
603 // mirrors. In this case 'mirrors' should not be in the environment.
604 if (name == dartLibraryEnvironmentPrefix + 'mirrors') {
605 return backend.supportsReflection ? "true" : null;
606 }
607 return "true";
608 }
609 return null;
610 }
584 611
585 Uri lookupLibraryUri(String libraryName) { 612 Uri lookupLibraryUri(String libraryName) {
586 assert(invariant(NO_LOCATION_SPANNABLE, 613 assert(invariant(NO_LOCATION_SPANNABLE,
587 sdkLibraries != null, message: "setupSdk() has not been run")); 614 sdkLibraries != null, message: "setupSdk() has not been run"));
588 return sdkLibraries[libraryName]; 615 return sdkLibraries[libraryName];
589 } 616 }
590 617
591 Uri resolvePatchUri(String libraryName) { 618 Uri resolvePatchUri(String libraryName) {
592 return backend.resolvePatchUri(libraryName, platformConfigUri); 619 return backend.resolvePatchUri(libraryName, platformConfigUri);
593 } 620 }
594 } 621 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/library_env_test.dart » ('j') | tests/compiler/dart2js/library_env_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698