Commit 6b1597dc authored by Devon Carew's avatar Devon Carew Committed by GitHub

send the base uri back to debuggers (#5321)

* send the base uri back to debuggers

* add a fullRestart parameter to app.restart

* add await
parent ec0f8800
...@@ -339,25 +339,30 @@ class AppDomain extends Domain { ...@@ -339,25 +339,30 @@ class AppDomain extends Domain {
); );
} }
bool supportsRestart = hotMode ? device.supportsHotMode : device.supportsRestart;
AppInstance app = new AppInstance(_getNextAppId(), runner); AppInstance app = new AppInstance(_getNextAppId(), runner);
_apps.add(app); _apps.add(app);
_sendAppEvent(app, 'start', <String, dynamic>{ _sendAppEvent(app, 'start', <String, dynamic>{
'deviceId': deviceId, 'deviceId': deviceId,
'directory': projectDirectory, 'directory': projectDirectory,
'supportsRestart': device.supportsRestart && hotMode 'supportsRestart': supportsRestart
}); });
Completer<int> observatoryPortCompleter; Completer<DebugConnectionInfo> connectionInfoCompleter;
if (options.debuggingEnabled) { if (options.debuggingEnabled) {
observatoryPortCompleter = new Completer<int>(); connectionInfoCompleter = new Completer<DebugConnectionInfo>();
observatoryPortCompleter.future.then((int port) { connectionInfoCompleter.future.then((DebugConnectionInfo info) {
_sendAppEvent(app, 'debugPort', <String, dynamic>{ 'port': port }); Map<String, dynamic> params = <String, dynamic>{ 'port': info.port };
if (info.baseUri != null)
params['baseUri'] = info.baseUri;
_sendAppEvent(app, 'debugPort', params);
}); });
} }
app._runInZone(this, () { app._runInZone(this, () {
runner.run(observatoryPortCompleter: observatoryPortCompleter, route: route).then((_) { runner.run(connectionInfoCompleter: connectionInfoCompleter, route: route).then((_) {
_sendAppEvent(app, 'stop'); _sendAppEvent(app, 'stop');
}).catchError((dynamic error) { }).catchError((dynamic error) {
_sendAppEvent(app, 'stop', <String, dynamic>{ 'error' : error.toString() }); _sendAppEvent(app, 'stop', <String, dynamic>{ 'error' : error.toString() });
...@@ -371,19 +376,20 @@ class AppDomain extends Domain { ...@@ -371,19 +376,20 @@ class AppDomain extends Domain {
'appId': app.id, 'appId': app.id,
'deviceId': deviceId, 'deviceId': deviceId,
'directory': projectDirectory, 'directory': projectDirectory,
'supportsRestart': device.supportsRestart 'supportsRestart': supportsRestart
}; };
} }
Future<bool> restart(Map<String, dynamic> args) async { Future<bool> restart(Map<String, dynamic> args) async {
String appId = _getStringArg(args, 'appId', required: true); String appId = _getStringArg(args, 'appId', required: true);
bool fullRestart = _getBoolArg(args, 'fullRestart') ?? false;
AppInstance app = _getApp(appId); AppInstance app = _getApp(appId);
if (app == null) if (app == null)
throw "app '$appId' not found"; throw "app '$appId' not found";
return app._runInZone(this, () { return app._runInZone(this, () {
return app.restart(); return app.restart(fullRestart: fullRestart);
}); });
} }
...@@ -584,7 +590,9 @@ class AppInstance { ...@@ -584,7 +590,9 @@ class AppInstance {
_AppRunLogger _logger; _AppRunLogger _logger;
Future<bool> restart() => runner.restart(); Future<bool> restart({ bool fullRestart: false }) {
return runner.restart(fullRestart: fullRestart);
}
Future<Null> stop() => runner.stop(); Future<Null> stop() => runner.stop();
......
...@@ -162,14 +162,14 @@ class HotRunner extends ResidentRunner { ...@@ -162,14 +162,14 @@ class HotRunner extends ResidentRunner {
@override @override
Future<int> run({ Future<int> run({
Completer<int> observatoryPortCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) { }) {
// Don't let uncaught errors kill the process. // Don't let uncaught errors kill the process.
return runZoned(() { return runZoned(() {
return _run( return _run(
observatoryPortCompleter: observatoryPortCompleter, connectionInfoCompleter: connectionInfoCompleter,
route: route, route: route,
shouldBuild: shouldBuild shouldBuild: shouldBuild
); );
...@@ -179,7 +179,7 @@ class HotRunner extends ResidentRunner { ...@@ -179,7 +179,7 @@ class HotRunner extends ResidentRunner {
} }
Future<int> _run({ Future<int> _run({
Completer<int> observatoryPortCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) async { }) async {
...@@ -275,19 +275,28 @@ class HotRunner extends ResidentRunner { ...@@ -275,19 +275,28 @@ class HotRunner extends ResidentRunner {
return 2; return 2;
} }
if (observatoryPortCompleter != null && result.hasObservatory)
observatoryPortCompleter.complete(result.observatoryPort);
await connectToServiceProtocol(result.observatoryPort); await connectToServiceProtocol(result.observatoryPort);
if (device.needsDevFS) { 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); _loaderShowMessage('Connecting...', progress: 0);
bool result = await _updateDevFS( bool devfsResult = await _updateDevFS(
progressReporter: (int progress, int max) { 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.'); _loaderShowMessage('Failed.');
printError('Could not perform initial file synchronization.'); printError('Could not perform initial file synchronization.');
return 3; return 3;
...@@ -295,6 +304,9 @@ class HotRunner extends ResidentRunner { ...@@ -295,6 +304,9 @@ class HotRunner extends ResidentRunner {
printStatus('Running ${getDisplayPath(_mainPath)} on ${device.name}...'); printStatus('Running ${getDisplayPath(_mainPath)} on ${device.name}...');
_loaderShowMessage('Launching...'); _loaderShowMessage('Launching...');
await _launchFromDevFS(_package, _mainPath); await _launchFromDevFS(_package, _mainPath);
} else {
if (connectionInfoCompleter != null)
connectionInfoCompleter.complete(new DebugConnectionInfo(result.observatoryPort));
} }
_startReadingFromControlPipe(); _startReadingFromControlPipe();
...@@ -339,22 +351,16 @@ class HotRunner extends ResidentRunner { ...@@ -339,22 +351,16 @@ class HotRunner extends ResidentRunner {
} }
DevFS _devFS; DevFS _devFS;
Future<bool> _updateDevFS({ DevFSProgressReporter progressReporter }) async {
if (_devFS == null) {
String fsName = path.basename(_projectRootPath);
_devFS = new DevFS(serviceProtocol,
fsName,
new Directory(_projectRootPath));
try { Future<Uri> _initDevFS() {
await _devFS.create(); String fsName = path.basename(_projectRootPath);
} catch (error) { _devFS = new DevFS(serviceProtocol,
_devFS = null; fsName,
printError('Error initializing DevFS: $error'); new Directory(_projectRootPath));
return false; return _devFS.create();
} }
}
Future<bool> _updateDevFS({ DevFSProgressReporter progressReporter }) async {
final bool rebuildBundle = bundle.needsBuild(); final bool rebuildBundle = bundle.needsBuild();
if (rebuildBundle) { if (rebuildBundle) {
Status bundleStatus = logger.startProgress('Updating assets...'); Status bundleStatus = logger.startProgress('Updating assets...');
...@@ -484,7 +490,14 @@ class HotRunner extends ResidentRunner { ...@@ -484,7 +490,14 @@ class HotRunner extends ResidentRunner {
} }
@override @override
Future<bool> restart() => _reloadSources(); Future<bool> restart({ bool fullRestart: false }) async {
if (fullRestart) {
await _restartFromSources();
return true;
} else {
return _reloadSources();
}
}
Future<bool> _reloadSources() async { Future<bool> _reloadSources() async {
if (serviceProtocol.firstIsolateId == null) if (serviceProtocol.firstIsolateId == null)
......
...@@ -32,12 +32,12 @@ abstract class ResidentRunner { ...@@ -32,12 +32,12 @@ abstract class ResidentRunner {
/// Start the app and keep the process running during its lifetime. /// Start the app and keep the process running during its lifetime.
Future<int> run({ Future<int> run({
Completer<int> observatoryPortCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}); });
Future<bool> restart(); Future<bool> restart({ bool fullRestart: false });
Future<Null> stop() async { Future<Null> stop() async {
await stopEchoingDeviceLog(); await stopEchoingDeviceLog();
...@@ -208,3 +208,10 @@ String getMissingPackageHintForPlatform(TargetPlatform platform) { ...@@ -208,3 +208,10 @@ String getMissingPackageHintForPlatform(TargetPlatform platform) {
return null; return null;
} }
} }
class DebugConnectionInfo {
DebugConnectionInfo(this.port, { this.baseUri });
final int port;
final String baseUri;
}
...@@ -39,7 +39,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -39,7 +39,7 @@ class RunAndStayResident extends ResidentRunner {
@override @override
Future<int> run({ Future<int> run({
Completer<int> observatoryPortCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) { }) {
...@@ -48,7 +48,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -48,7 +48,7 @@ class RunAndStayResident extends ResidentRunner {
return _run( return _run(
traceStartup: traceStartup, traceStartup: traceStartup,
benchmark: benchmark, benchmark: benchmark,
observatoryPortCompleter: observatoryPortCompleter, connectionInfoCompleter: connectionInfoCompleter,
route: route, route: route,
shouldBuild: shouldBuild shouldBuild: shouldBuild
); );
...@@ -58,7 +58,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -58,7 +58,7 @@ class RunAndStayResident extends ResidentRunner {
} }
@override @override
Future<bool> restart() async { Future<bool> restart({ bool fullRestart: false }) async {
if (serviceProtocol == null) { if (serviceProtocol == null) {
printError('Debugging is not enabled.'); printError('Debugging is not enabled.');
return false; return false;
...@@ -94,7 +94,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -94,7 +94,7 @@ class RunAndStayResident extends ResidentRunner {
Future<int> _run({ Future<int> _run({
bool traceStartup: false, bool traceStartup: false,
bool benchmark: false, bool benchmark: false,
Completer<int> observatoryPortCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) async { }) async {
...@@ -175,8 +175,8 @@ class RunAndStayResident extends ResidentRunner { ...@@ -175,8 +175,8 @@ class RunAndStayResident extends ResidentRunner {
startTime.stop(); startTime.stop();
if (observatoryPortCompleter != null && _result.hasObservatory) if (connectionInfoCompleter != null && _result.hasObservatory)
observatoryPortCompleter.complete(_result.observatoryPort); connectionInfoCompleter.complete(new DebugConnectionInfo(_result.observatoryPort));
// Connect to observatory. // Connect to observatory.
if (debuggingOptions.debuggingEnabled) { if (debuggingOptions.debuggingEnabled) {
......
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