Commit 0a79ffe7 authored by John McCutchan's avatar John McCutchan Committed by GitHub

Fix hot restart so that it works with iOS simulators (#5272)

parent 2f23137c
...@@ -38,10 +38,13 @@ class HotRunner extends ResidentRunner { ...@@ -38,10 +38,13 @@ class HotRunner extends ResidentRunner {
}) : super(device, }) : super(device,
target: target, target: target,
debuggingOptions: debuggingOptions, debuggingOptions: debuggingOptions,
usesTerminalUI: usesTerminalUI); usesTerminalUI: usesTerminalUI) {
_projectRootPath = Directory.current.path;
}
ApplicationPackage _package; ApplicationPackage _package;
String _mainPath; String _mainPath;
String _projectRootPath;
final AssetBundle bundle = new AssetBundle(); final AssetBundle bundle = new AssetBundle();
/// Start the app and keep the process running during its lifetime. /// Start the app and keep the process running during its lifetime.
...@@ -202,13 +205,12 @@ class HotRunner extends ResidentRunner { ...@@ -202,13 +205,12 @@ class HotRunner extends ResidentRunner {
} }
DevFS _devFS; DevFS _devFS;
String _devFSProjectRootPath;
Future<bool> _updateDevFS({ DevFSProgressReporter progressReporter }) async { Future<bool> _updateDevFS({ DevFSProgressReporter progressReporter }) async {
if (_devFS == null) { if (_devFS == null) {
Directory directory = Directory.current; String fsName = path.basename(_projectRootPath);
_devFSProjectRootPath = directory.path; _devFS = new DevFS(serviceProtocol,
String fsName = path.basename(directory.path); fsName,
_devFS = new DevFS(serviceProtocol, fsName, directory); new Directory(_projectRootPath));
try { try {
await _devFS.create(); await _devFS.create();
...@@ -242,17 +244,10 @@ class HotRunner extends ResidentRunner { ...@@ -242,17 +244,10 @@ class HotRunner extends ResidentRunner {
_devFS = null; _devFS = null;
} }
Future<Null> _launchFromDevFS(ApplicationPackage package, Future<Null> _launchInView(String entryPath,
String mainScript) async { String packagesPath,
String entryPath = path.relative(mainScript, from: _devFSProjectRootPath); String assetsDirectoryPath) async {
String deviceEntryPath =
_devFS.baseUri.resolve(entryPath).toFilePath();
String devicePackagesPath =
_devFS.baseUri.resolve('.packages').toFilePath();
String deviceAssetsDirectoryPath =
_devFS.baseUri.resolve('build/flx').toFilePath();
String viewId = await serviceProtocol.getFirstViewId(); String viewId = await serviceProtocol.getFirstViewId();
// When this completer completes the isolate is running. // When this completer completes the isolate is running.
// TODO(johnmccutchan): Have the framework send an event after the first // TODO(johnmccutchan): Have the framework send an event after the first
// frame is rendered and use that instead of 'runnable'. // frame is rendered and use that instead of 'runnable'.
...@@ -267,20 +262,51 @@ class HotRunner extends ResidentRunner { ...@@ -267,20 +262,51 @@ class HotRunner extends ResidentRunner {
} }
}); });
await serviceProtocol.runInView(viewId, await serviceProtocol.runInView(viewId,
deviceEntryPath, entryPath,
devicePackagesPath, packagesPath,
deviceAssetsDirectoryPath); assetsDirectoryPath);
await completer.future; await completer.future;
await subscription.cancel(); await subscription.cancel();
} }
Future<Null> _launchFromDevFS(ApplicationPackage package,
String mainScript) async {
String entryPath = path.relative(mainScript, from: _projectRootPath);
String deviceEntryPath =
_devFS.baseUri.resolve(entryPath).toFilePath();
String devicePackagesPath =
_devFS.baseUri.resolve('.packages').toFilePath();
String deviceAssetsDirectoryPath =
_devFS.baseUri.resolve('build/flx').toFilePath();
await _launchInView(deviceEntryPath,
devicePackagesPath,
deviceAssetsDirectoryPath);
}
Future<Null> _launchFromDisk(ApplicationPackage package,
String mainScript) async {
Uri baseUri = new Uri.directory(_projectRootPath);
String entryPath = path.relative(mainScript, from: _projectRootPath);
String diskEntryPath = baseUri.resolve(entryPath).toFilePath();
String diskPackagesPath = baseUri.resolve('.packages').toFilePath();
String diskAssetsDirectoryPath = baseUri.resolve('build/flx').toFilePath();
await _launchInView(diskEntryPath,
diskPackagesPath,
diskAssetsDirectoryPath);
}
Future<Null> _restartFromSources() async { Future<Null> _restartFromSources() async {
if (_devFS != null) if (_devFS == null) {
Status restartStatus = logger.startProgress('Restarting application...');
await _launchFromDisk(_package, _mainPath);
restartStatus.stop(showElapsedTime: true);
} else {
await _updateDevFS(); await _updateDevFS();
Status restartStatus = logger.startProgress('Restarting application...'); Status restartStatus = logger.startProgress('Restarting application...');
await _launchFromDevFS(_package, _mainPath); await _launchFromDevFS(_package, _mainPath);
restartStatus.stop(showElapsedTime: true); restartStatus.stop(showElapsedTime: true);
} }
}
/// Returns [true] if the reload was successful. /// Returns [true] if the reload was successful.
bool _printReloadReport(Map<String, dynamic> reloadReport) { bool _printReloadReport(Map<String, dynamic> reloadReport) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment