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 {
}) : super(device,
target: target,
debuggingOptions: debuggingOptions,
usesTerminalUI: usesTerminalUI);
usesTerminalUI: usesTerminalUI) {
_projectRootPath = Directory.current.path;
}
ApplicationPackage _package;
String _mainPath;
String _projectRootPath;
final AssetBundle bundle = new AssetBundle();
/// Start the app and keep the process running during its lifetime.
......@@ -202,13 +205,12 @@ class HotRunner extends ResidentRunner {
}
DevFS _devFS;
String _devFSProjectRootPath;
Future<bool> _updateDevFS({ DevFSProgressReporter progressReporter }) async {
if (_devFS == null) {
Directory directory = Directory.current;
_devFSProjectRootPath = directory.path;
String fsName = path.basename(directory.path);
_devFS = new DevFS(serviceProtocol, fsName, directory);
String fsName = path.basename(_projectRootPath);
_devFS = new DevFS(serviceProtocol,
fsName,
new Directory(_projectRootPath));
try {
await _devFS.create();
......@@ -242,17 +244,10 @@ class HotRunner extends ResidentRunner {
_devFS = null;
}
Future<Null> _launchFromDevFS(ApplicationPackage package,
String mainScript) async {
String entryPath = path.relative(mainScript, from: _devFSProjectRootPath);
String deviceEntryPath =
_devFS.baseUri.resolve(entryPath).toFilePath();
String devicePackagesPath =
_devFS.baseUri.resolve('.packages').toFilePath();
String deviceAssetsDirectoryPath =
_devFS.baseUri.resolve('build/flx').toFilePath();
Future<Null> _launchInView(String entryPath,
String packagesPath,
String assetsDirectoryPath) async {
String viewId = await serviceProtocol.getFirstViewId();
// When this completer completes the isolate is running.
// TODO(johnmccutchan): Have the framework send an event after the first
// frame is rendered and use that instead of 'runnable'.
......@@ -267,20 +262,51 @@ class HotRunner extends ResidentRunner {
}
});
await serviceProtocol.runInView(viewId,
deviceEntryPath,
devicePackagesPath,
deviceAssetsDirectoryPath);
entryPath,
packagesPath,
assetsDirectoryPath);
await completer.future;
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 {
if (_devFS != null)
if (_devFS == null) {
Status restartStatus = logger.startProgress('Restarting application...');
await _launchFromDisk(_package, _mainPath);
restartStatus.stop(showElapsedTime: true);
} else {
await _updateDevFS();
Status restartStatus = logger.startProgress('Restarting application...');
await _launchFromDevFS(_package, _mainPath);
restartStatus.stop(showElapsedTime: true);
}
}
/// Returns [true] if the reload was successful.
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