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 /// A wrapper on top of the [IncrementalKernelGenerator] that tracks | 5 /// A wrapper on top of the [IncrementalKernelGenerator] that tracks |
6 /// file modifications between subsequent compilation requests and only | 6 /// file modifications between subsequent compilation requests and only |
7 /// invalidates those files that appear to be modified. | 7 /// invalidates those files that appear to be modified. |
8 library front_end.example.incremental_reload.compiler_with_invalidation; | 8 library front_end.example.incremental_reload.compiler_with_invalidation; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 import 'dart:async'; | 11 import 'dart:async'; |
12 | 12 |
13 import 'package:front_end/compiler_options.dart'; | 13 import 'package:front_end/compiler_options.dart'; |
14 import 'package:front_end/incremental_kernel_generator.dart'; | 14 import 'package:front_end/incremental_kernel_generator.dart'; |
15 import 'package:front_end/src/byte_store/file_byte_store.dart'; | 15 import 'package:front_end/src/byte_store/file_byte_store.dart'; |
16 import 'package:front_end/src/byte_store/byte_store.dart'; | 16 import 'package:front_end/src/byte_store/byte_store.dart'; |
17 import 'package:kernel/ast.dart'; | 17 import 'package:kernel/ast.dart'; |
18 import 'package:kernel/binary/limited_ast_to_binary.dart'; | 18 import 'package:kernel/binary/limited_ast_to_binary.dart'; |
| 19 import 'package:kernel/target/targets.dart'; |
19 | 20 |
20 /// Create an instance of an [IncrementalCompiler] to compile a program whose | 21 /// Create an instance of an [IncrementalCompiler] to compile a program whose |
21 /// main entry point file is [entry]. This uses some default options | 22 /// main entry point file is [entry]. This uses some default options |
22 /// for the location of the sdk and temporary folder to save intermediate | 23 /// for the location of the sdk and temporary folder to save intermediate |
23 /// results. | 24 /// results. |
24 // TODO(sigmund): make this example work outside of the SDK repo. | |
25 Future<IncrementalCompiler> createIncrementalCompiler(String entry, | 25 Future<IncrementalCompiler> createIncrementalCompiler(String entry, |
26 {bool persistent: true}) { | 26 {bool persistent: true, Uri sdkRoot, Target target}) { |
27 var entryUri = Uri.base.resolve(entry); | 27 var entryUri = Uri.base.resolve(entry); |
28 var dartVm = Uri.base.resolve(Platform.resolvedExecutable); | 28 var dartVm = Uri.base.resolve(Platform.resolvedExecutable); |
29 var sdkRoot = dartVm.resolve("patched_sdk/"); | |
30 var tmpDir = Directory.systemTemp.createTempSync('ikg_cache'); | 29 var tmpDir = Directory.systemTemp.createTempSync('ikg_cache'); |
31 var options = new CompilerOptions() | 30 var options = new CompilerOptions() |
32 ..sdkRoot = sdkRoot | 31 ..sdkRoot = sdkRoot ?? dartVm.resolve("patched_sdk/") |
33 ..packagesFileUri = Uri.base.resolve('.packages') | 32 ..packagesFileUri = Uri.base.resolve('.packages') |
34 ..strongMode = false | 33 ..strongMode = false |
| 34 ..target = target |
35 // Note: we do not report error on the console because the incremental | 35 // Note: we do not report error on the console because the incremental |
36 // compiler is an ongoing background service that shouldn't polute stdout. | 36 // compiler is an ongoing background service that shouldn't polute stdout. |
37 // TODO(sigmund): do something with the errors. | 37 // TODO(sigmund): do something with the errors. |
38 ..onError = (_) {} | 38 ..onError = (_) {} |
39 ..byteStore = | 39 ..byteStore = |
40 persistent ? new FileByteStore(tmpDir.path) : new MemoryByteStore(); | 40 persistent ? new FileByteStore(tmpDir.path) : new MemoryByteStore(); |
41 return IncrementalCompiler.create(options, entryUri); | 41 return IncrementalCompiler.create(options, entryUri); |
42 } | 42 } |
43 | 43 |
44 /// An incremental compiler that monitors file modifications on disk and | 44 /// An incremental compiler that monitors file modifications on disk and |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 result.errorSeen = true; | 163 result.errorSeen = true; |
164 } | 164 } |
165 | 165 |
166 result.changed = compiler.changed; | 166 result.changed = compiler.changed; |
167 result.totalFiles = compiler.lastModified.length; | 167 result.totalFiles = compiler.lastModified.length; |
168 result.invalidateTime = compiler.invalidateTime; | 168 result.invalidateTime = compiler.invalidateTime; |
169 result.compileTime = compiler.compileTime; | 169 result.compileTime = compiler.compileTime; |
170 result.reloadTime = 0; | 170 result.reloadTime = 0; |
171 return result; | 171 return result; |
172 } | 172 } |
OLD | NEW |