[flutter_tool] support --use-application-binary in flutter drive (#68060)

--use-application-binary allows running with an already built APK. This can be useful for speeding up CI test cases, or in our case eventually supporting some sort of build server. Demonstrate that this works by updating the old gallery test to use it. Fixes #56604

Co-authored-by: Jenn Magder <magder@google.com>
This commit is contained in:
Jonah Williams 2020-10-13 19:27:30 -07:00 committed by GitHub
parent f8f6963cd1
commit 751459df24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 16 deletions

View File

@ -62,21 +62,40 @@ class GalleryTransitionTest {
final Device device = await devices.workingDevice; final Device device = await devices.workingDevice;
await device.unlock(); await device.unlock();
final String deviceId = device.deviceId; final String deviceId = device.deviceId;
final Directory galleryDirectory = final Directory galleryDirectory = dir('${flutterDirectory.path}/dev/integration_tests/flutter_gallery');
dir('${flutterDirectory.path}/dev/integration_tests/flutter_gallery');
await inDirectory<void>(galleryDirectory, () async { await inDirectory<void>(galleryDirectory, () async {
await flutter('packages', options: <String>['get']); String applicationBinaryPath;
if (deviceOperatingSystem == DeviceOperatingSystem.android) {
section('BUILDING APPLICATION');
await flutter(
'build',
options: <String>[
'apk',
'--profile',
'-t',
'test_driver/$testFile.dart',
'--target-platform',
'android-arm,android-arm64',
],
);
applicationBinaryPath = 'build/app/outputs/flutter-apk/app-profile.apk';
}
final String testDriver = driverFile ?? (semanticsEnabled final String testDriver = driverFile ?? (semanticsEnabled
? '${testFile}_with_semantics_test' ? '${testFile}_with_semantics_test'
: '${testFile}_test'); : '${testFile}_test');
section('DRIVE START');
await flutter('drive', options: <String>[ await flutter('drive', options: <String>[
'--profile', '--profile',
if (needFullTimeline) if (needFullTimeline)
'--trace-startup', '--trace-startup',
'-t', if (applicationBinaryPath != null)
'test_driver/$testFile.dart', '--use-application-binary=$applicationBinaryPath'
else
...<String>[
'-t',
'test_driver/$testFile.dart',
],
'--driver', '--driver',
'test_driver/$testDriver.dart', 'test_driver/$testDriver.dart',
'-d', '-d',

View File

@ -572,7 +572,6 @@ class PerfTest {
@protected @protected
Future<TaskResult> internalRun({ Future<TaskResult> internalRun({
bool cacheSkSL = false, bool cacheSkSL = false,
bool noBuild = false,
String existingApp, String existingApp,
String writeSkslFileName, String writeSkslFileName,
}) { }) {
@ -589,7 +588,6 @@ class PerfTest {
if (needsFullTimeline) if (needsFullTimeline)
'--trace-startup', // Enables "endless" timeline event buffering. '--trace-startup', // Enables "endless" timeline event buffering.
'-t', testTarget, '-t', testTarget,
if (noBuild) '--no-build',
if (testDriver != null) if (testDriver != null)
...<String>['--driver', testDriver], ...<String>['--driver', testDriver],
if (existingApp != null) if (existingApp != null)
@ -730,7 +728,6 @@ class PerfTestWithSkSL extends PerfTest {
// that we won't remove the SkSLs generated earlier. // that we won't remove the SkSLs generated earlier.
await super.internalRun( await super.internalRun(
cacheSkSL: true, cacheSkSL: true,
noBuild: true,
writeSkslFileName: _skslJsonFileName, writeSkslFileName: _skslJsonFileName,
); );
} }

View File

@ -466,8 +466,14 @@ Future<LaunchResult> _startApp(
globals.printTrace('Stopping previously running application, if any.'); globals.printTrace('Stopping previously running application, if any.');
await appStopper(command); await appStopper(command);
final ApplicationPackage package = await command.applicationPackages final File applicationBinary = command.stringArg('use-application-binary') == null
.getPackageForPlatform(await command.device.targetPlatform, buildInfo: command.getBuildInfo()); ? null
: globals.fs.file(command.stringArg('use-application-binary'));
final ApplicationPackage package = await command.applicationPackages.getPackageForPlatform(
await command.device.targetPlatform,
buildInfo: command.getBuildInfo(),
applicationBinary: applicationBinary,
);
final Map<String, dynamic> platformArgs = <String, dynamic>{}; final Map<String, dynamic> platformArgs = <String, dynamic>{};
if (command.traceStartup) { if (command.traceStartup) {
@ -508,6 +514,7 @@ Future<LaunchResult> _startApp(
), ),
platformArgs: platformArgs, platformArgs: platformArgs,
userIdentifier: userIdentifier, userIdentifier: userIdentifier,
prebuiltApplication: applicationBinary != null,
); );
if (!result.started) { if (!result.started) {

View File

@ -70,7 +70,14 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
negatable: false, negatable: false,
hide: !verboseHelp, hide: !verboseHelp,
help: 'No longer require an authentication code to connect to the VM ' help: 'No longer require an authentication code to connect to the VM '
'service (not recommended).'); 'service (not recommended).'
)
..addOption('use-application-binary',
help: 'Specify a pre-built application binary to use when running. For android applications, '
'this must be the path to an APK. For iOS applications, the path to an IPA. Other device types '
'do not yet support prebuilt application binaries',
valueHelp: 'path/to/app.apk',
);
usesWebOptions(hide: !verboseHelp); usesWebOptions(hide: !verboseHelp);
usesTargetOption(); usesTargetOption();
usesPortOptions(); usesPortOptions();
@ -178,10 +185,6 @@ class RunCommand extends RunCommandBase {
'This flag is not available on the stable channel and is only ' 'This flag is not available on the stable channel and is only '
'applied in debug and profile modes. This option should only ' 'applied in debug and profile modes. This option should only '
'be used for experiments and should not be used by typical users.') 'be used for experiments and should not be used by typical users.')
..addOption('use-application-binary',
hide: !verboseHelp,
help: 'Specify a pre-built application binary to use when running.',
)
..addOption('project-root', ..addOption('project-root',
hide: !verboseHelp, hide: !verboseHelp,
help: 'Specify the project root directory.', help: 'Specify the project root directory.',