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

Unified Diff: pkg/compiler/lib/src/apiimpl.dart

Issue 1975153002: Support (de)serialization from command-line (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 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 | « no previous file | pkg/compiler/lib/src/commandline_options.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/apiimpl.dart
diff --git a/pkg/compiler/lib/src/apiimpl.dart b/pkg/compiler/lib/src/apiimpl.dart
index e802bd449fd4fb5b5066cc1d2abbe8d68e421d76..631d29b3d22f1cdf7704182ec1c6153f681f0a81 100644
--- a/pkg/compiler/lib/src/apiimpl.dart
+++ b/pkg/compiler/lib/src/apiimpl.dart
@@ -26,6 +26,7 @@ import 'options.dart' show CompilerOptions;
import 'platform_configuration.dart' as platform_configuration;
import 'resolved_uri_translator.dart';
import 'script.dart';
+import 'serialization/system.dart';
/// Implements the [Compiler] using a [api.CompilerInput] for supplying the
/// sources.
@@ -112,17 +113,8 @@ class CompilerImpl extends Compiler {
// TODO(johnniwinther): Wrap the result from [provider] in a specialized
// [Future] to ensure that we never execute an asynchronous action without
// setting up the current element of the compiler.
- return new Future.sync(() => callUserProvider(resourceUri)).then((data) {
- SourceFile sourceFile;
- if (data is List<int>) {
- sourceFile = new Utf8BytesSourceFile(resourceUri, data);
- } else if (data is String) {
- sourceFile = new StringSourceFile.fromUri(resourceUri, data);
- } else {
- String message = "Expected a 'String' or a 'List<int>' from the input "
- "provider, but got: ${Error.safeToString(data)}.";
- reportReadError(message);
- }
+ return new Future.sync(() => callUserProvider(resourceUri))
+ .then((SourceFile sourceFile) {
// We use [readableUri] as the URI for the script since need to preserve
// the scheme in the script because [Script.uri] is used for resolving
// relative URIs mentioned in the script. See the comment on
@@ -182,10 +174,9 @@ class CompilerImpl extends Compiler {
// and we can't depend on 'dart:io' classes.
packages = new NonFilePackagesDirectoryPackages(options.packageRoot);
} else if (options.packageConfig != null) {
- return callUserProvider(options.packageConfig).then((configContents) {
- if (configContents is String) {
- configContents = UTF8.encode(configContents);
- }
+ return callUserProvider(options.packageConfig)
+ .then((SourceFile sourceFile) {
+ List<int> configContents = sourceFile.slowUtf8ZeroTerminatedBytes();
// The input provider may put a trailing 0 byte when it reads a source
// file, which confuses the package config parser.
if (configContents.length > 0 && configContents.last == 0) {
@@ -213,18 +204,27 @@ class CompilerImpl extends Compiler {
}
Future<Null> setupSdk() {
+ Future future = new Future.value(null);
+ if (options.resolutionInput != null) {
+ reporter.log('Reading serialized data from ${options.resolutionInput}');
+ future = callUserProvider(options.resolutionInput)
+ .then((SourceFile sourceFile) {
+ serialization.deserializeFromText(sourceFile.slowText());
+ });
+ }
if (resolvedUriTranslator.isNotSet) {
- return platform_configuration
- .load(options.platformConfigUri, provider)
- .then((Map<String, Uri> mapping) {
- resolvedUriTranslator.resolvedUriTranslator =
- new ResolvedUriTranslator(mapping, reporter);
+ future = future.then((_) {
+ return platform_configuration
+ .load(options.platformConfigUri, provider)
+ .then((Map<String, Uri> mapping) {
+ resolvedUriTranslator.resolvedUriTranslator =
+ new ResolvedUriTranslator(mapping, reporter);
+ });
});
- } else {
- // The incremental compiler sets up the sdk before run.
- // Therefore this will be called a second time.
- return new Future.value(null);
}
+ // The incremental compiler sets up the sdk before run.
+ // Therefore this will be called a second time.
+ return future;
}
Future<bool> run(Uri uri) {
@@ -316,9 +316,22 @@ class CompilerImpl extends Compiler {
}
}
- Future callUserProvider(Uri uri) {
+ Future<SourceFile> callUserProvider(Uri uri) {
try {
- return userProviderTask.measureIo(() => provider.readFromUri(uri));
+ return userProviderTask
+ .measureIo(() => provider.readFromUri(uri))
+ .then((data) {
+ SourceFile sourceFile;
+ if (data is List<int>) {
+ sourceFile = new Utf8BytesSourceFile(uri, data);
+ } else if (data is String) {
+ sourceFile = new StringSourceFile.fromUri(uri, data);
+ } else {
+ throw "Expected a 'String' or a 'List<int>' from the input "
+ "provider, but got: ${Error.safeToString(data)}.";
+ }
+ return sourceFile;
+ });
} catch (ex, s) {
reportCrashInUserCode('Uncaught exception in input provider', ex, s);
rethrow;
« no previous file with comments | « no previous file | pkg/compiler/lib/src/commandline_options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698