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 ce9eee88a23557ccf57f2018013505886939a734..67bd3c17b3f4446f0a4d3559acd0599153c71815 100644 |
--- a/pkg/front_end/lib/kernel_generator.dart |
+++ b/pkg/front_end/lib/kernel_generator.dart |
@@ -9,6 +9,9 @@ import 'compilation_error.dart'; |
import 'compiler_options.dart'; |
import 'dart:async'; |
+import 'package:analyzer/src/generated/source.dart' show SourceKind; |
+import 'package:analyzer/src/summary/package_bundle_reader.dart' |
+ show InSummarySource; |
// TODO(sigmund): move loader logic under front_end/lib/src/kernel/ |
import 'package:kernel/analyzer/loader.dart'; |
import 'package:kernel/kernel.dart'; |
@@ -30,7 +33,8 @@ import 'package:source_span/source_span.dart' show SourceSpan; |
/// TODO(paulberry): will the VM have a pickled version of the SDK inside it? If |
/// so, then maybe this method should not convert SDK libraries to kernel. |
Future<Program> kernelForProgram(Uri source, CompilerOptions options) async { |
- var loader = await _createLoader(options); |
+ var loader = await _createLoader(options, entry: source); |
+ // TODO(sigmund): consider adding support for sdk summaries here as well. |
Program program = loader.loadProgram(source); |
_reportErrors(loader.errors, options.onError); |
return program; |
@@ -63,20 +67,48 @@ Future<Program> kernelForProgram(Uri source, CompilerOptions options) async { |
/// caller to match up referenced elements to the summary files they were |
/// obtained from? |
Future<Program> kernelForBuildUnit( |
- List<Uri> sources, CompilerOptions options) async { |
+ List<Uri> sources, CompilerOptions options) async { |
var repository = new Repository(); |
- var loader = await _createLoader(options, repository: repository); |
- // TODO(sigmund): add special handling for part files. |
- sources.forEach(loader.loadLibrary); |
+ var loader = await _createLoader(options, |
+ repository: repository, entry: sources.first); |
Paul Berry
2016/12/09 13:41:40
It seems weird to treat the first source any diffe
Siggi Cherem (dart-lang)
2016/12/09 16:58:21
Good point, will do once we decide on the other as
Siggi Cherem (dart-lang)
2016/12/09 20:46:40
Done.
|
+ var context = loader.context; |
+ |
+ // Process every library in the build unit. |
+ for (var uri in sources) { |
+ var source = context.sourceFactory.forUri2(uri); |
+ // We ignore part files, those are handled by their enclosing library. |
+ if (context.computeKindOf(source) == SourceKind.PART) continue; |
+ loader.loadLibrary(uri); |
+ } |
+ |
+ // Process any library that has been referenced and that was not loaded from a |
+ // summary file. |
Paul Berry
2016/12/09 13:41:40
This is actually undesirable behavior IMHO. It co
Siggi Cherem (dart-lang)
2016/12/09 16:58:21
Let's chat more about this.
I initially was kin t
Siggi Cherem (dart-lang)
2016/12/09 20:46:40
Updated the code based on an offline discussion. H
|
+ for (int i = 0; i < repository.libraries.length; ++i) { |
Paul Berry
2016/12/09 13:41:40
Nit: since `i` is not used, this would be clearer
asgerf
2016/12/09 13:56:53
I think the number of libraries will grow during i
Siggi Cherem (dart-lang)
2016/12/09 16:58:21
Asger is correct - the list is growing as more lib
Siggi Cherem (dart-lang)
2016/12/09 20:46:40
Done, added some documentation.
|
+ var lib = repository.libraries[i]; |
+ var source = context.sourceFactory.forUri2(lib.importUri); |
+ if (source is InSummarySource) continue; |
+ // Depending on the context we can allow or report an error when a library |
+ // is loaded here. For command-line tools we want to allow it to |
+ // make it easy to define build units in terms of a few entry point files. |
+ // For a closed build system like bazel, we can report an error. |
+ // TODO(sigmund): expose an option to indicate that this should be an error. |
+ loader.ensureLibraryIsLoaded(lib); |
+ } |
+ |
Program program = new Program(repository.libraries); |
_reportErrors(loader.errors, options.onError); |
return program; |
} |
+/// Create a [DartLoader] using the provided [options]. |
+/// |
+/// If [options] contain no configuration to resolve `.packages`, the [entry] |
+/// file will be used to search for a `.packages` file. |
Future<DartLoader> _createLoader(CompilerOptions options, |
- {Repository repository}) async { |
+ {Repository repository, Uri entry}) async { |
var kernelOptions = _convertOptions(options); |
- var packages = await createPackages(options.packagesFilePath); |
+ var packages = await createPackages(options.packagesFilePath, |
+ discoveryPath: entry?.path); |
return new DartLoader( |
repository ?? new Repository(), kernelOptions, packages); |
} |
@@ -84,6 +116,7 @@ Future<DartLoader> _createLoader(CompilerOptions options, |
DartOptions _convertOptions(CompilerOptions options) { |
return new DartOptions( |
sdk: options.sdkPath, |
+ sdkSummary: options.sdkSummary, |
packagePath: options.packagesFilePath, |
declaredVariables: options.declaredVariables); |
} |