Skip to content

Commit abb292a

Browse files
[CP-stable]instead of exiting the tool, print a warning when using --flavor with an incompatible device (flutter#143785)
**This pull request is opened against a release branch.<br> To request a cherry pick of a commit, please fill in the form below.** (Questions with an asterisk are required.)<br> **To fill in the form, you can edit this PR description and type your answers after the 'My Answer' keywords. <br> A flutter domain expert will evaluate this cherry pick request shortly after ALL questions are answered.** * Issue Link: What is the link to the issue this cherry-pick is addressing?<br> <pre> <b>My Answer:</b> flutter#143574 </pre> * Changelog Description: Explain this cherry pick in one line that is accessible to most Flutter developers See https://github.com/flutter/flutter/wiki/Hotfix-Documentation-Best-Practices for examples (Bug fix, feature, docs update, ...)<br> <pre> <b>My Answer:</b> Instead of exiting, the `flutter` CLI tool now prints a warning when the `--flavor` option is used with a target platform that doesn't have flavors support. </pre> * impact_description: What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch)<br> <pre> <b>My Answer:</b> All Flutter devs using the Flavors feature that use their IDE to select a target device. </pre> * Workaround: Is there a workaround for this issue?<br> <pre> <b>My Answer:</b> Users can create duplicate debug launch configurations for target platforms that do not support the flavors feature. </pre> * Risk: What is the risk level of this cherry-pick?<br> <pre> <b>My Answer:</b> </pre> * Test Coverage: Are you confident that your fix is well-tested by automated tests?<br> <pre> <b>My Answer:</b> </pre> * Validation Steps: What are the steps to validate that this fix works?<br> <pre> <b>My Answer:</b> Set up a flutter project and configure at least one flavor for it. In VSCode, create a launch configuration that uses `--flavor` to select the flavor you configured (see flutter#143574 (comment) for an example). In VSCode, select chrome as the target device and try running the application using the configured launch configuration. </pre>
1 parent bae5e49 commit abb292a

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

packages/flutter_tools/lib/src/commands/run.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,11 @@ class RunCommand extends RunCommandBase {
615615
final bool flavorsSupportedOnEveryDevice = devices!
616616
.every((Device device) => device.supportsFlavors);
617617
if (flavor != null && !flavorsSupportedOnEveryDevice) {
618-
throwToolExit('--flavor is only supported for Android, macOS, and iOS devices.');
618+
globals.printWarning(
619+
'--flavor is only supported for Android, macOS, and iOS devices. '
620+
'Flavor-related features may not function properly and could '
621+
'behave differently in a future release.'
622+
);
619623
}
620624
}
621625

packages/flutter_tools/test/commands.shard/hermetic/run_test.dart

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ void main() {
4848
});
4949

