OLD | NEW |
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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:front_end/compiler_options.dart'; | 7 import 'package:front_end/compiler_options.dart'; |
8 import 'package:front_end/incremental_kernel_generator.dart'; | 8 import 'package:front_end/incremental_kernel_generator.dart'; |
9 import 'package:front_end/memory_file_system.dart'; | 9 import 'package:front_end/memory_file_system.dart'; |
10 import 'package:front_end/src/incremental/byte_store.dart'; | 10 import 'package:front_end/src/incremental/byte_store.dart'; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 .newInstance(compilerOptions, entryPoint, watch: watchFn); | 52 .newInstance(compilerOptions, entryPoint, watch: watchFn); |
53 return (await incrementalKernelGenerator.computeDelta()).newProgram; | 53 return (await incrementalKernelGenerator.computeDelta()).newProgram; |
54 } | 54 } |
55 | 55 |
56 test_compile_chain() async { | 56 test_compile_chain() async { |
57 writeFile('/test/.packages', 'test:lib/'); | 57 writeFile('/test/.packages', 'test:lib/'); |
58 String aPath = '/test/lib/a.dart'; | 58 String aPath = '/test/lib/a.dart'; |
59 String bPath = '/test/lib/b.dart'; | 59 String bPath = '/test/lib/b.dart'; |
60 String cPath = '/test/lib/c.dart'; | 60 String cPath = '/test/lib/c.dart'; |
61 Uri aUri = writeFile(aPath, 'var a = 1;'); | 61 Uri aUri = writeFile(aPath, 'var a = 1;'); |
62 Uri bUri = writeFile( | 62 Uri bUri = writeFile(bPath, r''' |
63 bPath, | |
64 r''' | |
65 import 'a.dart'; | 63 import 'a.dart'; |
66 var b = a; | 64 var b = a; |
67 '''); | 65 '''); |
68 Uri cUri = writeFile( | 66 Uri cUri = writeFile(cPath, r''' |
69 cPath, | |
70 r''' | |
71 import 'a.dart'; | 67 import 'a.dart'; |
72 import 'b.dart'; | 68 import 'b.dart'; |
73 var c1 = a; | 69 var c1 = a; |
74 var c2 = b; | 70 var c2 = b; |
75 void main() {} | 71 void main() {} |
76 '''); | 72 '''); |
77 | 73 |
78 { | 74 { |
79 Program program = await getInitialState(cUri); | 75 Program program = await getInitialState(cUri); |
80 _assertLibraryUris(program, | 76 _assertLibraryUris(program, |
81 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); | 77 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); |
82 Library library = _getLibrary(program, cUri); | 78 Library library = _getLibrary(program, cUri); |
83 expect( | 79 expect(_getLibraryText(library), r''' |
84 _getLibraryText(library), | |
85 r''' | |
86 library; | 80 library; |
87 import self as self; | 81 import self as self; |
88 import "dart:core" as core; | 82 import "dart:core" as core; |
89 import "./a.dart" as a; | 83 import "./a.dart" as a; |
90 import "./b.dart" as b; | 84 import "./b.dart" as b; |
91 | 85 |
92 static field core::int c1 = a::a; | 86 static field core::int c1 = a::a; |
93 static field core::int c2 = b::b; | 87 static field core::int c2 = b::b; |
94 static method main() → void {} | 88 static method main() → void {} |
95 '''); | 89 '''); |
96 // The main method is set. | 90 // The main method is set. |
97 expect(program.mainMethod, isNotNull); | 91 expect(program.mainMethod, isNotNull); |
98 expect(program.mainMethod.enclosingLibrary.fileUri, cUri.toString()); | 92 expect(program.mainMethod.enclosingLibrary.fileUri, cUri.toString()); |
99 } | 93 } |
100 | 94 |
101 // Update b.dart and recompile c.dart | 95 // Update b.dart and recompile c.dart |
102 writeFile( | 96 writeFile(bPath, r''' |
103 bPath, | |
104 r''' | |
105 import 'a.dart'; | 97 import 'a.dart'; |
106 var b = 1.2; | 98 var b = 1.2; |
107 '''); | 99 '''); |
108 incrementalKernelGenerator.invalidate(bUri); | 100 incrementalKernelGenerator.invalidate(bUri); |
109 { | 101 { |
110 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); | 102 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
111 Program program = delta.newProgram; | 103 Program program = delta.newProgram; |
112 _assertLibraryUris(program, | 104 _assertLibraryUris(program, |
113 includes: [bUri, cUri], excludes: [aUri, Uri.parse('dart:core')]); | 105 includes: [bUri, cUri], excludes: [aUri, Uri.parse('dart:core')]); |
114 Library library = _getLibrary(program, cUri); | 106 Library library = _getLibrary(program, cUri); |
115 expect( | 107 expect(_getLibraryText(library), r''' |
116 _getLibraryText(library), | |
117 r''' | |
118 library; | 108 library; |
119 import self as self; | 109 import self as self; |
120 import "dart:core" as core; | 110 import "dart:core" as core; |
121 import "./a.dart" as a; | 111 import "./a.dart" as a; |
122 import "./b.dart" as b; | 112 import "./b.dart" as b; |
123 | 113 |
124 static field core::int c1 = a::a; | 114 static field core::int c1 = a::a; |
125 static field core::double c2 = b::b; | 115 static field core::double c2 = b::b; |
126 static method main() → void {} | 116 static method main() → void {} |
127 '''); | 117 '''); |
128 // The main method is set even though not the entry point is updated. | 118 // The main method is set even though not the entry point is updated. |
129 expect(program.mainMethod, isNotNull); | 119 expect(program.mainMethod, isNotNull); |
130 expect(program.mainMethod.enclosingLibrary.fileUri, cUri.toString()); | 120 expect(program.mainMethod.enclosingLibrary.fileUri, cUri.toString()); |
131 } | 121 } |
132 } | 122 } |
133 | 123 |
134 test_compile_includePathToMain() async { | 124 test_compile_includePathToMain() async { |
135 writeFile('/test/.packages', 'test:lib/'); | 125 writeFile('/test/.packages', 'test:lib/'); |
136 String aPath = '/test/lib/a.dart'; | 126 String aPath = '/test/lib/a.dart'; |
137 String bPath = '/test/lib/b.dart'; | 127 String bPath = '/test/lib/b.dart'; |
138 String cPath = '/test/lib/c.dart'; | 128 String cPath = '/test/lib/c.dart'; |
139 String dPath = '/test/lib/d.dart'; | 129 String dPath = '/test/lib/d.dart'; |
140 | 130 |
141 // A --> B -> C | 131 // A --> B -> C |
142 // \-> D | 132 // \-> D |
143 | 133 |
144 Uri aUri = writeFile( | 134 Uri aUri = writeFile(aPath, r''' |
145 aPath, | |
146 r''' | |
147 import 'b.dart'; | 135 import 'b.dart'; |
148 import 'd.dart'; | 136 import 'd.dart'; |
149 main() { | 137 main() { |
150 b(); | 138 b(); |
151 d(); | 139 d(); |
152 } | 140 } |
153 '''); | 141 '''); |
154 Uri bUri = writeFile( | 142 Uri bUri = writeFile(bPath, r''' |
155 bPath, | |
156 r''' | |
157 import 'c.dart'; | 143 import 'c.dart'; |
158 b() { | 144 b() { |
159 c(); | 145 c(); |
160 } | 146 } |
161 '''); | 147 '''); |
162 Uri cUri = writeFile(cPath, 'c() { print(0); }'); | 148 Uri cUri = writeFile(cPath, 'c() { print(0); }'); |
163 Uri dUri = writeFile(dPath, 'd() {}'); | 149 Uri dUri = writeFile(dPath, 'd() {}'); |
164 | 150 |
165 { | 151 { |
166 Program program = await getInitialState(aUri); | 152 Program program = await getInitialState(aUri); |
(...skipping 15 matching lines...) Expand all Loading... |
182 excludes: [dUri, Uri.parse('dart:core')]); | 168 excludes: [dUri, Uri.parse('dart:core')]); |
183 // While a.dart and b.dart are is included (VM needs them), they were not | 169 // While a.dart and b.dart are is included (VM needs them), they were not |
184 // recompiled, because the change to c.dart was in the function body. | 170 // recompiled, because the change to c.dart was in the function body. |
185 _assertCompiledUris([cUri]); | 171 _assertCompiledUris([cUri]); |
186 } | 172 } |
187 } | 173 } |
188 | 174 |
189 test_updateEntryPoint() async { | 175 test_updateEntryPoint() async { |
190 writeFile('/test/.packages', 'test:lib/'); | 176 writeFile('/test/.packages', 'test:lib/'); |
191 String path = '/test/lib/test.dart'; | 177 String path = '/test/lib/test.dart'; |
192 Uri uri = writeFile( | 178 Uri uri = writeFile(path, r''' |
193 path, | |
194 r''' | |
195 main() { | 179 main() { |
196 var v = 1; | 180 var v = 1; |
197 } | 181 } |
198 '''); | 182 '''); |
199 | 183 |
200 String initialText = r''' | 184 String initialText = r''' |
201 library; | 185 library; |
202 import self as self; | 186 import self as self; |
203 import "dart:core" as core; | 187 import "dart:core" as core; |
204 | 188 |
205 static method main() → dynamic { | 189 static method main() → dynamic { |
206 core::int v = 1; | 190 core::int v = 1; |
207 } | 191 } |
208 '''; | 192 '''; |
209 | 193 |
210 // Compute the initial state. | 194 // Compute the initial state. |
211 { | 195 { |
212 Program program = await getInitialState(uri); | 196 Program program = await getInitialState(uri); |
213 Library library = _getLibrary(program, uri); | 197 Library library = _getLibrary(program, uri); |
214 expect(_getLibraryText(library), initialText); | 198 expect(_getLibraryText(library), initialText); |
215 } | 199 } |
216 | 200 |
217 // Update the entry point library. | 201 // Update the entry point library. |
218 writeFile( | 202 writeFile(path, r''' |
219 path, | |
220 r''' | |
221 main() { | 203 main() { |
222 var v = 2.3; | 204 var v = 2.3; |
223 } | 205 } |
224 '''); | 206 '''); |
225 | 207 |
226 // We have not invalidated the file, so the delta is empty. | 208 // We have not invalidated the file, so the delta is empty. |
227 { | 209 { |
228 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); | 210 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
229 expect(delta.newProgram.libraries, isEmpty); | 211 expect(delta.newProgram.libraries, isEmpty); |
230 } | 212 } |
231 | 213 |
232 // Invalidate the file, so get the new text. | 214 // Invalidate the file, so get the new text. |
233 incrementalKernelGenerator.invalidate(uri); | 215 incrementalKernelGenerator.invalidate(uri); |
234 { | 216 { |
235 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); | 217 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
236 Program program = delta.newProgram; | 218 Program program = delta.newProgram; |
237 _assertLibraryUris(program, includes: [uri]); | 219 _assertLibraryUris(program, includes: [uri]); |
238 Library library = _getLibrary(program, uri); | 220 Library library = _getLibrary(program, uri); |
239 expect( | 221 expect(_getLibraryText(library), r''' |
240 _getLibraryText(library), | |
241 r''' | |
242 library; | 222 library; |
243 import self as self; | 223 import self as self; |
244 import "dart:core" as core; | 224 import "dart:core" as core; |
245 | 225 |
246 static method main() → dynamic { | 226 static method main() → dynamic { |
247 core::double v = 2.3; | 227 core::double v = 2.3; |
248 } | 228 } |
249 '''); | 229 '''); |
250 } | 230 } |
251 } | 231 } |
252 | 232 |
253 test_watch() async { | 233 test_watch() async { |
254 writeFile('/test/.packages', 'test:lib/'); | 234 writeFile('/test/.packages', 'test:lib/'); |
255 String aPath = '/test/lib/a.dart'; | 235 String aPath = '/test/lib/a.dart'; |
256 String bPath = '/test/lib/b.dart'; | 236 String bPath = '/test/lib/b.dart'; |
257 String cPath = '/test/lib/c.dart'; | 237 String cPath = '/test/lib/c.dart'; |
258 Uri aUri = writeFile(aPath, ''); | 238 Uri aUri = writeFile(aPath, ''); |
259 Uri bUri = writeFile(bPath, ''); | 239 Uri bUri = writeFile(bPath, ''); |
260 Uri cUri = writeFile( | 240 Uri cUri = writeFile(cPath, r''' |
261 cPath, | |
262 r''' | |
263 import 'a.dart'; | 241 import 'a.dart'; |
264 '''); | 242 '''); |
265 | 243 |
266 var usedFiles = <Uri>[]; | 244 var usedFiles = <Uri>[]; |
267 var unusedFiles = <Uri>[]; | 245 var unusedFiles = <Uri>[]; |
268 watchFn = (Uri uri, bool used) { | 246 watchFn = (Uri uri, bool used) { |
269 if (used) { | 247 if (used) { |
270 usedFiles.add(uri); | 248 usedFiles.add(uri); |
271 } else { | 249 } else { |
272 unusedFiles.add(uri); | 250 unusedFiles.add(uri); |
273 } | 251 } |
274 return new Future.value(); | 252 return new Future.value(); |
275 }; | 253 }; |
276 | 254 |
277 { | 255 { |
278 await getInitialState(cUri); | 256 await getInitialState(cUri); |
279 // We use at least c.dart and a.dart now. | 257 // We use at least c.dart and a.dart now. |
280 expect(usedFiles, contains(cUri)); | 258 expect(usedFiles, contains(cUri)); |
281 expect(usedFiles, contains(aUri)); | 259 expect(usedFiles, contains(aUri)); |
282 usedFiles.clear(); | 260 usedFiles.clear(); |
283 expect(unusedFiles, isEmpty); | 261 expect(unusedFiles, isEmpty); |
284 } | 262 } |
285 | 263 |
286 // Update c.dart to reference also b.dart file. | 264 // Update c.dart to reference also b.dart file. |
287 writeFile( | 265 writeFile(cPath, r''' |
288 cPath, | |
289 r''' | |
290 import 'a.dart'; | 266 import 'a.dart'; |
291 import 'b.dart'; | 267 import 'b.dart'; |
292 '''); | 268 '''); |
293 incrementalKernelGenerator.invalidate(cUri); | 269 incrementalKernelGenerator.invalidate(cUri); |
294 { | 270 { |
295 await incrementalKernelGenerator.computeDelta(); | 271 await incrementalKernelGenerator.computeDelta(); |
296 // The only new file is b.dart now. | 272 // The only new file is b.dart now. |
297 expect(usedFiles, [bUri]); | 273 expect(usedFiles, [bUri]); |
298 usedFiles.clear(); | 274 usedFiles.clear(); |
299 expect(unusedFiles, isEmpty); | 275 expect(unusedFiles, isEmpty); |
300 } | 276 } |
301 | 277 |
302 // Update c.dart to stop referencing b.dart file. | 278 // Update c.dart to stop referencing b.dart file. |
303 writeFile( | 279 writeFile(cPath, r''' |
304 cPath, | |
305 r''' | |
306 import 'a.dart'; | 280 import 'a.dart'; |
307 '''); | 281 '''); |
308 incrementalKernelGenerator.invalidate(cUri); | 282 incrementalKernelGenerator.invalidate(cUri); |
309 { | 283 { |
310 await incrementalKernelGenerator.computeDelta(); | 284 await incrementalKernelGenerator.computeDelta(); |
311 // No new used files. | 285 // No new used files. |
312 expect(usedFiles, isEmpty); | 286 expect(usedFiles, isEmpty); |
313 // The file b.dart is not used anymore. | 287 // The file b.dart is not used anymore. |
314 expect(unusedFiles, [bUri]); | 288 expect(unusedFiles, [bUri]); |
315 unusedFiles.clear(); | 289 unusedFiles.clear(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 throw fail('No library found with URI "$uri"'); | 352 throw fail('No library found with URI "$uri"'); |
379 } | 353 } |
380 | 354 |
381 String _getLibraryText(Library library) { | 355 String _getLibraryText(Library library) { |
382 StringBuffer buffer = new StringBuffer(); | 356 StringBuffer buffer = new StringBuffer(); |
383 new Printer(buffer, syntheticNames: new NameSystem()) | 357 new Printer(buffer, syntheticNames: new NameSystem()) |
384 .writeLibraryFile(library); | 358 .writeLibraryFile(library); |
385 return buffer.toString(); | 359 return buffer.toString(); |
386 } | 360 } |
387 } | 361 } |
OLD | NEW |