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

Unified Diff: pkg/front_end/lib/src/fasta/testing/kernel_chain.dart

Issue 2976543002: Reapply "Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service."" (Closed)
Patch Set: fix Created 3 years, 5 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/src/fasta/testing/kernel_chain.dart
diff --git a/pkg/front_end/lib/src/fasta/testing/kernel_chain.dart b/pkg/front_end/lib/src/fasta/testing/kernel_chain.dart
index 04ae0cfa6fa7f3eca9eaa6305050a6e8586666ed..bdb0ff71bacb40946129d9ee6bad1e44288a72db 100644
--- a/pkg/front_end/lib/src/fasta/testing/kernel_chain.dart
+++ b/pkg/front_end/lib/src/fasta/testing/kernel_chain.dart
@@ -28,10 +28,14 @@ import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
import 'package:testing/testing.dart'
- show ChainContext, Result, StdioProcess, Step;
+ show ChainContext, Result, StdioProcess, Step, TestDescription;
import 'package:kernel/ast.dart' show Program;
+import 'package:front_end/front_end.dart';
+
+import 'patched_sdk_location.dart' show computePatchedSdk;
+
class Print extends Step<Program, Program, ChainContext> {
const Print();
@@ -170,6 +174,40 @@ class Copy extends Step<Program, Program, ChainContext> {
}
}
+/// A `package:testing` step that runs the `package:front_end` compiler to
+/// generate a kernel program for an individual file.
+///
+/// Most options are hard-coded, but if necessary they could be moved to the
+/// [CompileContext] object in the future.
+class Compile extends Step<TestDescription, Program, CompileContext> {
+ const Compile();
+
+ String get name => "fasta compilation";
+
+ Future<Result<Program>> run(
+ TestDescription description, CompileContext context) async {
+ Result<Program> result;
+ reportError(CompilationError error) {
+ result ??= fail(null, error.message);
+ }
+
+ Uri sdk = await computePatchedSdk();
+ Program p = await kernelForProgram(
+ description.uri,
+ new CompilerOptions()
+ ..sdkRoot = sdk
+ ..packagesFileUri = Uri.base.resolve('.packages')
+ ..strongMode = context.strongMode
+ ..linkedDependencies = [sdk.resolve('platform.dill')]
+ ..onError = reportError);
+ return result ??= pass(p);
+ }
+}
+
+abstract class CompileContext implements ChainContext {
+ bool get strongMode;
+}
+
class BytesCollector implements Sink<List<int>> {
final List<List<int>> lists = <List<int>>[];

Powered by Google App Engine
This is Rietveld 408576698