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

Side by Side Diff: pkg/kernel/test/reify/suite.dart

Issue 2981813002: Move `reify` to use fasta instead of dartk (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library test.kernel.reify.suite; 5 library test.kernel.reify.suite;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show Directory, File, Platform; 9 import 'dart:io' show Platform, File;
10
11 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
12
13 import 'package:analyzer/src/kernel/loader.dart'
14 show DartLoader, DartOptions, createDartSdk;
15
16 import 'package:kernel/class_hierarchy.dart' show ClosedWorldClassHierarchy;
17 10
18 import 'package:kernel/core_types.dart' show CoreTypes; 11 import 'package:kernel/core_types.dart' show CoreTypes;
19 12
20 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; 13 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
21 14
22 import 'package:kernel/target/vmcc.dart' show VmClosureConvertedTarget; 15 import 'package:kernel/target/vmcc.dart' show VmClosureConvertedTarget;
23 16
24 import 'kernel_chain.dart' 17 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'
25 show MatchExpectation, Print, ReadDill, SanityCheck, WriteDill; 18 show computeDartVm, computePatchedSdk;
19 import 'package:front_end/src/fasta/testing/kernel_chain.dart'
20 show
21 Compile,
22 CompileContext,
23 MatchExpectation,
24 Print,
25 ReadDill,
26 Verify,
27 WriteDill;
26 28
27 import 'package:testing/testing.dart' 29 import 'package:testing/testing.dart'
28 show 30 show Chain, ChainContext, Result, StdioProcess, Step, runMe;
29 Chain,
30 ChainContext,
31 Result,
32 StdioProcess,
33 Step,
34 TestDescription,
35 runMe;
36 31
37 import 'package:kernel/ast.dart' show Program; 32 import 'package:kernel/ast.dart' show Program;
38 33
39 import 'package:kernel/transformations/generic_types_reification.dart' 34 import 'package:kernel/transformations/generic_types_reification.dart'
40 as generic_types_reification; 35 as generic_types_reification;
41 36
42 import 'package:package_config/discovery.dart' show loadPackagesFile; 37 class TestContext extends ChainContext implements CompileContext {
38 final Uri vm;
39 final Uri platformUri;
40 final Uri sdk;
43 41
44 class TestContext extends ChainContext { 42 @override
45 final Uri vm; 43 final Target target = new NotReifiedTarget(new TargetFlags(
44 strongMode: true,
45 kernelRuntime: Platform.script.resolve("../../runtime/")));
46 46
47 final Uri packages; 47 // Strong mode is required to keep the type arguments in invocations of
48 48 // generic methods.
49 final DartOptions options; 49 @override
50 50 bool get strongMode => true;
51 final DartSdk dartSdk;
52 51
53 final List<Step> steps; 52 final List<Step> steps;
54 53
55 TestContext(String sdk, this.vm, Uri packages, bool strongMode, this.dartSdk, 54 TestContext(this.vm, this.platformUri, this.sdk, bool updateExpectations)
56 bool updateExpectations) 55 : steps = <Step>[
57 : packages = packages, 56 const Compile(),
58 options = new DartOptions(
59 strongMode: strongMode,
60 sdk: sdk,
61 packagePath: packages.toFilePath()),
62 steps = <Step>[
63 const NotReifiedKernel(),
64 const Print(), 57 const Print(),
65 const SanityCheck(), 58 const Verify(true),
66 const GenericTypesReification(), 59 const GenericTypesReification(),
67 const Print(), 60 const Print(),
68 const SanityCheck(), 61 const Verify(true),
69 new MatchExpectation(".expect", 62 new MatchExpectation(".expect",
70 updateExpectations: updateExpectations), 63 updateExpectations: updateExpectations),
71 const WriteDill(), 64 const WriteDill(),
72 const ReadDill(), 65 const ReadDill(),
73 const Run(), 66 const Run(),
74 ]; 67 ];
75
76 Future<DartLoader> createLoader() async {
77 return new DartLoader(
78 new Program(), options, await loadPackagesFile(packages),
79 dartSdk: dartSdk);
80 }
81 } 68 }
82 69
83 enum Environment { 70 enum Environment {
84 directory, 71 directory,
85 file, 72 file,
86 } 73 }
87 74
88 Future<String> getEnvironmentVariable(
89 String name, Environment kind, String undefined, notFound(String n)) async {
90 String result = Platform.environment[name];
91 if (result == null) {
92 throw undefined;
93 }
94 switch (kind) {
95 case Environment.directory:
96 if (!await new Directory(result).exists()) throw notFound(result);
97 break;
98
99 case Environment.file:
100 if (!await new File(result).exists()) throw notFound(result);
101 break;
102 }
103 return result;
104 }
105
106 Future<bool> fileExists(Uri base, String path) async {
107 return await new File.fromUri(base.resolve(path)).exists();
108 }
109
110 Future<TestContext> createContext( 75 Future<TestContext> createContext(
111 Chain suite, Map<String, String> environment) async { 76 Chain suite, Map<String, String> environment) async {
112 const String suggestion = """Try building the patched SDK by running 77 Uri sdk = await computePatchedSdk();
113 'tools/build.py patched_sdk'"""; 78 Uri vm = computeDartVm(sdk);
114 79 Uri platform = sdk.resolve('platform.dill');
115 // TODO(karlklose): The path is different on MacOS. 80 bool updateExpectations = environment["updateExpectations"] == "true";
116 String sdk = "out/DebugX64/patched_sdk/"; 81 return new TestContext(vm, platform, sdk, updateExpectations);
117 Uri sdkUri = Uri.base.resolve(sdk);
118 const String asyncDart = "lib/async/async.dart";
119 if (!await fileExists(sdkUri, asyncDart)) {
120 throw "Couldn't find the patched SDK. $suggestion";
121 }
122 const String asyncSources = "lib/async/async_sources.gypi";
123 if (await fileExists(sdkUri, asyncSources)) {
124 throw "Found '$asyncSources' in '$sdk', so it isn't a patched SDK. "
125 "$suggestion";
126 }
127
128 // TODO(karlklose): select the VM based on the mode.
129 Uri vm = Uri.base.resolve("out/ReleaseX64/dart");
130
131 Uri packages = Uri.base.resolve(".packages");
132 // Strong mode is required to keep the type arguments in invocations of
133 // generic methods.
134 bool strongMode = true;
135 bool updateExpectations = const String.fromEnvironment("updateExpectations",
136 defaultValue: "false") ==
137 "true";
138 return new TestContext(sdk, vm, packages, strongMode,
139 createDartSdk(sdk, strongMode: strongMode), updateExpectations);
140 } 82 }
141 83
142 // [NotReifiedTarget] is intended to work as the [Target] class that 84 // [NotReifiedTarget] is intended to work as the [Target] class that
143 // [VmGenericTypesReifiedTarget] inherits from, but with some transformations 85 // [VmGenericTypesReifiedTarget] inherits from, but with some transformations
144 // disabled. Those include tree shaking and generic types information erasure 86 // disabled. Those include tree shaking and generic types information erasure
145 // passes. 87 // passes.
146 // [NotReifiedTarget] also adds the necessary runtime libraries. 88 // [NotReifiedTarget] also adds the necessary runtime libraries.
147 class NotReifiedTarget extends VmClosureConvertedTarget { 89 class NotReifiedTarget extends VmClosureConvertedTarget {
148 NotReifiedTarget(TargetFlags flags) : super(flags); 90 NotReifiedTarget(TargetFlags flags) : super(flags);
149 91
(...skipping 15 matching lines...) Expand all
165 107
166 // Adds the necessary runtime libraries. 108 // Adds the necessary runtime libraries.
167 @override 109 @override
168 List<String> get extraRequiredLibraries { 110 List<String> get extraRequiredLibraries {
169 Target reifyTarget = getTarget("vmreify", this.flags); 111 Target reifyTarget = getTarget("vmreify", this.flags);
170 var x = reifyTarget.extraRequiredLibraries; 112 var x = reifyTarget.extraRequiredLibraries;
171 return x; 113 return x;
172 } 114 }
173 } 115 }
174 116
175 class NotReifiedKernel extends Step<TestDescription, Program, TestContext> {
176 const NotReifiedKernel();
177
178 String get name => "kernel";
179
180 Future<Result<Program>> run(
181 TestDescription description, TestContext testContext) async {
182 try {
183 DartLoader loader = await testContext.createLoader();
184
185 // Strong mode is required to keep the type arguments in invocations of
186 // generic methods.
187 Target target = new NotReifiedTarget(new TargetFlags(
188 strongMode: true,
189 kernelRuntime: Platform.script.resolve("../../runtime/")));
190
191 String path = description.file.path;
192 Uri uri = Uri.base.resolve(path);
193 loader.loadProgram(uri, target: target);
194 var program = loader.program;
195 for (var error in loader.errors) {
196 return fail(program, "$error");
197 }
198 var coreTypes = new CoreTypes(program);
199 var hierarchy = new ClosedWorldClassHierarchy(program);
200 target
201 ..performModularTransformationsOnProgram(coreTypes, hierarchy, program)
202 ..performGlobalTransformations(coreTypes, program);
203 return pass(program);
204 } catch (e, s) {
205 return crash(e, s);
206 }
207 }
208 }
209
210 class GenericTypesReification extends Step<Program, Program, TestContext> { 117 class GenericTypesReification extends Step<Program, Program, TestContext> {
211 const GenericTypesReification(); 118 const GenericTypesReification();
212 119
213 String get name => "generic types reification"; 120 String get name => "generic types reification";
214 121
215 Future<Result<Program>> run(Program program, TestContext testContext) async { 122 Future<Result<Program>> run(Program program, TestContext testContext) async {
216 try { 123 try {
217 CoreTypes coreTypes = new CoreTypes(program); 124 CoreTypes coreTypes = new CoreTypes(program);
218 program = generic_types_reification.transformProgram(coreTypes, program); 125 program = generic_types_reification.transformProgram(coreTypes, program);
219 return pass(program); 126 return pass(program);
220 } catch (e, s) { 127 } catch (e, s) {
221 return crash(e, s); 128 return crash(e, s);
222 } 129 }
223 } 130 }
224 } 131 }
225 132
226 class Run extends Step<Uri, int, TestContext> { 133 class Run extends Step<Uri, int, TestContext> {
227 const Run(); 134 const Run();
228 135
229 String get name => "run"; 136 String get name => "run";
230 137
138 bool get isAsync => true;
139
140 bool get isRuntime => true;
141
231 Future<Result<int>> run(Uri uri, TestContext context) async { 142 Future<Result<int>> run(Uri uri, TestContext context) async {
232 File generated = new File.fromUri(uri); 143 File generated = new File.fromUri(uri);
233 StdioProcess process; 144 StdioProcess process;
234 try { 145 try {
235 process = 146 var sdkPath = context.sdk.toFilePath();
236 await StdioProcess.run(context.vm.toFilePath(), [generated.path]); 147 var args = ['--kernel-binaries=$sdkPath', generated.path];
148 process = await StdioProcess.run(context.vm.toFilePath(), args);
237 print(process.output); 149 print(process.output);
238 } finally { 150 } finally {
239 generated.parent.delete(recursive: true); 151 generated.parent.delete(recursive: true);
240 } 152 }
241 return process.toResult(); 153 return process.toResult();
242 } 154 }
243 } 155 }
244 156
245 main(List<String> arguments) => runMe(arguments, createContext, "testing.json"); 157 main(List<String> arguments) => runMe(arguments, createContext, "testing.json");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698