Load extraRequiredLibraries from the target passed in the options
This makes the behavior match what fasta does.
Long term I agree we don't want these implicit imports. I sent an email to
brainstorm a solution for that.
This change will address one of the issues reported in http://dartbug.com/30491
R=scheglov@google.com
Review-Url: https://codereview.chromium.org/3007503002 .
diff --git a/pkg/front_end/lib/src/incremental/file_state.dart b/pkg/front_end/lib/src/incremental/file_state.dart
index d060d02..cb0a0d6 100644
--- a/pkg/front_end/lib/src/incremental/file_state.dart
+++ b/pkg/front_end/lib/src/incremental/file_state.dart
@@ -15,7 +15,7 @@
import 'package:front_end/src/byte_store/byte_store.dart';
import 'package:front_end/src/incremental/format.dart';
import 'package:front_end/src/incremental/unlinked_unit.dart';
-import 'package:kernel/target/vm.dart';
+import 'package:kernel/target/targets.dart';
/// This function is called for each newly discovered file, and the returned
/// [Future] is awaited before reading the file content.
@@ -182,7 +182,7 @@
_importedLibraries.add(file);
}
}
- await _addVmTargetImportsForCore();
+ await _addTargetExtraRequiredLibraries();
for (var export_ in unlinkedUnit.exports) {
FileState file = await _getFileForRelativeUri(export_.uri);
if (file != null) {
@@ -228,13 +228,14 @@
return uri.toString();
}
- /// Fasta unconditionally loads all VM libraries. In order to be able to
- /// serve them using the file system view, pretend that all of them were
- /// imported into `dart:core`.
- /// TODO(scheglov) Ask VM people whether all these libraries are required.
- Future<Null> _addVmTargetImportsForCore() async {
+ /// Fasta unconditionally loads extra libraries based on the target. In order
+ /// to be able to serve them using the file system view, pretend that all of
+ /// them were imported into `dart:core`.
+ /// TODO(scheglov,sigmund): remove this implicit import, instead make fasta
+ /// and IKG aware of extra code that needs to be loaded.
+ Future<Null> _addTargetExtraRequiredLibraries() async {
if (uri.toString() != 'dart:core') return;
- for (String uri in new VmTarget(null).extraRequiredLibraries) {
+ for (String uri in _fsState.target.extraRequiredLibraries) {
FileState file = await _getFileForRelativeUri(uri);
// TODO(scheglov) add error handling
if (file != null) {
@@ -267,6 +268,7 @@
class FileSystemState {
final ByteStore _byteStore;
final FileSystem fileSystem;
+ final Target target;
final UriTranslator uriTranslator;
final List<int> _salt;
final NewFileFn _newFileFn;
@@ -285,8 +287,8 @@
/// We do this when we use SDK outline instead of compiling SDK sources.
final Set<Uri> skipSdkLibraries = new Set<Uri>();
- FileSystemState(this._byteStore, this.fileSystem, this.uriTranslator,
- this._salt, this._newFileFn);
+ FileSystemState(this._byteStore, this.fileSystem, this.target,
+ this.uriTranslator, this._salt, this._newFileFn);
/// Return the [FileSystem] that is backed by this [FileSystemState]. The
/// files in this [FileSystem] always have the same content as the
diff --git a/pkg/front_end/lib/src/incremental/kernel_driver.dart b/pkg/front_end/lib/src/incremental/kernel_driver.dart
index be9b602..1ca0f2c 100644
--- a/pkg/front_end/lib/src/incremental/kernel_driver.dart
+++ b/pkg/front_end/lib/src/incremental/kernel_driver.dart
@@ -105,8 +105,8 @@
return new Future.value();
}
- _fsState = new FileSystemState(
- _byteStore, _fileSystem, _uriTranslator, _salt, onFileAdded);
+ _fsState = new FileSystemState(_byteStore, _fileSystem, _options.target,
+ _uriTranslator, _salt, onFileAdded);
}
/// Return the [FileSystemState] that contains the current file state.
diff --git a/pkg/front_end/test/src/incremental/file_state_test.dart b/pkg/front_end/test/src/incremental/file_state_test.dart
index 9395651..8a988cb 100644
--- a/pkg/front_end/test/src/incremental/file_state_test.dart
+++ b/pkg/front_end/test/src/incremental/file_state_test.dart
@@ -11,6 +11,7 @@
import 'package:package_config/packages.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
+import 'package:kernel/target/targets.dart';
import 'mock_sdk.dart';
@@ -34,8 +35,8 @@
new UriTranslatorImpl(createSdkFiles(fileSystem), Packages.noPackages);
_coreUri = Uri.parse('dart:core');
expect(_coreUri, isNotNull);
- fsState = new FileSystemState(byteStore, fileSystem, uriTranslator, <int>[],
- (uri) {
+ fsState = new FileSystemState(byteStore, fileSystem,
+ new NoneTarget(new TargetFlags()), uriTranslator, <int>[], (uri) {
_newFileUris.add(uri);
return new Future.value();
});