Remove web, fuchsia, and unsupported devices from all (#35709)
This commit is contained in:
parent
34e18d38ce
commit
1e26c41f17
@ -169,17 +169,49 @@ class DeviceManager {
|
|||||||
|
|
||||||
/// Find and return a list of devices based on the current project and environment.
|
/// Find and return a list of devices based on the current project and environment.
|
||||||
///
|
///
|
||||||
/// Returns a list of deviecs specified by the user. If the user has not specified
|
/// Returns a list of deviecs specified by the user.
|
||||||
/// all devices and has multiple connected then filter the list by those supported
|
///
|
||||||
/// in the current project and remove non-ephemeral device types.
|
/// * If the user specified '-d all', then return all connected devices which
|
||||||
|
/// support the current project, except for fuchsia and web.
|
||||||
|
///
|
||||||
|
/// * If the user specified a device id, then do nothing as the list is already
|
||||||
|
/// filtered by [getDevices].
|
||||||
|
///
|
||||||
|
/// * If the user did not specify a device id and there is more than one
|
||||||
|
/// device connected, then filter out unsupported devices and prioritize
|
||||||
|
/// ephemeral devices.
|
||||||
Future<List<Device>> findTargetDevices(FlutterProject flutterProject) async {
|
Future<List<Device>> findTargetDevices(FlutterProject flutterProject) async {
|
||||||
List<Device> devices = await getDevices().toList();
|
List<Device> devices = await getDevices().toList();
|
||||||
|
|
||||||
if (devices.length > 1 && !deviceManager.hasSpecifiedAllDevices && !deviceManager.hasSpecifiedDeviceId) {
|
// Always remove web and fuchsia devices from `--all`. This setting
|
||||||
devices = devices
|
// currently requires devices to share a frontend_server and resident
|
||||||
.where((Device device) => isDeviceSupportedForProject(device, flutterProject))
|
// runnner instance. Both web and fuchsia require differently configured
|
||||||
.toList();
|
// compilers, and web requires an entirely different resident runner.
|
||||||
|
if (hasSpecifiedAllDevices) {
|
||||||
|
devices = <Device>[
|
||||||
|
for (Device device in devices)
|
||||||
|
if (await device.targetPlatform != TargetPlatform.fuchsia &&
|
||||||
|
await device.targetPlatform != TargetPlatform.web_javascript)
|
||||||
|
device
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is no specified device, the remove all devices which are not
|
||||||
|
// supported by the current application. For example, if there was no
|
||||||
|
// 'android' folder then don't attempt to launch with an Android device.
|
||||||
|
if (devices.length > 1 && !hasSpecifiedDeviceId) {
|
||||||
|
devices = <Device>[
|
||||||
|
for (Device device in devices)
|
||||||
|
if (device.isSupportedForProject(flutterProject))
|
||||||
|
device
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are still multiple devices and the user did not specify to run
|
||||||
|
// all, then attempt to prioritize ephemeral devices. For example, if the
|
||||||
|
// use only typed 'flutter run' and both an Android device and desktop
|
||||||
|
// device are availible, choose the Android device.
|
||||||
|
if (devices.length > 1 && !hasSpecifiedAllDevices) {
|
||||||
// Note: ephemeral is nullable for device types where this is not well
|
// Note: ephemeral is nullable for device types where this is not well
|
||||||
// defined.
|
// defined.
|
||||||
if (devices.any((Device device) => device.ephemeral == true)) {
|
if (devices.any((Device device) => device.ephemeral == true)) {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter_tools/src/build_info.dart';
|
||||||
import 'package:flutter_tools/src/device.dart';
|
import 'package:flutter_tools/src/device.dart';
|
||||||
import 'package:flutter_tools/src/project.dart';
|
import 'package:flutter_tools/src/project.dart';
|
||||||
|
|
||||||
@ -43,12 +44,18 @@ void main() {
|
|||||||
_MockDevice nonEphemeralOne;
|
_MockDevice nonEphemeralOne;
|
||||||
_MockDevice nonEphemeralTwo;
|
_MockDevice nonEphemeralTwo;
|
||||||
_MockDevice unsupported;
|
_MockDevice unsupported;
|
||||||
|
_MockDevice webDevice;
|
||||||
|
_MockDevice fuchsiaDevice;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
ephemeral = _MockDevice('ephemeral', 'ephemeral', true);
|
ephemeral = _MockDevice('ephemeral', 'ephemeral', true);
|
||||||
nonEphemeralOne = _MockDevice('nonEphemeralOne', 'nonEphemeralOne', false);
|
nonEphemeralOne = _MockDevice('nonEphemeralOne', 'nonEphemeralOne', false);
|
||||||
nonEphemeralTwo = _MockDevice('nonEphemeralTwo', 'nonEphemeralTwo', false);
|
nonEphemeralTwo = _MockDevice('nonEphemeralTwo', 'nonEphemeralTwo', false);
|
||||||
unsupported = _MockDevice('unsupported', 'unsupported', true, false);
|
unsupported = _MockDevice('unsupported', 'unsupported', true, false);
|
||||||
|
webDevice = _MockDevice('webby', 'webby')
|
||||||
|
..targetPlatform = Future<TargetPlatform>.value(TargetPlatform.web_javascript);
|
||||||
|
fuchsiaDevice = _MockDevice('fuchsiay', 'fuchsiay')
|
||||||
|
..targetPlatform = Future<TargetPlatform>.value(TargetPlatform.fuchsia);
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('chooses ephemeral device', () async {
|
testUsingContext('chooses ephemeral device', () async {
|
||||||
@ -79,6 +86,36 @@ void main() {
|
|||||||
nonEphemeralTwo,
|
nonEphemeralTwo,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('Removes web and fuchsia from --all', () async {
|
||||||
|
final List<Device> devices = <Device>[
|
||||||
|
webDevice,
|
||||||
|
fuchsiaDevice,
|
||||||
|
];
|
||||||
|
final DeviceManager deviceManager = TestDeviceManager(devices);
|
||||||
|
deviceManager.specifiedDeviceId = 'all';
|
||||||
|
|
||||||
|
final List<Device> filtered = await deviceManager.findTargetDevices(FlutterProject.current());
|
||||||
|
|
||||||
|
expect(filtered, <Device>[]);
|
||||||
|
});
|
||||||
|
|
||||||
|
testUsingContext('Removes unsupported devices from --all', () async {
|
||||||
|
final List<Device> devices = <Device>[
|
||||||
|
nonEphemeralOne,
|
||||||
|
nonEphemeralTwo,
|
||||||
|
unsupported,
|
||||||
|
];
|
||||||
|
final DeviceManager deviceManager = TestDeviceManager(devices);
|
||||||
|
deviceManager.specifiedDeviceId = 'all';
|
||||||
|
|
||||||
|
final List<Device> filtered = await deviceManager.findTargetDevices(FlutterProject.current());
|
||||||
|
|
||||||
|
expect(filtered, <Device>[
|
||||||
|
nonEphemeralOne,
|
||||||
|
nonEphemeralTwo,
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +143,9 @@ class _MockDevice extends Device {
|
|||||||
@override
|
@override
|
||||||
final String name;
|
final String name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<TargetPlatform> targetPlatform = Future<TargetPlatform>.value(TargetPlatform.android_arm);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
void noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user