Skip to content

Commit 7020f59

Browse files
a-wallena-wallen
and
a-wallen
authored
[tool] Support --flavor option for flutter install. (#114048)
* Alphabetize setup calls * Add --flavor as an option for install * Add verbose logging in install command * Test that flavors build succeeds with proper flavor and fails with bogus one. * Remove unused import * The import was used... * SQUASH * Add flavor install test * Rename test * Add flavors install integration tests * correct error message * remove unused imports * Delete copy test * update test target * Refactor mechanism to read buildInfo * Remove unused import * Set affected test targets to bringup: true Co-authored-by: a-wallen <[email protected]>
1 parent 1725a26 commit 7020f59

File tree

7 files changed

+89
-28
lines changed

7 files changed

+89
-28
lines changed

.ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,7 @@ targets:
16871687
task_name: fast_scroll_large_images__memory
16881688

16891689
- name: Linux_android flavors_test
1690+
bringup: true
16901691
recipe: devicelab/devicelab_drone
16911692
presubmit: false
16921693
timeout: 60
@@ -3371,6 +3372,7 @@ targets:
33713372
task_name: route_test_ios
33723373

33733374
- name: Mac_ios flavors_test_ios
3375+
bringup: true
33743376
recipe: devicelab/devicelab_drone
33753377
presubmit: false
33763378
timeout: 60
@@ -4537,7 +4539,7 @@ targets:
45374539
properties:
45384540
tags: >
45394541
["devicelab", "android", "windows"]
4540-
task_name: flavors_test_win
4542+
task_name: flavors_test
45414543

45424544
- name: Windows_android flutter_gallery_win__compile
45434545
recipe: devicelab/devicelab_drone

dev/devicelab/bin/tasks/flavors_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,38 @@
55
import 'package:flutter_devicelab/framework/devices.dart';
66
import 'package:flutter_devicelab/framework/framework.dart';
77
import 'package:flutter_devicelab/framework/task_result.dart';
8+
import 'package:flutter_devicelab/framework/utils.dart';
89
import 'package:flutter_devicelab/tasks/integration_tests.dart';
910

1011
Future<void> main() async {
1112
deviceOperatingSystem = DeviceOperatingSystem.android;
1213
await task(() async {
1314
await createFlavorsTest().call();
1415
await createIntegrationTestFlavorsTest().call();
16+
// test install and uninstall of flavors app
17+
await inDirectory('${flutterDirectory.path}/dev/integration_tests/flavors', () async {
18+
await flutter(
19+
'install',
20+
options: <String>['--flavor', 'paid'],
21+
);
22+
await flutter(
23+
'install',
24+
options: <String>['--flavor', 'paid', '--uninstall-only'],
25+
);
26+
final StringBuffer stderr = StringBuffer();
27+
await evalFlutter(
28+
'install',
29+
canFail: true,
30+
stderr: stderr,
31+
options: <String>['--flavor', 'bogus'],
32+
);
33+
34+
final String stderrString = stderr.toString();
35+
if (!stderrString.contains('The Xcode project defines schemes: free, paid')) {
36+
print(stderrString);
37+
return TaskResult.failure('Should not succeed with bogus flavor');
38+
}
39+
});
1540

1641
return TaskResult.success(null);
1742
});

dev/devicelab/bin/tasks/flavors_test_ios.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,38 @@
55
import 'package:flutter_devicelab/framework/devices.dart';
66
import 'package:flutter_devicelab/framework/framework.dart';
77
import 'package:flutter_devicelab/framework/task_result.dart';
8+
import 'package:flutter_devicelab/framework/utils.dart';
89
import 'package:flutter_devicelab/tasks/integration_tests.dart';
910

1011
Future<void> main() async {
1112
deviceOperatingSystem = DeviceOperatingSystem.ios;
1213
await task(() async {
1314
await createFlavorsTest().call();
1415
await createIntegrationTestFlavorsTest().call();
16+
// test install and uninstall of flavors app
17+
await inDirectory('${flutterDirectory.path}/dev/integration_tests/flavors', () async {
18+
await flutter(
19+
'install',
20+
options: <String>['--flavor', 'paid'],
21+
);
22+
await flutter(
23+
'install',
24+
options: <String>['--flavor', 'paid', '--uninstall-only'],
25+
);
26+
final StringBuffer stderr = StringBuffer();
27+
await evalFlutter(
28+
'install',
29+
canFail: true,
30+
stderr: stderr,
31+
options: <String>['--flavor', 'bogus'],
32+
);
33+
34+
final String stderrString = stderr.toString();
35+
if (!stderrString.contains('install failed, bogus flavor not found')) {
36+
print(stderrString);
37+
return TaskResult.failure('Should not succeed with bogus flavor');
38+
}
39+
});
1540

1641
return TaskResult.success(null);
1742
});

dev/devicelab/bin/tasks/flavors_test_win.dart

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/flutter_tools/lib/executable.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ List<FlutterCommand> generateCommands({
200200
artifacts: globals.artifacts!,
201201
processManager: globals.processManager,
202202
),
203-
InstallCommand(),
203+
InstallCommand(
204+
verboseHelp: verboseHelp,
205+
),
204206
LogsCommand(),
205207
MakeHostAppEditableCommand(),
206208
PackagesCommand(),

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ import '../globals.dart' as globals;
1212
import '../runner/flutter_command.dart';
1313

1414
class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
15-
InstallCommand() {
15+
InstallCommand({
16+
required bool verboseHelp,
17+
}) {
18+
addBuildModeFlags(verboseHelp: verboseHelp);
1619
requiresPubspecYaml();
17-
usesDeviceUserOption();
18-
usesDeviceTimeoutOption();
1920
usesApplicationBinaryOption();
21+
usesDeviceTimeoutOption();
22+
usesDeviceUserOption();
23+
usesFlavorOption();
2024
argParser.addFlag('uninstall-only',
2125
help: 'Uninstall the app if already on the device. Skip install.',
2226
);
@@ -60,6 +64,7 @@ class InstallCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts
6064
final ApplicationPackage? package = await applicationPackages?.getPackageForPlatform(
6165
await targetDevice.targetPlatform,
6266
applicationBinary: _applicationBinary,
67+
buildInfo: await getBuildInfo(),
6368
);
6469
if (package == null) {
6570
throwToolExit('Could not find or build package');

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void main() {
3232
});
3333

3434
testUsingContext('returns 0 when Android is connected and ready for an install', () async {
35-
final InstallCommand command = InstallCommand();
35+
final InstallCommand command = InstallCommand(verboseHelp: false);
3636
command.applicationPackages = FakeApplicationPackageFactory(FakeAndroidApk());
3737

3838
final FakeAndroidDevice device = FakeAndroidDevice();
@@ -46,7 +46,7 @@ void main() {
4646
});
4747

4848
testUsingContext('returns 1 when targeted device is not Android with --device-user', () async {
49-
final InstallCommand command = InstallCommand();
49+
final InstallCommand command = InstallCommand(verboseHelp: false);
5050
command.applicationPackages = FakeApplicationPackageFactory(FakeAndroidApk());
5151

5252
final FakeIOSDevice device = FakeIOSDevice();
@@ -61,7 +61,7 @@ void main() {
6161
});
6262

6363
testUsingContext('returns 0 when iOS is connected and ready for an install', () async {
64-
final InstallCommand command = InstallCommand();
64+
final InstallCommand command = InstallCommand(verboseHelp: false);
6565
command.applicationPackages = FakeApplicationPackageFactory(FakeIOSApp());
6666

6767
final FakeIOSDevice device = FakeIOSDevice();
@@ -75,7 +75,7 @@ void main() {
7575
});
7676

7777
testUsingContext('fails when prebuilt binary not found', () async {
78-
final InstallCommand command = InstallCommand();
78+
final InstallCommand command = InstallCommand(verboseHelp: false);
7979
command.applicationPackages = FakeApplicationPackageFactory(FakeAndroidApk());
8080

8181
final FakeAndroidDevice device = FakeAndroidDevice();
@@ -90,7 +90,7 @@ void main() {
9090
});
9191

9292
testUsingContext('succeeds using prebuilt binary', () async {
93-
final InstallCommand command = InstallCommand();
93+
final InstallCommand command = InstallCommand(verboseHelp: false);
9494
command.applicationPackages = FakeApplicationPackageFactory(FakeAndroidApk());
9595

9696
final FakeAndroidDevice device = FakeAndroidDevice();
@@ -103,16 +103,36 @@ void main() {
103103
FileSystem: () => fileSystem,
104104
ProcessManager: () => FakeProcessManager.any(),
105105
});
106+
107+
testUsingContext('Passes flavor to application package.', () async {
108+
const String flavor = 'free';
109+
final InstallCommand command = InstallCommand(verboseHelp: false);
110+
final FakeApplicationPackageFactory fakeAppFactory = FakeApplicationPackageFactory(FakeIOSApp());
111+
command.applicationPackages = fakeAppFactory;
112+
113+
final FakeIOSDevice device = FakeIOSDevice();
114+
testDeviceManager.addDevice(device);
115+
116+
await createTestCommandRunner(command).run(<String>['install', '--flavor', flavor]);
117+
expect(fakeAppFactory.buildInfo, isNotNull);
118+
expect(fakeAppFactory.buildInfo!.flavor, flavor);
119+
}, overrides: <Type, Generator>{
120+
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
121+
FileSystem: () => fileSystem,
122+
ProcessManager: () => FakeProcessManager.any(),
123+
});
106124
});
107125
}
108126

109127
class FakeApplicationPackageFactory extends Fake implements ApplicationPackageFactory {
110128
FakeApplicationPackageFactory(this.app);
111129

112130
final ApplicationPackage app;
131+
BuildInfo? buildInfo;
113132

114133
@override
115134
Future<ApplicationPackage> getPackageForPlatform(TargetPlatform platform, {BuildInfo? buildInfo, File? applicationBinary}) async {
135+
this.buildInfo = buildInfo;
116136
return app;
117137
}
118138
}

0 commit comments

Comments
 (0)