From 6b1597dc0d09a4ad18e65324e510a9ec848fd8d5 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 11 Aug 2016 09:51:19 -0700 Subject: [PATCH] send the base uri back to debuggers (#5321) * send the base uri back to debuggers * add a fullRestart parameter to app.restart * add await --- .../lib/src/commands/daemon.dart | 26 +++++--- packages/flutter_tools/lib/src/hot.dart | 63 +++++++++++-------- .../lib/src/resident_runner.dart | 11 +++- packages/flutter_tools/lib/src/run.dart | 12 ++-- 4 files changed, 70 insertions(+), 42 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index d72a05f6c5f..36aeef2edf3 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -339,25 +339,30 @@ class AppDomain extends Domain { ); } + bool supportsRestart = hotMode ? device.supportsHotMode : device.supportsRestart; + AppInstance app = new AppInstance(_getNextAppId(), runner); _apps.add(app); _sendAppEvent(app, 'start', { 'deviceId': deviceId, 'directory': projectDirectory, - 'supportsRestart': device.supportsRestart && hotMode + 'supportsRestart': supportsRestart }); - Completer observatoryPortCompleter; + Completer connectionInfoCompleter; if (options.debuggingEnabled) { - observatoryPortCompleter = new Completer(); - observatoryPortCompleter.future.then((int port) { - _sendAppEvent(app, 'debugPort', { 'port': port }); + connectionInfoCompleter = new Completer(); + connectionInfoCompleter.future.then((DebugConnectionInfo info) { + Map params = { 'port': info.port }; + if (info.baseUri != null) + params['baseUri'] = info.baseUri; + _sendAppEvent(app, 'debugPort', params); }); } app._runInZone(this, () { - runner.run(observatoryPortCompleter: observatoryPortCompleter, route: route).then((_) { + runner.run(connectionInfoCompleter: connectionInfoCompleter, route: route).then((_) { _sendAppEvent(app, 'stop'); }).catchError((dynamic error) { _sendAppEvent(app, 'stop', { 'error' : error.toString() }); @@ -371,19 +376,20 @@ class AppDomain extends Domain { 'appId': app.id, 'deviceId': deviceId, 'directory': projectDirectory, - 'supportsRestart': device.supportsRestart + 'supportsRestart': supportsRestart }; } Future restart(Map args) async { String appId = _getStringArg(args, 'appId', required: true); + bool fullRestart = _getBoolArg(args, 'fullRestart') ?? false; AppInstance app = _getApp(appId); if (app == null) throw "app '$appId' not found"; return app._runInZone(this, () { - return app.restart(); + return app.restart(fullRestart: fullRestart); }); } @@ -584,7 +590,9 @@ class AppInstance { _AppRunLogger _logger; - Future restart() => runner.restart(); + Future restart({ bool fullRestart: false }) { + return runner.restart(fullRestart: fullRestart); + } Future stop() => runner.stop(); diff --git a/packages/flutter_tools/lib/src/hot.dart b/packages/flutter_tools/lib/src/hot.dart index 56f5de9f682..932aca6f97f 100644 --- a/packages/flutter_tools/lib/src/hot.dart +++ b/packages/flutter_tools/lib/src/hot.dart @@ -162,14 +162,14 @@ class HotRunner extends ResidentRunner { @override Future run({ - Completer observatoryPortCompleter, + Completer connectionInfoCompleter, String route, bool shouldBuild: true }) { // Don't let uncaught errors kill the process. return runZoned(() { return _run( - observatoryPortCompleter: observatoryPortCompleter, + connectionInfoCompleter: connectionInfoCompleter, route: route, shouldBuild: shouldBuild ); @@ -179,7 +179,7 @@ class HotRunner extends ResidentRunner { } Future _run({ - Completer observatoryPortCompleter, + Completer connectionInfoCompleter, String route, bool shouldBuild: true }) async { @@ -275,19 +275,28 @@ class HotRunner extends ResidentRunner { return 2; } - if (observatoryPortCompleter != null && result.hasObservatory) - observatoryPortCompleter.complete(result.observatoryPort); - await connectToServiceProtocol(result.observatoryPort); if (device.needsDevFS) { + try { + Uri baseUri = await _initDevFS(); + if (connectionInfoCompleter != null) { + connectionInfoCompleter.complete( + new DebugConnectionInfo(result.observatoryPort, baseUri: baseUri.toString()) + ); + } + } catch (error) { + printError('Error initializing DevFS: $error'); + return 3; + } _loaderShowMessage('Connecting...', progress: 0); - bool result = await _updateDevFS( + bool devfsResult = await _updateDevFS( progressReporter: (int progress, int max) { - _loaderShowMessage('Syncing files to device...', progress: progress, max: max); + if (progress % 10 == 0) + _loaderShowMessage('Syncing files to device...', progress: progress, max: max); } ); - if (!result) { + if (!devfsResult) { _loaderShowMessage('Failed.'); printError('Could not perform initial file synchronization.'); return 3; @@ -295,6 +304,9 @@ class HotRunner extends ResidentRunner { printStatus('Running ${getDisplayPath(_mainPath)} on ${device.name}...'); _loaderShowMessage('Launching...'); await _launchFromDevFS(_package, _mainPath); + } else { + if (connectionInfoCompleter != null) + connectionInfoCompleter.complete(new DebugConnectionInfo(result.observatoryPort)); } _startReadingFromControlPipe(); @@ -339,22 +351,16 @@ class HotRunner extends ResidentRunner { } DevFS _devFS; + + Future _initDevFS() { + String fsName = path.basename(_projectRootPath); + _devFS = new DevFS(serviceProtocol, + fsName, + new Directory(_projectRootPath)); + return _devFS.create(); + } + Future _updateDevFS({ DevFSProgressReporter progressReporter }) async { - if (_devFS == null) { - String fsName = path.basename(_projectRootPath); - _devFS = new DevFS(serviceProtocol, - fsName, - new Directory(_projectRootPath)); - - try { - await _devFS.create(); - } catch (error) { - _devFS = null; - printError('Error initializing DevFS: $error'); - return false; - } - } - final bool rebuildBundle = bundle.needsBuild(); if (rebuildBundle) { Status bundleStatus = logger.startProgress('Updating assets...'); @@ -484,7 +490,14 @@ class HotRunner extends ResidentRunner { } @override - Future restart() => _reloadSources(); + Future restart({ bool fullRestart: false }) async { + if (fullRestart) { + await _restartFromSources(); + return true; + } else { + return _reloadSources(); + } + } Future _reloadSources() async { if (serviceProtocol.firstIsolateId == null) diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 8ce55ac9b39..0eb5aead4a4 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -32,12 +32,12 @@ abstract class ResidentRunner { /// Start the app and keep the process running during its lifetime. Future run({ - Completer observatoryPortCompleter, + Completer connectionInfoCompleter, String route, bool shouldBuild: true }); - Future restart(); + Future restart({ bool fullRestart: false }); Future stop() async { await stopEchoingDeviceLog(); @@ -208,3 +208,10 @@ String getMissingPackageHintForPlatform(TargetPlatform platform) { return null; } } + +class DebugConnectionInfo { + DebugConnectionInfo(this.port, { this.baseUri }); + + final int port; + final String baseUri; +} diff --git a/packages/flutter_tools/lib/src/run.dart b/packages/flutter_tools/lib/src/run.dart index 7108ef19b52..4764905cd5a 100644 --- a/packages/flutter_tools/lib/src/run.dart +++ b/packages/flutter_tools/lib/src/run.dart @@ -39,7 +39,7 @@ class RunAndStayResident extends ResidentRunner { @override Future run({ - Completer observatoryPortCompleter, + Completer connectionInfoCompleter, String route, bool shouldBuild: true }) { @@ -48,7 +48,7 @@ class RunAndStayResident extends ResidentRunner { return _run( traceStartup: traceStartup, benchmark: benchmark, - observatoryPortCompleter: observatoryPortCompleter, + connectionInfoCompleter: connectionInfoCompleter, route: route, shouldBuild: shouldBuild ); @@ -58,7 +58,7 @@ class RunAndStayResident extends ResidentRunner { } @override - Future restart() async { + Future restart({ bool fullRestart: false }) async { if (serviceProtocol == null) { printError('Debugging is not enabled.'); return false; @@ -94,7 +94,7 @@ class RunAndStayResident extends ResidentRunner { Future _run({ bool traceStartup: false, bool benchmark: false, - Completer observatoryPortCompleter, + Completer connectionInfoCompleter, String route, bool shouldBuild: true }) async { @@ -175,8 +175,8 @@ class RunAndStayResident extends ResidentRunner { startTime.stop(); - if (observatoryPortCompleter != null && _result.hasObservatory) - observatoryPortCompleter.complete(_result.observatoryPort); + if (connectionInfoCompleter != null && _result.hasObservatory) + connectionInfoCompleter.complete(new DebugConnectionInfo(_result.observatoryPort)); // Connect to observatory. if (debuggingOptions.debuggingEnabled) {