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

Unified Diff: pkg/front_end/lib/kernel_generator.dart

Issue 2894283002: Reapply CL: first step for modular support in fasta (Closed)
Patch Set: new changes since first CL 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
Index: pkg/front_end/lib/kernel_generator.dart
diff --git a/pkg/front_end/lib/kernel_generator.dart b/pkg/front_end/lib/kernel_generator.dart
index 6292ae300b8289681e46b96c4dc95afcde3f2ffd..0f5a4d888365aa8dacd1b1ec7f60d4d6b4945491 100644
--- a/pkg/front_end/lib/kernel_generator.dart
+++ b/pkg/front_end/lib/kernel_generator.dart
@@ -8,7 +8,7 @@ library front_end.kernel_generator;
import 'compiler_options.dart';
import 'dart:async' show Future;
import 'dart:async';
-import 'package:front_end/physical_file_system.dart';
+import 'package:front_end/src/base/processed_options.dart';
import 'src/fasta/dill/dill_target.dart' show DillTarget;
import 'src/fasta/errors.dart' show InputError;
import 'src/fasta/kernel/kernel_target.dart' show KernelTarget;
@@ -29,15 +29,13 @@ import 'src/simple_error.dart';
/// If `compileSdk` in [options] is true, the generated program will include
/// code for the SDK.
///
-/// If summaries are provided in [options], they may be used to speed up
-/// analysis. If in addition `compileSdk` is false, this will speed up
-/// compilation, as no source of the sdk will be generated. Note however, that
-/// summaries for application code can also speed up analysis, but they will not
-/// take the place of Dart source code (since the Dart source code is still
-/// needed to access the contents of method bodies).
+/// If summaries are provided in [options], they will be used to speed up
+/// the process. If in addition `compileSdk` is false, then the resulting
+/// program will not contain the sdk contents. This is useful when building apps
+/// for platforms that already embed the sdk (e.g. the VM), so there is no need
+/// to spend time and space rebuilding it.
Future<Program> kernelForProgram(Uri source, CompilerOptions options) async {
var fs = options.fileSystem;
-
report(String msg) {
options.onError(new SimpleError(msg));
return null;
@@ -47,16 +45,19 @@ Future<Program> kernelForProgram(Uri source, CompilerOptions options) async {
return report("Entry-point file not found: $source");
}
- if (!await validateOptions(options)) return null;
+ var pOptions = new ProcessedOptions(options);
+
+ if (!await pOptions.validateOptions()) return null;
try {
- TranslateUri uriTranslator = await TranslateUri.parse(
- PhysicalFileSystem.instance, null, options.packagesFileUri);
+ TranslateUri uriTranslator = await pOptions.getUriTranslator();
var dillTarget =
new DillTarget(new Ticker(isVerbose: false), uriTranslator);
- var summary = options.sdkSummary;
- if (summary != null) dillTarget.read(summary);
+ var summary = await pOptions.sdkSummaryProgram;
+ if (summary != null) {
+ dillTarget.loader.appendLibraries(summary);
+ }
var kernelTarget = new KernelTarget(
options.fileSystem, dillTarget, uriTranslator, options.strongMode);
@@ -64,7 +65,7 @@ Future<Program> kernelForProgram(Uri source, CompilerOptions options) async {
await dillTarget.buildOutlines();
await kernelTarget.buildOutlines();
- Program program = await kernelTarget.buildProgram();
+ Program program = await kernelTarget.buildProgram(trimDependencies: true);
if (kernelTarget.errors.isNotEmpty) {
kernelTarget.errors.forEach(report);
@@ -121,5 +122,63 @@ Future<Program> kernelForProgram(Uri source, CompilerOptions options) async {
/// obtained from?
Future<Program> kernelForBuildUnit(
List<Uri> sources, CompilerOptions options) async {
- throw new UnimplementedError("kernel for build-unit is not implemented");
+ var fs = options.fileSystem;
+ report(String msg) {
+ options.onError(new SimpleError(msg));
+ return null;
+ }
+
+ if (!options.chaseDependencies) {
+ // TODO(sigmund): add support, most likely we can do so by adding a wrapper
+ // on top of filesystem that restricts reads to a set of known files.
+ report("hermetic mode (chaseDependencies = false) is not implemented");
+ return null;
+ }
+
+ for (var source in sources) {
+ if (!await fs.entityForUri(source).exists()) {
+ return report("Entry-point file not found: $source");
+ }
+ }
+
+ var pOptions = new ProcessedOptions(options);
+
+ if (!await pOptions.validateOptions()) return null;
+
+ try {
+ TranslateUri uriTranslator = await pOptions.getUriTranslator();
+
+ var dillTarget =
+ new DillTarget(new Ticker(isVerbose: false), uriTranslator);
+ var summary = await pOptions.sdkSummaryProgram;
+ if (summary != null) {
+ dillTarget.loader.appendLibraries(summary);
+ }
+
+ // TODO(sigmund): this is likely not going to work if done naively: if
+ // summaries contain external references we need to ensure they are loaded
+ // in a specific order.
+ for (var inputSummary in await pOptions.inputSummariesPrograms) {
+ dillTarget.loader.appendLibraries(inputSummary);
+ }
+
+ await dillTarget.buildOutlines();
+
+ var kernelTarget = new KernelTarget(
+ options.fileSystem, dillTarget, uriTranslator, options.strongMode);
+ sources.forEach(kernelTarget.read);
+ await kernelTarget.buildOutlines();
+
+ Program program = await kernelTarget.buildProgram(trimDependencies: true);
+
+ if (kernelTarget.errors.isNotEmpty) {
+ kernelTarget.errors.forEach(report);
+ return null;
+ }
+
+ return program;
+ } on InputError catch (e) {
+ options.onError(new SimpleError(e.format()));
+ return null;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698