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

Unified Diff: pkg/front_end/lib/src/fasta/translate_uri.dart

Issue 2895983002: Read SDK and patches from a JSON file. (Closed)
Patch Set: Merged with 1333f97b9a0e3805f991578ef83b0ec4553ecf33 Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/target_implementation.dart ('k') | pkg/front_end/test/fasta/shaker_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/translate_uri.dart
diff --git a/pkg/front_end/lib/src/fasta/translate_uri.dart b/pkg/front_end/lib/src/fasta/translate_uri.dart
index f17d9af91bbfffe2991f88ba0ad450f6714a9cab..6c249a77239f69aa4782097213ae1e4208243038 100644
--- a/pkg/front_end/lib/src/fasta/translate_uri.dart
+++ b/pkg/front_end/lib/src/fasta/translate_uri.dart
@@ -6,7 +6,11 @@ library fasta.translate_uri;
import 'dart:async' show Future;
-import 'package:front_end/file_system.dart';
+import 'dart:convert' show JSON;
+
+import 'package:front_end/file_system.dart'
+ show FileSystem, FileSystemException;
+
import 'package:package_config/packages_file.dart' as packages_file show parse;
import 'errors.dart' show inputError;
@@ -15,7 +19,11 @@ class TranslateUri {
final Map<String, Uri> packages;
final Map<String, Uri> dartLibraries;
- TranslateUri(this.packages, this.dartLibraries);
+ // TODO(ahe): We probably want this to be `Map<String, Uri>`, that is, just
+ // one patch library (with parts).
+ final Map<String, List<Uri>> patches;
+
+ TranslateUri(this.packages, this.dartLibraries, this.patches);
Uri translate(Uri uri) {
if (uri.scheme == "dart") return translateDartUri(uri);
@@ -46,83 +54,57 @@ class TranslateUri {
return root.resolve(path);
}
+ /// Returns true if [uri] is private to the platform libraries (and thus not
+ /// accessible from user code).
+ bool isPlatformImplementation(Uri uri) {
+ if (uri.scheme != "dart") return false;
+ String path = uri.path;
+ return dartLibraries[path] == null || path.startsWith("_");
+ }
+
static Future<TranslateUri> parse(FileSystem fileSystem, Uri sdk,
- [Uri uri]) async {
- // This list below is generated with [bin/generate_dart_libraries.dart] and
- // additional entries for _builtin, _vmservice, profiler, and vmservice_io.
- //
- // TODO(ahe): This is only used with the option --compile-sdk, and
- // currently doesn't work outside the SDK source tree.
- Map<String, Uri> dartLibraries = <String, Uri>{};
- if (sdk != null) {
- dartLibraries = <String, Uri>{
- "_async_await_error_codes": sdk.resolve(
- "lib/_internal/js_runtime/lib/shared/async_await_error_codes.dart"),
- "_blink": sdk.resolve("lib/_blink/dartium/_blink_dartium.dart"),
- "_builtin": sdk.resolve("lib/_builtin/_builtin.dart"),
- "_chrome": sdk.resolve("lib/_chrome/dart2js/chrome_dart2js.dart"),
- "_foreign_helper":
- sdk.resolve("lib/_internal/js_runtime/lib/foreign_helper.dart"),
- "_interceptors":
- sdk.resolve("lib/_internal/js_runtime/lib/interceptors.dart"),
- "_internal": sdk.resolve("lib/internal/internal.dart"),
- "_isolate_helper":
- sdk.resolve("lib/_internal/js_runtime/lib/isolate_helper.dart"),
- "_js_embedded_names": sdk
- .resolve("lib/_internal/js_runtime/lib/shared/embedded_names.dart"),
- "_js_helper":
- sdk.resolve("lib/_internal/js_runtime/lib/js_helper.dart"),
- "_js_mirrors":
- sdk.resolve("lib/_internal/js_runtime/lib/js_mirrors.dart"),
- "_js_names": sdk.resolve("lib/_internal/js_runtime/lib/js_names.dart"),
- "_js_primitives":
- sdk.resolve("lib/_internal/js_runtime/lib/js_primitives.dart"),
- "_metadata": sdk.resolve("lib/html/html_common/metadata.dart"),
- "_native_typed_data":
- sdk.resolve("lib/_internal/js_runtime/lib/native_typed_data.dart"),
- "_vmservice": sdk.resolve("lib/vmservice/vmservice.dart"),
- "async": sdk.resolve("lib/async/async.dart"),
- "collection": sdk.resolve("lib/collection/collection.dart"),
- "convert": sdk.resolve("lib/convert/convert.dart"),
- "core": sdk.resolve("lib/core/core.dart"),
- "developer": sdk.resolve("lib/developer/developer.dart"),
- "html": sdk.resolve("lib/html/dart2js/html_dart2js.dart"),
- "html_common":
- sdk.resolve("lib/html/html_common/html_common_dart2js.dart"),
- "indexed_db":
- sdk.resolve("lib/indexed_db/dart2js/indexed_db_dart2js.dart"),
- "io": sdk.resolve("lib/io/io.dart"),
- "isolate": sdk.resolve("lib/isolate/isolate.dart"),
- "js": sdk.resolve("lib/js/dart2js/js_dart2js.dart"),
- "js_util": sdk.resolve("lib/js_util/dart2js/js_util_dart2js.dart"),
- "math": sdk.resolve("lib/math/math.dart"),
- "mirrors": sdk.resolve("lib/mirrors/mirrors.dart"),
- "nativewrappers": sdk.resolve("lib/html/dartium/nativewrappers.dart"),
- "profiler": sdk.resolve("lib/profiler/profiler.dart"),
- "svg": sdk.resolve("lib/svg/dart2js/svg_dart2js.dart"),
- "typed_data": sdk.resolve("lib/typed_data/typed_data.dart"),
- "vmservice_io": sdk.resolve("lib/vmservice_io/vmservice_io.dart"),
- "web_audio":
- sdk.resolve("lib/web_audio/dart2js/web_audio_dart2js.dart"),
- "web_gl": sdk.resolve("lib/web_gl/dart2js/web_gl_dart2js.dart"),
- "web_sql": sdk.resolve("lib/web_sql/dart2js/web_sql_dart2js.dart"),
- };
- }
- uri ??= Uri.base.resolve(".packages");
+ {Uri packages}) async {
+ Uri librariesJson = sdk?.resolve("lib/libraries.json");
+
+ // TODO(ahe): Provide a value for this file.
+ Uri patches = null;
+
+ packages ??= Uri.base.resolve(".packages");
List<int> bytes;
try {
- bytes = await fileSystem.entityForUri(uri).readAsBytes();
+ bytes = await fileSystem.entityForUri(packages).readAsBytes();
} on FileSystemException catch (e) {
- inputError(uri, -1, e.message);
+ inputError(packages, -1, e.message);
}
- Map<String, Uri> packages = const <String, Uri>{};
+ Map<String, Uri> parsedPackages;
try {
- packages = packages_file.parse(bytes, uri);
+ parsedPackages = packages_file.parse(bytes, packages);
} on FormatException catch (e) {
- return inputError(uri, e.offset, e.message);
+ return inputError(packages, e.offset, e.message);
}
- return new TranslateUri(packages, dartLibraries);
+ return new TranslateUri(
+ parsedPackages,
+ await computeLibraries(fileSystem, librariesJson),
+ await computePatches(fileSystem, patches));
}
}
+
+Future<Map<String, Uri>> computeLibraries(
+ FileSystem fileSystem, Uri uri) async {
+ if (uri == null) return const <String, Uri>{};
+ Map<String, String> libraries = JSON
+ .decode(await fileSystem.entityForUri(uri).readAsString())["libraries"];
+ Map<String, Uri> result = <String, Uri>{};
+ libraries.forEach((String name, String path) {
+ result[name] = uri.resolve(path);
+ });
+ return result;
+}
+
+Future<Map<String, List<Uri>>> computePatches(
+ FileSystem fileSystem, Uri uri) async {
+ // TODO(ahe): Read patch information.
+ return const <String, List<Uri>>{};
+}
« no previous file with comments | « pkg/front_end/lib/src/fasta/target_implementation.dart ('k') | pkg/front_end/test/fasta/shaker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698