From 985ccb6d14c6ce5ce74823a4d366df2438eac44f Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 8 Jan 2019 13:45:55 -0800 Subject: [PATCH] Revert "Replace netls and netaddr with dev_finder" (#26249) * Revert "Replace netls and netaddr with dev_finder (#26090)" This reverts commit eee154affbce8a4d69ee4dbfed332edc7550d264. --- .../flutter_tools/bin/fuchsia_attach.dart | 3 +- .../lib/src/fuchsia/fuchsia_device.dart | 26 +++++--- .../lib/src/fuchsia/fuchsia_sdk.dart | 61 ++++++++++--------- .../test/fuchsia/fuchsa_device_test.dart | 9 ++- 4 files changed, 56 insertions(+), 43 deletions(-) diff --git a/packages/flutter_tools/bin/fuchsia_attach.dart b/packages/flutter_tools/bin/fuchsia_attach.dart index 0180b73f92..71c0d9f613 100644 --- a/packages/flutter_tools/bin/fuchsia_attach.dart +++ b/packages/flutter_tools/bin/fuchsia_attach.dart @@ -41,7 +41,6 @@ Future main(List args) async { final String buildDirectory = argResults['build-dir']; final File frontendServer = fs.file('$buildDirectory/host_x64/gen/third_party/flutter/frontend_server/frontend_server_tool.snapshot'); final File sshConfig = fs.file('$buildDirectory/ssh-keys/ssh_config'); - final File devFinder = fs.file('$buildDirectory/host_x64/dev_finder'); final File platformKernelDill = fs.file('$buildDirectory/flutter_runner_patched_sdk/platform_strong.dill'); final File flutterPatchedSdk = fs.file('$buildDirectory/flutter_runner_patched_sdk'); final String packages = '$buildDirectory/dartlang/gen/$path/${name}_dart_library.packages'; @@ -92,7 +91,7 @@ Future main(List args) async { muteCommandLogging: false, verboseHelp: false, overrides: { - FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig, devFinder: devFinder), + FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig), Artifacts: () => OverrideArtifacts( parent: CachedArtifacts(), frontendServer: frontendServer, diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart index ed48b22fe5..be89010182 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_device.dart @@ -108,8 +108,12 @@ class FuchsiaDevices extends PollingDeviceDiscovery { if (!fuchsiaWorkflow.canListDevices) { return []; } - final String text = await fuchsiaSdk.listDevices(); - final List devices = parseListDevices(text); + final String text = await fuchsiaSdk.netls(); + final List devices = []; + for (String name in parseFuchsiaDeviceOutput(text)) { + final String id = await fuchsiaSdk.netaddr(); + devices.add(FuchsiaDevice(id, name: name)); + } return devices; } @@ -117,18 +121,24 @@ class FuchsiaDevices extends PollingDeviceDiscovery { Future> getDiagnostics() async => const []; } +/// Parses output from the netls tool into fuchsia devices names. +/// +/// Example output: +/// $ ./netls +/// > device liliac-shore-only-last (fe80::82e4:da4d:fe81:227d/3) @visibleForTesting -List parseListDevices(String text) { - final List devices = []; +List parseFuchsiaDeviceOutput(String text) { + final List names = []; for (String rawLine in text.trim().split('\n')) { final String line = rawLine.trim(); - // ['ip', 'device name'] + if (!line.startsWith('device')) + continue; + // ['device', 'device name', '(id)'] final List words = line.split(' '); final String name = words[1]; - final String id = words[0]; - devices.add(FuchsiaDevice(id, name: name)); + names.add(name); } - return devices; + return names; } class FuchsiaDevice extends Device { diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_sdk.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_sdk.dart index a9f95a60a2..63f91e136a 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_sdk.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_sdk.dart @@ -24,15 +24,21 @@ FuchsiaArtifacts get fuchsiaArtifacts => context[FuchsiaArtifacts]; /// This workflow assumes development within the fuchsia source tree, /// including a working fx command-line tool in the user's PATH. class FuchsiaSdk { + static const List _netaddrCommand = ['fx', 'netaddr', '--fuchsia', '--nowait']; + static const List _netlsCommand = ['fx', 'netls', '--nowait']; static const List _syslogCommand = ['fx', 'syslog', '--clock', 'Local']; + /// Invokes the `netaddr` command. + /// + /// This returns the network address of an attached fuchsia device. Does + /// not currently support multiple attached devices. + /// /// Example output: - /// $ dev_finder list -full - /// > 192.168.42.56 paper-pulp-bush-angel - Future listDevices() async { + /// $ fx netaddr --fuchsia --nowait + /// > fe80::9aaa:fcff:fe60:d3af%eth1 + Future netaddr() async { try { - final String path = fuchsiaArtifacts.devFinder.absolute.path; - final RunResult process = await runAsync([path, 'list', '-full']); + final RunResult process = await runAsync(_netaddrCommand); return process.stdout.trim(); } on ArgumentError catch (exception) { throwToolExit('$exception'); @@ -63,19 +69,36 @@ class FuchsiaSdk { } return null; } + + /// Invokes the `netls` command. + /// + /// This lists attached fuchsia devices with their name and address. Does + /// not currently support multiple attached devices. + /// + /// Example output: + /// $ fx netls --nowait + /// > device liliac-shore-only-last (fe80::82e4:da4d:fe81:227d/3) + Future netls() async { + try { + final RunResult process = await runAsync(_netlsCommand); + return process.stdout; + } on ArgumentError catch (exception) { + throwToolExit('$exception'); + } + return null; + } } /// Fuchsia-specific artifacts used to interact with a device. class FuchsiaArtifacts { /// Creates a new [FuchsiaArtifacts]. /// - /// May optionally provide a file `sshConfig` file and `devFinder` file. - FuchsiaArtifacts({File sshConfig, File devFinder}) - : _sshConfig = sshConfig, - _devFinder = devFinder; + /// May optionally provide a file `sshConfig` file. + FuchsiaArtifacts({File sshConfig}) + : _sshConfig = sshConfig; /// The location of the SSH configuration file used to interact with a - /// Fuchsia device. + /// fuchsia device. /// /// Requires the env variable `BUILD_DIR` to be set if not provided by /// the constructor. @@ -91,22 +114,4 @@ class FuchsiaArtifacts { return _sshConfig; } File _sshConfig; - - /// The location of the dev finder tool used to locate connected - /// Fuchsia devices. - /// - /// Requires the env variable `BUILD_DIR` to be set if not provided by - /// the constructor. - File get devFinder { - if (_devFinder == null) { - final String buildDirectory = platform.environment['BUILD_DIR']; - if (buildDirectory == null) { - throwToolExit('BUILD_DIR must be supplied to dev_finder. For example:\n' - ' export BUILD_DIR=path/to/fuchsia/out/x64\n'); - } - _devFinder = fs.file('$buildDirectory/host_x64/dev_finder'); - } - return _devFinder; - } - File _devFinder; } diff --git a/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart b/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart index db1ce5023f..fb192f0a4e 100644 --- a/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart +++ b/packages/flutter_tools/test/fuchsia/fuchsa_device_test.dart @@ -29,13 +29,12 @@ void main() { expect(device.name, name); }); - test('parse dev_finder output', () { - const String example = '192.168.42.56 paper-pulp-bush-angel'; - final List names = parseListDevices(example); + test('parse netls log output', () { + const String example = 'device lilia-shore-only-last (fe80::0000:a00a:f00f:2002/3)'; + final List names = parseFuchsiaDeviceOutput(example); expect(names.length, 1); - expect(names.first.name, 'paper-pulp-bush-angel'); - expect(names.first.id, '192.168.42.56'); + expect(names.first, 'lilia-shore-only-last'); }); test('default capabilities', () async {