Incremental compiler: Include right libraries when entry point is translated
Without this CL the incremental compiler could potentially return too
few libraries (or possibly 0 libraries):
If the entry point is translated to a package-URI and there is no main,
the entry-library when doing the transitive closure cannot be found and the
output will be no libraries.
If the entry point is translated to a package-URI and there is a main,
the entry-library when doing the transitive clusire is only found because
of the otherwise unneeded `mainMethod` parametesr.
This CL adds tests and fixes the problem.
Change-Id: Icea72eb892cb0d16f0d86e3729e29ce026fa7073
Reviewed-on: https://dart-review.googlesource.com/c/92430
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Peter von der Ahé <ahe@google.com>
diff --git a/pkg/front_end/lib/src/fasta/incremental_compiler.dart b/pkg/front_end/lib/src/fasta/incremental_compiler.dart
index 5192935..d5dda52 100644
--- a/pkg/front_end/lib/src/fasta/incremental_compiler.dart
+++ b/pkg/front_end/lib/src/fasta/incremental_compiler.dart
@@ -261,7 +261,7 @@
}
}
- userCode.setEntryPoints(<Uri>[entryPoint]);
+ entryPoint = userCode.setEntryPoints(<Uri>[entryPoint]).single;
await userCode.buildOutlines();
// This is not the full component. It is the component including all
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
index 6e0d8ae..104f403 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
@@ -155,8 +155,10 @@
uriToSource[uri] = new Source(lineStarts, sourceCode);
}
- void setEntryPoints(List<Uri> entryPoints) {
+ /// Return list of same size as input with possibly translated uris.
+ List<Uri> setEntryPoints(List<Uri> entryPoints) {
Map<String, Uri> packagesMap;
+ List<Uri> result = new List<Uri>();
for (Uri entryPoint in entryPoints) {
String scheme = entryPoint.scheme;
Uri fileUri;
@@ -187,8 +189,10 @@
}
}
}
+ result.add(entryPoint);
loader.read(entryPoint, -1, accessor: loader.first, fileUri: fileUri);
}
+ return result;
}
@override
diff --git a/pkg/front_end/test/incremental_load_from_dill_test.dart b/pkg/front_end/test/incremental_load_from_dill_test.dart
index 9862738..682f362 100644
--- a/pkg/front_end/test/incremental_load_from_dill_test.dart
+++ b/pkg/front_end/test/incremental_load_from_dill_test.dart
@@ -313,7 +313,7 @@
}
}
List<Library> entryLib = component.libraries
- .where((Library lib) => lib.importUri == entry)
+ .where((Library lib) => lib.importUri == entry || lib.fileUri == entry)
.toList();
if (entryLib.length != 1) {
throw "Expected the entry to become a library. Got ${entryLib.length} "
diff --git a/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_main.yaml b/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_main.yaml
new file mode 100644
index 0000000..5bd270e
--- /dev/null
+++ b/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_main.yaml
@@ -0,0 +1,20 @@
+# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE.md file.
+
+# When the entry is not given as a package-url, but is intepreted as one
+# (Interpreting this as package URI, 'package:untitled/main.dart'.) the library
+# should still be included in the output.
+
+type: newworld
+strong: true
+worlds:
+ - entry: main.dart
+ sources:
+ main.dart: |
+ main() {
+ }
+ .packages: untitled:/
+ expectedLibraryCount: 1
+ errors: false
+ warnings: true
diff --git a/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_main_with_errors.yaml b/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_main_with_errors.yaml
new file mode 100644
index 0000000..2360641
--- /dev/null
+++ b/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_main_with_errors.yaml
@@ -0,0 +1,21 @@
+# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE.md file.
+
+# When the entry is not given as a package-url, but is intepreted as one
+# (Interpreting this as package URI, 'package:untitled/main.dart'.) the library
+# should still be included in the output - even if there's errors in main.
+
+type: newworld
+strong: true
+worlds:
+ - entry: main.dart
+ sources:
+ main.dart: |
+ main() {
+ asdf;
+ }
+ .packages: untitled:/
+ expectedLibraryCount: 1
+ errors: true
+ warnings: true
diff --git a/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_no_main.yaml b/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_no_main.yaml
new file mode 100644
index 0000000..02a57de
--- /dev/null
+++ b/pkg/front_end/testcases/incremental_initialize_from_dill/entry_not_package_url_no_main.yaml
@@ -0,0 +1,19 @@
+# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE.md file.
+
+# When the entry is not given as a package-url, but is intepreted as one
+# (Interpreting this as package URI, 'package:untitled/main.dart'.) the library
+# should still be included in the output - even if there's no main.
+
+type: newworld
+strong: true
+worlds:
+ - entry: main.dart
+ sources:
+ main.dart: |
+ notMain() {}
+ .packages: untitled:/
+ expectedLibraryCount: 1
+ errors: false
+ warnings: true