in flutter run, throw tool exit when --flavor is provided but is not supported on the target device (#139045)

Fixes https://github.com/flutter/flutter/issues/134197
This commit is contained in:
Andrew Kolos
2024-01-05 13:47:58 -08:00
committed by GitHub
parent 8c11aa030d
commit e90e4888b8
13 changed files with 93 additions and 5 deletions

View File

@@ -372,6 +372,9 @@ class AndroidDevice extends Device {
@override
String get name => modelID;
@override
bool get supportsFlavors => true;
@override
Future<bool> isAppInstalled(
ApplicationPackage app, {

View File

@@ -610,6 +610,13 @@ class RunCommand extends RunCommandBase {
webMode = featureFlags.isWebEnabled &&
devices!.length == 1 &&
await devices!.single.targetPlatform == TargetPlatform.web_javascript;
final String? flavor = stringArg('flavor');
final bool flavorsSupportedOnEveryDevice = devices!
.every((Device device) => device.supportsFlavors);
if (flavor != null && !flavorsSupportedOnEveryDevice) {
throwToolExit('--flavor is only supported for Android, macOS, and iOS devices.');
}
}
@visibleForTesting

View File

@@ -469,6 +469,10 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
' sdk: flutter\n',
);
}
if (stringArg('flavor') != null && !integrationTestDevice.supportsFlavors) {
throwToolExit('--flavor is only supported for Android, macOS, and iOS devices.');
}
}
final Stopwatch? testRunnerTimeRecorderStopwatch = testTimeRecorder?.start(TestTimePhases.TestRunner);

View File

@@ -758,6 +758,9 @@ abstract class Device {
/// Whether the device supports the '--fast-start' development mode.
bool get supportsFastStart => false;
/// Whether the Flavors feature ('--flavor') is supported for this device.
bool get supportsFlavors => false;
/// Stop an app package on the current device.
///
/// Specify [userIdentifier] to stop app installed to a profile (Android only).

View File

@@ -358,6 +358,9 @@ class IOSDevice extends Device {
@override
bool get supportsStartPaused => false;
@override
bool get supportsFlavors => true;
@override
Future<bool> isAppInstalled(
ApplicationPackage app, {

View File

@@ -392,6 +392,9 @@ class IOSSimulator extends Device {
@override
bool get supportsHotRestart => true;
@override
bool get supportsFlavors => true;
@override
Future<bool> get supportsHardwareRendering async => false;

View File

@@ -47,6 +47,9 @@ class MacOSDevice extends DesktopDevice {
@override
String get name => 'macOS';
@override
bool get supportsFlavors => true;
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.darwin;

View File

@@ -48,6 +48,9 @@ class MacOSDesignedForIPadDevice extends DesktopDevice {
@override
bool isSupported() => _operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm64;
@override
bool get supportsFlavors => true;
@override
bool isSupportedForProject(FlutterProject flutterProject) {
return flutterProject.ios.existsSync() && _operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm64;

View File

@@ -90,6 +90,9 @@ class FlutterTesterDevice extends Device {
@override
bool supportsRuntimeMode(BuildMode buildMode) => buildMode == BuildMode.debug;
@override
bool get supportsFlavors => true;
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.tester;