| Index: pkg/compiler/lib/src/apiimpl.dart
|
| diff --git a/pkg/compiler/lib/src/apiimpl.dart b/pkg/compiler/lib/src/apiimpl.dart
|
| index ac5670047699cd92a91b2e0499802ad24ea42889..e515631bdb9163d8f06ebf1a796f860c2402b6ad 100644
|
| --- a/pkg/compiler/lib/src/apiimpl.dart
|
| +++ b/pkg/compiler/lib/src/apiimpl.dart
|
| @@ -14,7 +14,9 @@ import 'package:package_config/src/packages_impl.dart' show
|
| NonFilePackagesDirectoryPackages;
|
| import 'package:package_config/src/util.dart' show
|
| checkValidPackageUri;
|
| -import 'package:sdk_library_metadata/libraries.dart' as library_info;
|
| +import 'package:sdk_library_metadata/libraries.dart' hide LIBRARIES;
|
| +import 'package:sdk_library_metadata/libraries.dart' as library_info show
|
| + LIBRARIES;
|
|
|
| import '../compiler_new.dart' as api;
|
| import 'commandline_options.dart';
|
| @@ -48,7 +50,7 @@ class Compiler extends leg.Compiler {
|
| List<String> options;
|
| Map<String, dynamic> environment;
|
| bool mockableLibraryUsed = false;
|
| - final Set<library_info.Category> allowedLibraryCategories;
|
| + final Set<String> allowedLibraryCategories;
|
|
|
| GenericTask userHandlerTask;
|
| GenericTask userProviderTask;
|
| @@ -177,24 +179,38 @@ class Compiler extends leg.Compiler {
|
| return const <String>[];
|
| }
|
|
|
| - static Set<library_info.Category> getAllowedLibraryCategories(
|
| - List<String> options) {
|
| - Iterable<library_info.Category> categories =
|
| - extractCsvOption(options, '--categories=')
|
| - .map(library_info.parseCategory)
|
| - .where((x) => x != null);
|
| - if (categories.isEmpty) {
|
| - return new Set.from([library_info.Category.client]);
|
| + static Set<String> getAllowedLibraryCategories(List<String> options) {
|
| + var result = extractCsvOption(options, '--categories=');
|
| + if (result.isEmpty) {
|
| + result = ['Client'];
|
| }
|
| - return new Set.from(categories);
|
| + result.add('Shared');
|
| + result.add('Internal');
|
| + return new Set<String>.from(result);
|
| }
|
|
|
| static bool hasOption(List<String> options, String option) {
|
| return options.indexOf(option) >= 0;
|
| }
|
|
|
| + // TODO(johnniwinther): Merge better with [translateDartUri] when
|
| + // [scanBuiltinLibrary] is removed.
|
| + String lookupLibraryPath(Uri uri, LibraryInfo info) {
|
| + if (info == null) return null;
|
| + if (!info.isDart2jsLibrary) return null;
|
| + if (!allowedLibraryCategories.contains(info.category)) {
|
| + registerDisallowedLibraryUse(uri);
|
| + return null;
|
| + }
|
| + String path = info.dart2jsPath;
|
| + if (path == null) {
|
| + path = info.path;
|
| + }
|
| + return "lib/$path";
|
| + }
|
| +
|
| String lookupPatchPath(String dartLibraryName) {
|
| - library_info.LibraryInfo info = lookupLibraryInfo(dartLibraryName);
|
| + LibraryInfo info = lookupLibraryInfo(dartLibraryName);
|
| if (info == null) return null;
|
| if (!info.isDart2jsLibrary) return null;
|
| String path = info.dart2jsPatchPath;
|
| @@ -305,68 +321,36 @@ class Compiler extends leg.Compiler {
|
| }
|
| }
|
|
|
| - /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative
|
| - /// to [libraryRoot] according to the information in [library_info.libraries].
|
| - ///
|
| - /// Returns null and emits an error if the library could not be found or
|
| - /// imported into [importingLibrary].
|
| - ///
|
| - /// If [importingLibrary] is a platform or patch library all dart2js libraries
|
| - /// can be resolved. Otherwise only libraries with categories in
|
| - /// [allowedLibraryCategories] can be resolved.
|
| Uri translateDartUri(elements.LibraryElement importingLibrary,
|
| Uri resolvedUri, Spannable spannable) {
|
| -
|
| - library_info.LibraryInfo libraryInfo = lookupLibraryInfo(resolvedUri.path);
|
| -
|
| - bool allowInternalLibraryAccess = false;
|
| - if (importingLibrary != null) {
|
| - if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) {
|
| - allowInternalLibraryAccess = true;
|
| - } else if (importingLibrary.canonicalUri.path.contains(
|
| - 'sdk/tests/compiler/dart2js_native')) {
|
| - allowInternalLibraryAccess = true;
|
| + LibraryInfo libraryInfo = lookupLibraryInfo(resolvedUri.path);
|
| + String path = lookupLibraryPath(resolvedUri, libraryInfo);
|
| + if (libraryInfo != null &&
|
| + libraryInfo.category == "Internal") {
|
| + bool allowInternalLibraryAccess = false;
|
| + if (importingLibrary != null) {
|
| + if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) {
|
| + allowInternalLibraryAccess = true;
|
| + } else if (importingLibrary.canonicalUri.path.contains(
|
| + 'sdk/tests/compiler/dart2js_native')) {
|
| + allowInternalLibraryAccess = true;
|
| + }
|
| }
|
| - }
|
| -
|
| - String computePath() {
|
| - if (libraryInfo == null) {
|
| - return null;
|
| - } else if (!libraryInfo.isDart2jsLibrary) {
|
| - return null;
|
| - } else {
|
| - if (libraryInfo.isInternal &&
|
| - !allowInternalLibraryAccess) {
|
| - if (importingLibrary != null) {
|
| - reporter.reportErrorMessage(
|
| - spannable,
|
| - MessageKind.INTERNAL_LIBRARY_FROM,
|
| - {'resolvedUri': resolvedUri,
|
| - 'importingUri': importingLibrary.canonicalUri});
|
| - } else {
|
| - reporter.reportErrorMessage(
|
| - spannable,
|
| - MessageKind.INTERNAL_LIBRARY,
|
| - {'resolvedUri': resolvedUri});
|
| - registerDisallowedLibraryUse(resolvedUri);
|
| - }
|
| - return null;
|
| - } else if (!allowInternalLibraryAccess &&
|
| - !allowedLibraryCategories.any(libraryInfo.categories.contains)) {
|
| - registerDisallowedLibraryUse(resolvedUri);
|
| - // TODO(sigurdm): Currently we allow the sdk libraries to import
|
| - // libraries from any category. We might want to revisit this.
|
| - return null;
|
| + if (!allowInternalLibraryAccess) {
|
| + if (importingLibrary != null) {
|
| + reporter.reportErrorMessage(
|
| + spannable,
|
| + MessageKind.INTERNAL_LIBRARY_FROM,
|
| + {'resolvedUri': resolvedUri,
|
| + 'importingUri': importingLibrary.canonicalUri});
|
| } else {
|
| - return (libraryInfo.dart2jsPath != null)
|
| - ? libraryInfo.dart2jsPath
|
| - : libraryInfo.path;
|
| + reporter.reportErrorMessage(
|
| + spannable,
|
| + MessageKind.INTERNAL_LIBRARY,
|
| + {'resolvedUri': resolvedUri});
|
| }
|
| }
|
| }
|
| -
|
| - String path = computePath();
|
| -
|
| if (path == null) {
|
| if (libraryInfo == null) {
|
| reporter.reportErrorMessage(
|
| @@ -383,14 +367,13 @@ class Compiler extends leg.Compiler {
|
| // value.
|
| return null;
|
| }
|
| -
|
| if (resolvedUri.path == 'html' ||
|
| resolvedUri.path == 'io') {
|
| // TODO(ahe): Get rid of mockableLibraryUsed when test.dart
|
| // supports this use case better.
|
| mockableLibraryUsed = true;
|
| }
|
| - return libraryRoot.resolve("lib/$path");
|
| + return libraryRoot.resolve(path);
|
| }
|
|
|
| Uri resolvePatchUri(String dartLibraryPath) {
|
| @@ -564,7 +547,7 @@ class Compiler extends leg.Compiler {
|
|
|
| fromEnvironment(String name) => environment[name];
|
|
|
| - library_info.LibraryInfo lookupLibraryInfo(String libraryName) {
|
| - return library_info.libraries[libraryName];
|
| + LibraryInfo lookupLibraryInfo(String libraryName) {
|
| + return library_info.LIBRARIES[libraryName];
|
| }
|
| }
|
|
|