Add runDebug for remote devices (#26)

This commit is contained in:
Hidenori Matsubayashi
2021-07-28 14:15:35 +09:00
committed by GitHub
parent 29eb6f6c21
commit 09f57d9082
+60 -4
View File
@@ -85,8 +85,9 @@ class ELinuxDevice extends Device {
} }
@override @override
bool supportsRuntimeMode(BuildMode buildMode) => bool supportsRuntimeMode(BuildMode buildMode) => _desktop
buildMode != BuildMode.jitRelease; ? buildMode != BuildMode.jitRelease
: buildMode == BuildMode.debug;
@override @override
Future<String> get sdkNameAndVersion async => Future<String> get sdkNameAndVersion async =>
@@ -136,6 +137,36 @@ class ELinuxDevice extends Device {
bool ipv6 = false, bool ipv6 = false,
String userIdentifier, String userIdentifier,
}) async { }) async {
if (!_desktop) {
if (!await installApp(package)) {
return LaunchResult.failed();
}
final List<String> interpolated = interpolateCommand(
_config.runDebugCommand,
<String, String>{'remotePath': '/tmp/', 'appName': package.name});
_logger.printStatus('Launch $package.name on ${_config.id}');
final Process process = await _processManager.start(interpolated);
final ProtocolDiscovery discovery = ProtocolDiscovery.observatory(
_logReader,
portForwarder: null,
hostPort: null,
devicePort: null,
logger: _logger,
ipv6: ipv6,
);
_logReader.initializeProcess(process);
final Uri observatoryUri = await discovery.uri;
await discovery.cancel();
return LaunchResult.succeeded(observatoryUri: observatoryUri);
}
// Target is desktop hosts from here.
if (!prebuiltApplication) { if (!prebuiltApplication) {
_logger.printTrace('Building app'); _logger.printTrace('Building app');
await buildForDevice( await buildForDevice(
@@ -367,9 +398,10 @@ class ELinuxDevice extends Device {
additionalReplacementValues: additionalReplacementValues); additionalReplacementValues: additionalReplacementValues);
try { try {
_logger.printStatus('Uninstall $appName from ${_config.id}.');
await _processUtils.run(interpolated, await _processUtils.run(interpolated,
throwOnError: true, timeout: timeout); throwOnError: true, timeout: timeout);
_logger.printStatus('Uninstallation Success: $appName'); _logger.printStatus('Uninstallation Success');
return true; return true;
} on ProcessException catch (e) { } on ProcessException catch (e) {
_logger.printError( _logger.printError(
@@ -390,9 +422,10 @@ class ELinuxDevice extends Device {
additionalReplacementValues: additionalReplacementValues); additionalReplacementValues: additionalReplacementValues);
try { try {
_logger.printStatus('Install $appName ($localPath) to ${_config.id}');
await _processUtils.run(interpolated, await _processUtils.run(interpolated,
throwOnError: true, timeout: timeout); throwOnError: true, timeout: timeout);
_logger.printStatus('Installation Success: $appName ($localPath)'); _logger.printStatus('Installation Success');
return true; return true;
} on ProcessException catch (e) { } on ProcessException catch (e) {
_logger.printError( _logger.printError(
@@ -400,6 +433,29 @@ class ELinuxDevice extends Device {
return false; return false;
} }
} }
Future<bool> tryRunDebug(
{@required String appName,
Duration timeout,
Map<String, String> additionalReplacementValues =
const <String, String>{}}) async {
final List<String> interpolated = interpolateCommand(
_config.runDebugCommand,
<String, String>{'remotePath': '/tmp/', 'appName': appName},
additionalReplacementValues: additionalReplacementValues);
try {
_logger.printStatus('Launch $appName on ${_config.id}');
await _processUtils.run(interpolated,
throwOnError: true, timeout: timeout);
_logger.printStatus('Running $appName...');
return true;
} on ProcessException catch (e) {
_logger.printError(
'Error executing runDebug command for custom device $id: $e');
return false;
}
}
} }
class ELinuxLogReader extends DeviceLogReader { class ELinuxLogReader extends DeviceLogReader {