| 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 /// Example that illustrates how to use the incremental compiler and trigger a | 5 /// Example that illustrates how to use the incremental compiler and trigger a |
| 6 /// hot-reload on the VM after recompiling the application. | 6 /// hot-reload on the VM after recompiling the application. |
| 7 /// | 7 /// |
| 8 /// This example resembles the `run` command in flutter-tools. It creates an | 8 /// This example resembles the `run` command in flutter-tools. It creates an |
| 9 /// interactive command-line program that waits for the user to tap a key to | 9 /// interactive command-line program that waits for the user to tap a key to |
| 10 /// trigger a recompile and reload. | 10 /// trigger a recompile and reload. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 library front_end.example.incremental_reload.run; | 43 library front_end.example.incremental_reload.run; |
| 44 | 44 |
| 45 import 'dart:io'; | 45 import 'dart:io'; |
| 46 import 'dart:async'; | 46 import 'dart:async'; |
| 47 import 'dart:convert' show ASCII; | 47 import 'dart:convert' show ASCII; |
| 48 | 48 |
| 49 import '../../tool/vm/reload.dart'; | 49 import '../../tool/vm/reload.dart'; |
| 50 | 50 |
| 51 import 'compiler_with_invalidation.dart'; | 51 import 'compiler_with_invalidation.dart'; |
| 52 | 52 |
| 53 VmReloader reloader = new VmReloader(); | 53 RemoteVm remoteVm = new RemoteVm(); |
| 54 AnsiTerminal terminal = new AnsiTerminal(); | 54 AnsiTerminal terminal = new AnsiTerminal(); |
| 55 | 55 |
| 56 main(List<String> args) async { | 56 main(List<String> args) async { |
| 57 if (args.length <= 1) { | 57 if (args.length <= 1) { |
| 58 print('usage: dart incremental_compile.dart input.dart out.dill'); | 58 print('usage: dart incremental_compile.dart input.dart out.dill'); |
| 59 exit(1); | 59 exit(1); |
| 60 } | 60 } |
| 61 | 61 |
| 62 var compiler = await createIncrementalCompiler(args[0]); | 62 var compiler = await createIncrementalCompiler(args[0]); |
| 63 var outputUri = Uri.base.resolve(args[1]); | 63 var outputUri = Uri.base.resolve(args[1]); |
| 64 | 64 |
| 65 showHeader(); | 65 showHeader(); |
| 66 listenOnKeyPress(compiler, outputUri) | 66 listenOnKeyPress(compiler, outputUri) |
| 67 .whenComplete(() => reloader.disconnect()); | 67 .whenComplete(() => remoteVm.disconnect()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 /// Implements the interactive UI by listening for input keys from the user. | 70 /// Implements the interactive UI by listening for input keys from the user. |
| 71 Future listenOnKeyPress(IncrementalCompiler compiler, Uri outputUri) { | 71 Future listenOnKeyPress(IncrementalCompiler compiler, Uri outputUri) { |
| 72 var completer = new Completer(); | 72 var completer = new Completer(); |
| 73 terminal.singleCharMode = true; | 73 terminal.singleCharMode = true; |
| 74 StreamSubscription subscription; | 74 StreamSubscription subscription; |
| 75 subscription = terminal.onCharInput.listen((String char) async { | 75 subscription = terminal.onCharInput.listen((String char) async { |
| 76 try { | 76 try { |
| 77 CompilationResult compilationResult; | 77 CompilationResult compilationResult; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 completer.completeError(null); | 115 completer.completeError(null); |
| 116 }); | 116 }); |
| 117 | 117 |
| 118 return completer.future; | 118 return completer.future; |
| 119 } | 119 } |
| 120 | 120 |
| 121 /// Request a reload and gather timing metrics. | 121 /// Request a reload and gather timing metrics. |
| 122 Future<ReloadResult> reload(outputUri) async { | 122 Future<ReloadResult> reload(outputUri) async { |
| 123 var result = new ReloadResult(); | 123 var result = new ReloadResult(); |
| 124 var reloadTimer = new Stopwatch()..start(); | 124 var reloadTimer = new Stopwatch()..start(); |
| 125 var reloadResult = await reloader.reload(outputUri); | 125 var reloadResult = await remoteVm.reload(outputUri); |
| 126 reloadTimer.stop(); | 126 reloadTimer.stop(); |
| 127 result.reloadTime = reloadTimer.elapsedMilliseconds; | 127 result.reloadTime = reloadTimer.elapsedMilliseconds; |
| 128 result.errorSeen = false; | 128 result.errorSeen = false; |
| 129 result.errorDetails; | 129 result.errorDetails; |
| 130 if (!reloadResult['success']) { | 130 if (!reloadResult['success']) { |
| 131 result.errorSeen = true; | 131 result.errorSeen = true; |
| 132 result.errorDetails = reloadResult['details']['notices'].first['message']; | 132 result.errorDetails = reloadResult['details']['notices'].first['message']; |
| 133 } | 133 } |
| 134 return result; | 134 return result; |
| 135 } | 135 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } on StdinException catch (error) { | 275 } on StdinException catch (error) { |
| 276 if (!_lineModeIgnorableErrors.contains(error.osError?.errorCode)) rethrow; | 276 if (!_lineModeIgnorableErrors.contains(error.osError?.errorCode)) rethrow; |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 /// Return keystrokes from the console. | 280 /// Return keystrokes from the console. |
| 281 /// | 281 /// |
| 282 /// Useful when the console is in [singleCharMode]. | 282 /// Useful when the console is in [singleCharMode]. |
| 283 Stream<String> get onCharInput => stdin.transform(ASCII.decoder); | 283 Stream<String> get onCharInput => stdin.transform(ASCII.decoder); |
| 284 } | 284 } |
| OLD | NEW |