[fuchsia] - remove device-finder for device discovery (#91502)

device-finder binary is being from removed from the Fuchsia SDK
in fxb/85985.
This commit is contained in:
omerlevran46
2021-10-13 16:04:27 -04:00
committed by GitHub
parent 92dd9d2358
commit 4b1b65118e
10 changed files with 23 additions and 438 deletions

View File

@@ -1,88 +0,0 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:file/file.dart';
import 'package:process/process.dart';
import '../base/common.dart';
import '../base/logger.dart';
import '../base/process.dart';
import 'fuchsia_sdk.dart';
// Usage: device-finder <flags> <subcommand> <subcommand args>
//
// Subcommands:
// commands list all command names
// flags describe all known top-level flags
// help describe subcommands and their syntax
// list lists all Fuchsia devices on the network
// resolve attempts to resolve all passed Fuchsia domain names on the
// network
/// A simple wrapper for the Fuchsia SDK's 'device-finder' tool.
class FuchsiaDevFinder {
FuchsiaDevFinder({
required FuchsiaArtifacts? fuchsiaArtifacts,
required Logger logger,
required ProcessManager processManager,
})
: _fuchsiaArtifacts = fuchsiaArtifacts,
_logger = logger,
_processUtils = ProcessUtils(logger: logger, processManager: processManager);
final FuchsiaArtifacts? _fuchsiaArtifacts;
final Logger _logger;
final ProcessUtils _processUtils;
/// Returns a list of attached devices as a list of strings with entries
/// formatted as follows:
///
/// 192.168.42.172 scare-cable-skip-joy
Future<List<String>?> list({ Duration? timeout }) async {
final File? devFinder = _fuchsiaArtifacts?.devFinder;
if (devFinder == null || !devFinder.existsSync()) {
throwToolExit('Fuchsia device-finder tool not found.');
}
final List<String> command = <String>[
devFinder.path,
'list',
'-full',
if (timeout != null)
...<String>['-timeout', '${timeout.inMilliseconds}ms']
];
final RunResult result = await _processUtils.run(command);
if (result.exitCode != 0) {
// No devices returns error code 1.
// https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=48563
if (!result.stderr.contains('no devices found')) {
_logger.printError('device-finder failed: ${result.stderr}');
}
return null;
}
return result.stdout.split('\n');
}
/// Returns the address of the named device.
///
/// The string [deviceName] should be the name of the device from the
/// 'list' command, e.g. 'scare-cable-skip-joy'.
Future<String?> resolve(String deviceName) async {
final File? devFinder = _fuchsiaArtifacts?.devFinder;
if (devFinder == null || !devFinder.existsSync()) {
throwToolExit('Fuchsia device-finder tool not found.');
}
final List<String> command = <String>[
devFinder.path,
'resolve',
'-device-limit', '1',
deviceName,
];
final RunResult result = await _processUtils.run(command);
if (result.exitCode != 0) {
_logger.printError('device-finder failed: ${result.stderr}');
return null;
}
return result.stdout.trim();
}
}

View File

@@ -191,7 +191,6 @@ class FuchsiaDevices extends PollingDeviceDiscovery {
// TODO(omerlevran): Remove once soft transition is complete fxb/67602.
final List<String> text = (await _fuchsiaSdk.listDevices(
timeout: timeout,
useDeviceFinder: _fuchsiaWorkflow.shouldUseDeviceFinder,
))?.split('\n');
if (text == null || text.isEmpty) {
return <Device>[];
@@ -218,18 +217,9 @@ class FuchsiaDevices extends PollingDeviceDiscovery {
return null;
}
final String name = words[1];
String resolvedHost;
// TODO(omerlevran): Remove once soft transition is complete fxb/67602.
if (_fuchsiaWorkflow.shouldUseDeviceFinder) {
// TODO(omerlevran): Add support for resolve on the FuchsiaSdk Object.
resolvedHost = await _fuchsiaSdk.fuchsiaDevFinder.resolve(
name,
);
} else {
// TODO(omerlevran): Add support for resolve on the FuchsiaSdk Object.
resolvedHost = await _fuchsiaSdk.fuchsiaFfx.resolve(name);
}
// TODO(omerlevran): Add support for resolve on the FuchsiaSdk Object.
final String resolvedHost = await _fuchsiaSdk.fuchsiaFfx.resolve(name);
if (resolvedHost == null) {
_logger.printError('Failed to resolve host for Fuchsia device `$name`');
return null;

View File

@@ -87,7 +87,7 @@ class FuchsiaPM {
///
/// The argument [repoPath] should have previously been an argument to
/// [newrepo]. The [host] should be the host reported by
/// [FuchsiaDevFinder.resolve] or [FuchsiaFfx.resolve] and [port] should be an unused port for the
/// [FuchsiaFfx.resolve], and [port] should be an unused port for the
/// http server to bind.
Future<Process> serve(String repoPath, String host, int port) async {
final File? pm = globals.fuchsiaArtifacts?.pm;
@@ -157,7 +157,7 @@ class FuchsiaPM {
/// var server = FuchsiaPackageServer(
/// '/path/to/repo',
/// 'server_name',
/// await FuchsiaDevFinder.resolve(deviceName),
/// await FuchsiaFfx.resolve(deviceName),
/// await freshPort());
/// try {
/// await server.start();

View File

@@ -11,7 +11,6 @@ import '../base/platform.dart';
import '../convert.dart';
import '../globals_null_migrated.dart' as globals;
import 'fuchsia_dev_finder.dart';
import 'fuchsia_ffx.dart';
import 'fuchsia_kernel_compiler.dart';
import 'fuchsia_pm.dart';
@@ -32,13 +31,6 @@ class FuchsiaSdk {
/// Interface to the 'pm' tool.
late final FuchsiaPM fuchsiaPM = FuchsiaPM();
/// Interface to the 'device-finder' tool.
late final FuchsiaDevFinder fuchsiaDevFinder = FuchsiaDevFinder(
fuchsiaArtifacts: globals.fuchsiaArtifacts,
logger: globals.logger,
processManager: globals.processManager
);
/// Interface to the 'kernel_compiler' tool.
late final FuchsiaKernelCompiler fuchsiaKernelCompiler = FuchsiaKernelCompiler();
@@ -52,21 +44,12 @@ class FuchsiaSdk {
/// Returns any attached devices is a newline-denominated String.
///
/// Example output: abcd::abcd:abc:abcd:abcd%qemu scare-cable-skip-joy
Future<String?> listDevices({Duration? timeout, bool useDeviceFinder = false}) async {
List<String>? devices;
if (useDeviceFinder) {
final File? devFinder = globals.fuchsiaArtifacts?.devFinder;
if (devFinder == null || !devFinder.existsSync()) {
return null;
}
devices = await fuchsiaDevFinder.list(timeout: timeout);
} else {
final File? ffx = globals.fuchsiaArtifacts?.ffx;
if (ffx == null || !ffx.existsSync()) {
return null;
}
devices = await fuchsiaFfx.list(timeout: timeout);
Future<String?> listDevices({Duration? timeout}) async {
final File? ffx = globals.fuchsiaArtifacts?.ffx;
if (ffx == null || !ffx.existsSync()) {
return null;
}
final List<String>? devices = await fuchsiaFfx.list(timeout: timeout);
if (devices == null) {
return null;
}
@@ -118,7 +101,6 @@ class FuchsiaArtifacts {
/// Creates a new [FuchsiaArtifacts].
FuchsiaArtifacts({
this.sshConfig,
this.devFinder,
this.ffx,
this.pm,
});
@@ -147,13 +129,11 @@ class FuchsiaArtifacts {
final String fuchsia = globals.cache.getArtifactDirectory('fuchsia').path;
final String tools = globals.fs.path.join(fuchsia, 'tools');
final File devFinder = globals.fs.file(globals.fs.path.join(tools, 'device-finder'));
final File ffx = globals.fs.file(globals.fs.path.join(tools, 'x64/ffx'));
final File pm = globals.fs.file(globals.fs.path.join(tools, 'pm'));
return FuchsiaArtifacts(
sshConfig: sshConfig,
devFinder: devFinder.existsSync() ? devFinder : null,
ffx: ffx.existsSync() ? ffx : null,
pm: pm.existsSync() ? pm : null,
);
@@ -166,10 +146,6 @@ class FuchsiaArtifacts {
/// Fuchsia device.
final File? sshConfig;
/// The location of the dev finder tool used to locate connected
/// Fuchsia devices.
final File? devFinder;
/// The location of the ffx tool used to locate connected
/// Fuchsia devices.
final File? ffx;

View File

@@ -31,28 +31,13 @@ class FuchsiaWorkflow implements Workflow {
@override
bool get appliesToHostPlatform => _featureFlags.isFuchsiaEnabled && (_platform.isLinux || _platform.isMacOS);
bool get shouldUseDeviceFinder {
final String? useDeviceFinder = _platform.environment.containsKey('FUCHSIA_DISABLED_ffx_discovery')
? _platform.environment['FUCHSIA_DISABLED_ffx_discovery'] : '0';
if (useDeviceFinder == '1') {
return true;
}
return false;
}
@override
bool get canListDevices {
if (shouldUseDeviceFinder) {
return _fuchsiaArtifacts.devFinder != null;
}
return _fuchsiaArtifacts.ffx != null;
}
@override
bool get canLaunchDevices {
if (shouldUseDeviceFinder) {
return _fuchsiaArtifacts.devFinder != null && _fuchsiaArtifacts.sshConfig != null;
}
return _fuchsiaArtifacts.ffx != null && _fuchsiaArtifacts.sshConfig != null;
}