5050
group('run', () {
51+
late BufferLogger logger;
5152
late TestDeviceManager testDeviceManager;
5253
late FileSystem fileSystem;
5354

5455
setUp(() {
55-
testDeviceManager = TestDeviceManager(logger: BufferLogger.test());
56+
logger = BufferLogger.test();
57+
testDeviceManager = TestDeviceManager(logger: logger);
5658
fileSystem = MemoryFileSystem.test();
5759
});
5860

@@ -65,7 +67,7 @@ void main() {
6567
}, overrides: <Type, Generator>{
6668
FileSystem: () => fileSystem,
6769
ProcessManager: () => FakeProcessManager.any(),
68-
Logger: () => BufferLogger.test(),
70+
Logger: () => logger,
6971
});
7072

7173
testUsingContext('does not support --no-sound-null-safety by default', () async {
@@ -89,7 +91,7 @@ void main() {
8991
}, overrides: <Type, Generator>{
9092
FileSystem: () => fileSystem,
9193
ProcessManager: () => FakeProcessManager.any(),
92-
Logger: () => BufferLogger.test(),
94+
Logger: () => logger,
9395
});
9496

9597
testUsingContext('supports --no-sound-null-safety with an overridden NonNullSafeBuilds', () async {
@@ -109,7 +111,7 @@ void main() {
109111
}, overrides: <Type, Generator>{
110112
DeviceManager: () => testDeviceManager,
111113
FileSystem: () => fileSystem,
112-
Logger: () => BufferLogger.test(),
114+
Logger: () => logger,
113115
NonNullSafeBuilds: () => NonNullSafeBuilds.allowed,
114116
ProcessManager: () => FakeProcessManager.any(),
115117
});
@@ -137,7 +139,7 @@ void main() {
137139
}, overrides: <Type, Generator>{
138140
FileSystem: () => fileSystem,
139141
ProcessManager: () => FakeProcessManager.any(),
140-
Logger: () => BufferLogger.test(),
142+
Logger: () => logger,
141143
});
142144

143145
testUsingContext('Walks upward looking for a pubspec.yaml and succeeds if found', () async {
@@ -165,7 +167,7 @@ void main() {
165167
}, overrides: <Type, Generator>{
166168
FileSystem: () => fileSystem,
167169
ProcessManager: () => FakeProcessManager.any(),
168-
Logger: () => BufferLogger.test(),
170+
Logger: () => logger,
169171
});
170172

171173
testUsingContext('Walks upward looking for a pubspec.yaml and exits if missing', () async {
@@ -185,7 +187,7 @@ void main() {
185187
}, overrides: <Type, Generator>{
186188
FileSystem: () => fileSystem,
187189
ProcessManager: () => FakeProcessManager.any(),
188-
Logger: () => BufferLogger.test(),
190+
Logger: () => logger,
189191
});
190192

191193
group('run app', () {
@@ -431,7 +433,7 @@ void main() {
431433
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
432434
});
433435

434-
testUsingContext('fails when --flavor is used with an unsupported target platform', () async {
436+
testUsingContext('prints warning when --flavor is used with an unsupported target platform', () async {
435437
const List<String> runCommand = <String>[
436438
'run',
437439
'--no-pub',
@@ -440,24 +442,25 @@ void main() {
440442
'-d',
441443
'all',
442444
];
443-
444445
// Useful for test readability.
445446
// ignore: avoid_redundant_argument_values
446447
final FakeDevice deviceWithoutFlavorSupport = FakeDevice(supportsFlavors: false);
447448
final FakeDevice deviceWithFlavorSupport = FakeDevice(supportsFlavors: true);
448449
testDeviceManager.devices = <Device>[deviceWithoutFlavorSupport, deviceWithFlavorSupport];
449450

450-
await expectLater(
451-
() => createTestCommandRunner(RunCommand()).run(runCommand),
452-
throwsToolExit(
453-
message: '--flavor is only supported for Android, macOS, and iOS devices.',
454-
),
455-
);
451+
await createTestCommandRunner(TestRunCommandThatOnlyValidates()).run(runCommand);
452+
453+
expect(logger.warningText, contains(
454+
'--flavor is only supported for Android, macOS, and iOS devices. '
455+
'Flavor-related features may not function properly and could '
456+
'behave differently in a future release.'
457+
));
456458
}, overrides: <Type, Generator>{
457459
DeviceManager: () => testDeviceManager,
458460
FileSystem: () => fs,
459461
ProcessManager: () => FakeProcessManager.any(),
460462
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
463+
Logger: () => logger,
461464
});
462465

463466
testUsingContext('forwards --uninstall-only to DebuggingOptions', () async {
@@ -677,7 +680,7 @@ void main() {
677680
ProcessManager: () => FakeProcessManager.any(),
678681
Usage: () => usage,
679682
Stdio: () => FakeStdio(),
680-
Logger: () => AppRunLogger(parent: BufferLogger.test()),
683+
Logger: () => AppRunLogger(parent: logger),
681684
});
682685

683686
testUsingContext('can disable devtools with --no-devtools', () async {
@@ -705,7 +708,7 @@ void main() {
705708
ProcessManager: () => FakeProcessManager.any(),
706709
Usage: () => usage,
707710
Stdio: () => FakeStdio(),
708-
Logger: () => AppRunLogger(parent: BufferLogger.test()),
711+
Logger: () => AppRunLogger(parent: logger),
709712
});
710713
});
711714
});
@@ -1014,7 +1017,7 @@ void main() {
10141017
}, overrides: <Type, Generator>{
10151018
FileSystem: () => fileSystem,
10161019
ProcessManager: () => FakeProcessManager.any(),
1017-
Logger: () => BufferLogger.test(),
1020+
Logger: () => logger,
10181021
DeviceManager: () => testDeviceManager,
10191022
});
10201023

@@ -1035,7 +1038,7 @@ void main() {
10351038
}, overrides: <Type, Generator>{
10361039
FileSystem: () => fileSystem,
10371040
ProcessManager: () => FakeProcessManager.any(),
1038-
Logger: () => BufferLogger.test(),
1041+
Logger: () => logger,
10391042
DeviceManager: () => testDeviceManager,
10401043
});
10411044

@@ -1059,7 +1062,7 @@ void main() {
10591062
}, overrides: <Type, Generator>{
10601063
FileSystem: () => fileSystem,
10611064
ProcessManager: () => FakeProcessManager.any(),
1062-
Logger: () => BufferLogger.test(),
1065+
Logger: () => logger,
10631066
DeviceManager: () => testDeviceManager,
10641067
});
10651068

@@ -1079,7 +1082,7 @@ void main() {
10791082
}, overrides: <Type, Generator>{
10801083
FileSystem: () => fileSystem,
10811084
ProcessManager: () => FakeProcessManager.any(),
1082-
Logger: () => BufferLogger.test(),
1085+
Logger: () => logger,
10831086
DeviceManager: () => testDeviceManager,
10841087
});
10851088
});

0 commit comments

Comments
 (0)