From 751459df2483e10e18d9d20aed8b24b2f6c382cc Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 13 Oct 2020 19:27:30 -0700 Subject: [PATCH] [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 --- dev/devicelab/lib/tasks/gallery.dart | 31 +++++++++++++++---- dev/devicelab/lib/tasks/perf_tests.dart | 3 -- .../flutter_tools/lib/src/commands/drive.dart | 11 +++++-- .../flutter_tools/lib/src/commands/run.dart | 13 +++++--- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/dev/devicelab/lib/tasks/gallery.dart b/dev/devicelab/lib/tasks/gallery.dart index a21045488c..b06beae752 100644 --- a/dev/devicelab/lib/tasks/gallery.dart +++ b/dev/devicelab/lib/tasks/gallery.dart @@ -62,21 +62,40 @@ class GalleryTransitionTest { final Device device = await devices.workingDevice; await device.unlock(); final String deviceId = device.deviceId; - final Directory galleryDirectory = - dir('${flutterDirectory.path}/dev/integration_tests/flutter_gallery'); + final Directory galleryDirectory = dir('${flutterDirectory.path}/dev/integration_tests/flutter_gallery'); await inDirectory(galleryDirectory, () async { - await flutter('packages', options: ['get']); + String applicationBinaryPath; + if (deviceOperatingSystem == DeviceOperatingSystem.android) { + section('BUILDING APPLICATION'); + await flutter( + 'build', + options: [ + '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 ? '${testFile}_with_semantics_test' : '${testFile}_test'); - + section('DRIVE START'); await flutter('drive', options: [ '--profile', if (needFullTimeline) '--trace-startup', - '-t', - 'test_driver/$testFile.dart', + if (applicationBinaryPath != null) + '--use-application-binary=$applicationBinaryPath' + else + ...[ + '-t', + 'test_driver/$testFile.dart', + ], '--driver', 'test_driver/$testDriver.dart', '-d', diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index fa8aa579bd..290704675c 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -572,7 +572,6 @@ class PerfTest { @protected Future internalRun({ bool cacheSkSL = false, - bool noBuild = false, String existingApp, String writeSkslFileName, }) { @@ -589,7 +588,6 @@ class PerfTest { if (needsFullTimeline) '--trace-startup', // Enables "endless" timeline event buffering. '-t', testTarget, - if (noBuild) '--no-build', if (testDriver != null) ...['--driver', testDriver], if (existingApp != null) @@ -730,7 +728,6 @@ class PerfTestWithSkSL extends PerfTest { // that we won't remove the SkSLs generated earlier. await super.internalRun( cacheSkSL: true, - noBuild: true, writeSkslFileName: _skslJsonFileName, ); } diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 77abf78a32..76a1ca5b7b 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -466,8 +466,14 @@ Future _startApp( globals.printTrace('Stopping previously running application, if any.'); await appStopper(command); - final ApplicationPackage package = await command.applicationPackages - .getPackageForPlatform(await command.device.targetPlatform, buildInfo: command.getBuildInfo()); + final File applicationBinary = command.stringArg('use-application-binary') == null + ? 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 platformArgs = {}; if (command.traceStartup) { @@ -508,6 +514,7 @@ Future _startApp( ), platformArgs: platformArgs, userIdentifier: userIdentifier, + prebuiltApplication: applicationBinary != null, ); if (!result.started) { diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index 35d29fccdc..34ae7f04bc 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart @@ -70,7 +70,14 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment negatable: false, hide: !verboseHelp, 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); usesTargetOption(); usesPortOptions(); @@ -178,10 +185,6 @@ class RunCommand extends RunCommandBase { 'This flag is not available on the stable channel and is only ' 'applied in debug and profile modes. This option should only ' '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', hide: !verboseHelp, help: 'Specify the project root directory.',