diff --git a/packages/flutter_driver/lib/src/common/fuchsia_compat.dart b/packages/flutter_driver/lib/src/common/fuchsia_compat.dart index f84cb5a733..a406b2d671 100644 --- a/packages/flutter_driver/lib/src/common/fuchsia_compat.dart +++ b/packages/flutter_driver/lib/src/common/fuchsia_compat.dart @@ -13,9 +13,6 @@ import 'package:fuchsia_remote_debug_protocol/fuchsia_remote_debug_protocol.dart import 'error.dart'; -// TODO(awdavies): Update this to use the hub. -final Directory _kDartPortDir = Directory('/tmp/dart.services'); - class _DummyPortForwarder implements PortForwarder { _DummyPortForwarder(this._port, this._remotePort); @@ -49,13 +46,13 @@ class _DummySshCommandRunner implements SshCommandRunner { @override Future> run(String command) async { try { - return List.of(_kDartPortDir - .listSync(recursive: false, followLinks: false) - .map((FileSystemEntity entity) => entity.path - .replaceAll(entity.parent.path, '') - .replaceFirst(Platform.pathSeparator, ''))); - } on FileSystemException catch (e) { - _log.warning('Error listing directory: $e'); + final List splitCommand = command.split(' '); + final String exe = splitCommand[0]; + final List args = splitCommand.skip(1).toList(); + final ProcessResult r = Process.runSync(exe, args); + return r.stdout.split('\n'); + } on ProcessException catch (e) { + _log.warning("Error running '$command': $e"); } return []; } diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart index 57189a8e39..2b6d3b8523 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart @@ -216,8 +216,28 @@ class FuchsiaDevice extends Device { /// List the ports currently running a dart observatory. Future> servicePorts() async { - final String lsOutput = await shell('ls /tmp/dart.services'); - return parseFuchsiaDartPortOutput(lsOutput); + final String findOutput = await shell('find /hub -name vmservice-port'); + if (findOutput.trim() == '') { + throwToolExit('No Dart Observatories found. Are you running a debug build?'); + return null; + } + final List ports = []; + for (String path in findOutput.split('\n')) { + if (path == '') { + continue; + } + final String lsOutput = await shell('ls $path'); + for (String line in lsOutput.split('\n')) { + if (line == '') { + continue; + } + final int port = int.tryParse(line); + if (port != null) { + ports.add(port); + } + } + } + return ports; } /// Run `command` on the Fuchsia device shell. @@ -225,9 +245,6 @@ class FuchsiaDevice extends Device { final RunResult result = await runAsync([ 'ssh', '-F', fuchsiaArtifacts.sshConfig.absolute.path, id, command]); if (result.exitCode != 0) { - if (result.stderr.contains('/tmp/dart.services: No such file or directory')) { - throwToolExit('No Dart Observatories found. Are you running a debug build?'); - } throwToolExit('Command failed: $command\nstdout: ${result.stdout}\nstderr: ${result.stderr}'); return null; } @@ -336,28 +353,3 @@ class FuchsiaModulePackage extends ApplicationPackage { @override final String name; } - -/// Parses output from `dart.services` output on a fuchsia device. -/// -/// Example output: -/// $ ls /tmp/dart.services -/// > d 2 0 . -/// > - 1 0 36780 -@visibleForTesting -List parseFuchsiaDartPortOutput(String text) { - final List ports = []; - if (text == null) - return ports; - for (String line in text.split('\n')) { - final String trimmed = line.trim(); - final int lastSpace = trimmed.lastIndexOf(' '); - final String lastWord = trimmed.substring(lastSpace + 1); - if ((lastWord != '.') && (lastWord != '..')) { - final int value = int.tryParse(lastWord); - if (value != null) { - ports.add(value); - } - } - } - return ports; -} diff --git a/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart b/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart index 41683698d0..2ec75f93e6 100644 --- a/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart +++ b/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart @@ -36,16 +36,6 @@ void main() { expect(names.length, 1); expect(names.first, 'lilia-shore-only-last'); }); - - test('parse ls tmp/dart.servies output', () { - const String example = ''' -d 2 0 . -'- 1 0 36780 -'''; - final List ports = parseFuchsiaDartPortOutput(example); - expect(ports.length, 1); - expect(ports.single, 36780); - }); }); group('displays friendly error when', () { @@ -60,7 +50,7 @@ d 2 0 . )).thenAnswer((Invocation invocation) => Future.value(mockProcessResult)); when(mockProcessResult.exitCode).thenReturn(1); when(mockProcessResult.stdout).thenReturn(''); - when(mockProcessResult.stderr).thenReturn('ls: lstat /tmp/dart.services: No such file or directory'); + when(mockProcessResult.stderr).thenReturn(''); when(mockFuchsiaArtifacts.sshConfig).thenReturn(mockFile); when(mockFile.absolute).thenReturn(mockFile); when(mockFile.path).thenReturn(''); @@ -78,7 +68,18 @@ d 2 0 . ProcessManager: () => mockProcessManager, }); - testUsingContext('with BUILD_DIR set', () async { + final MockProcessManager emptyStdoutProcessManager = MockProcessManager(); + final MockProcessResult emptyStdoutProcessResult = MockProcessResult(); + when(emptyStdoutProcessManager.run( + any, + environment: anyNamed('environment'), + workingDirectory: anyNamed('workingDirectory'), + )).thenAnswer((Invocation invocation) => Future.value(emptyStdoutProcessResult)); + when(emptyStdoutProcessResult.exitCode).thenReturn(0); + when(emptyStdoutProcessResult.stdout).thenReturn(''); + when(emptyStdoutProcessResult.stderr).thenReturn(''); + + testUsingContext('No vmservices found', () async { final FuchsiaDevice device = FuchsiaDevice('id'); ToolExit toolExit; try { @@ -86,9 +87,9 @@ d 2 0 . } on ToolExit catch (err) { toolExit = err; } - expect(toolExit.message, 'No Dart Observatories found. Are you running a debug build?'); + expect(toolExit.message, contains('No Dart Observatories found. Are you running a debug build?')); }, overrides: { - ProcessManager: () => mockProcessManager, + ProcessManager: () => emptyStdoutProcessManager, FuchsiaArtifacts: () => mockFuchsiaArtifacts, }); diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart b/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart index 2c34a78466..91a8a0349f 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/fuchsia_remote_connection.dart @@ -523,24 +523,21 @@ class FuchsiaRemoteConnection { /// found. An exception is thrown in the event of an actual error when /// attempting to acquire the ports. Future> getDeviceServicePorts() async { - // TODO(awdavies): This is using a temporary workaround rather than a - // well-defined service, and will be deprecated in the near future. - final List lsOutput = - await _sshCommandRunner.run('ls /tmp/dart.services'); + final List portPaths = + await _sshCommandRunner.run('find /hub -name vmservice-port'); final List ports = []; - - // The output of lsOutput is a list of available ports as the Fuchsia dart - // service advertises. An example lsOutput would look like: - // - // [ '31782\n', '1234\n', '11967' ] - for (String s in lsOutput) { - final String trimmed = s.trim(); - final int lastSpace = trimmed.lastIndexOf(' '); - final String lastWord = trimmed.substring(lastSpace + 1); - if ((lastWord != '.') && (lastWord != '..')) { - final int value = int.tryParse(lastWord); - if (value != null) { - ports.add(value); + for (String path in portPaths) { + if (path == '') { + continue; + } + final List lsOutput = await _sshCommandRunner.run('ls $path'); + for (String line in lsOutput) { + if (line == '') { + continue; + } + final int port = int.tryParse(line); + if (port != null) { + ports.add(port); } } } diff --git a/packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart b/packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart index dc62fdf894..1d13e077d1 100644 --- a/packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart +++ b/packages/fuchsia_remote_debug_protocol/test/fuchsia_remote_connection_test.dart @@ -21,7 +21,9 @@ void main() { setUp(() { mockRunner = MockSshCommandRunner(); // Adds some extra junk to make sure the strings will be cleaned up. - when(mockRunner.run(any)).thenAnswer((_) => + when(mockRunner.run(argThat(startsWith('find')))).thenAnswer((_) => + Future>.value(['/hub/blah/blah/blah/vmservice-port\n'])); + when(mockRunner.run(argThat(startsWith('ls')))).thenAnswer((_) => Future>.value(['123\n\n\n', '456 ', '789'])); const String address = 'fe80::8eae:4cff:fef4:9247'; const String interface = 'eno1';