Unverified Commit dd93ee30 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] drive uses correct application package for prebuilt (#68309)

Both start and stop app create an application package, but only start app used the application binary. Create the application package once and pass it to both start and stop app.
parent 8d730429
...@@ -181,6 +181,14 @@ class DriveCommand extends RunCommandBase { ...@@ -181,6 +181,14 @@ class DriveCommand extends RunCommandBase {
ResidentRunner residentRunner; ResidentRunner residentRunner;
final BuildInfo buildInfo = getBuildInfo(); final BuildInfo buildInfo = getBuildInfo();
final bool isWebPlatform = await device.targetPlatform == TargetPlatform.web_javascript; final bool isWebPlatform = await device.targetPlatform == TargetPlatform.web_javascript;
final File applicationBinary = stringArg('use-application-binary') == null
? null
: globals.fs.file(stringArg('use-application-binary'));
final ApplicationPackage package = await applicationPackages.getPackageForPlatform(
await device.targetPlatform,
buildInfo: buildInfo,
applicationBinary: applicationBinary,
);
if (argResults['use-existing-app'] == null) { if (argResults['use-existing-app'] == null) {
globals.printStatus('Starting application: $targetFile'); globals.printStatus('Starting application: $targetFile');
...@@ -238,7 +246,7 @@ class DriveCommand extends RunCommandBase { ...@@ -238,7 +246,7 @@ class DriveCommand extends RunCommandBase {
webUri = residentRunner.uri; webUri = residentRunner.uri;
} }
final LaunchResult result = await appStarter(this, webUri); final LaunchResult result = await appStarter(this, webUri, package, applicationBinary != null);
if (result == null) { if (result == null) {
throwToolExit('Application failed to start. Will not run test. Quitting.', exitCode: 1); throwToolExit('Application failed to start. Will not run test. Quitting.', exitCode: 1);
} }
...@@ -364,7 +372,7 @@ $ex ...@@ -364,7 +372,7 @@ $ex
globals.printStatus('Leaving the application running.'); globals.printStatus('Leaving the application running.');
} else { } else {
globals.printStatus('Stopping application instance.'); globals.printStatus('Stopping application instance.');
await appStopper(this); await appStopper(this, package);
} }
} }
...@@ -417,7 +425,7 @@ $ex ...@@ -417,7 +425,7 @@ $ex
Future<Device> findTargetDevice({ @required Duration timeout }) async { Future<Device> findTargetDevice({ @required Duration timeout }) async {
final DeviceManager deviceManager = globals.deviceManager; final DeviceManager deviceManager = globals.deviceManager;
final List<Device> devices = await deviceManager.findTargetDevices(FlutterProject.current(), timeout: timeout); final List<Device> devices = await deviceManager.findTargetDevices(null, timeout: timeout);
if (deviceManager.hasSpecifiedDeviceId) { if (deviceManager.hasSpecifiedDeviceId) {
if (devices.isEmpty) { if (devices.isEmpty) {
...@@ -444,7 +452,7 @@ Future<Device> findTargetDevice({ @required Duration timeout }) async { ...@@ -444,7 +452,7 @@ Future<Device> findTargetDevice({ @required Duration timeout }) async {
} }
/// Starts the application on the device given command configuration. /// Starts the application on the device given command configuration.
typedef AppStarter = Future<LaunchResult> Function(DriveCommand command, Uri webUri); typedef AppStarter = Future<LaunchResult> Function(DriveCommand command, Uri webUri, ApplicationPackage applicationPackage, bool prebuiltApplication);
AppStarter appStarter = _startApp; // (mutable for testing) AppStarter appStarter = _startApp; // (mutable for testing)
void restoreAppStarter() { void restoreAppStarter() {
...@@ -453,9 +461,10 @@ void restoreAppStarter() { ...@@ -453,9 +461,10 @@ void restoreAppStarter() {
Future<LaunchResult> _startApp( Future<LaunchResult> _startApp(
DriveCommand command, DriveCommand command,
Uri webUri, { Uri webUri,
String userIdentifier, ApplicationPackage applicationPackage,
}) async { bool prebuiltApplication,
) async {
final String mainPath = findMainDartFile(command.targetFile); final String mainPath = findMainDartFile(command.targetFile);
if (await globals.fs.type(mainPath) != FileSystemEntityType.file) { if (await globals.fs.type(mainPath) != FileSystemEntityType.file) {
globals.printError('Tried to run $mainPath, but that file does not exist.'); globals.printError('Tried to run $mainPath, but that file does not exist.');
...@@ -463,16 +472,8 @@ Future<LaunchResult> _startApp( ...@@ -463,16 +472,8 @@ 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, applicationPackage);
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<String, dynamic> platformArgs = <String, dynamic>{}; final Map<String, dynamic> platformArgs = <String, dynamic>{};
if (command.traceStartup) { if (command.traceStartup) {
...@@ -491,13 +492,13 @@ Future<LaunchResult> _startApp( ...@@ -491,13 +492,13 @@ Future<LaunchResult> _startApp(
globals.printTrace('Starting application.'); globals.printTrace('Starting application.');
// Forward device log messages to the terminal window running the "drive" command. // Forward device log messages to the terminal window running the "drive" command.
final DeviceLogReader logReader = await command.device.getLogReader(app: package); final DeviceLogReader logReader = await command.device.getLogReader(app: applicationPackage);
command._deviceLogSubscription = logReader command._deviceLogSubscription = logReader
.logLines .logLines
.listen(globals.printStatus); .listen(globals.printStatus);
final LaunchResult result = await command.device.startApp( final LaunchResult result = await command.device.startApp(
package, applicationPackage,
mainPath: mainPath, mainPath: mainPath,
route: command.route, route: command.route,
debuggingOptions: DebuggingOptions.enabled( debuggingOptions: DebuggingOptions.enabled(
...@@ -512,8 +513,8 @@ Future<LaunchResult> _startApp( ...@@ -512,8 +513,8 @@ Future<LaunchResult> _startApp(
purgePersistentCache: command.purgePersistentCache, purgePersistentCache: command.purgePersistentCache,
), ),
platformArgs: platformArgs, platformArgs: platformArgs,
userIdentifier: userIdentifier, userIdentifier: command.userIdentifier,
prebuiltApplication: applicationBinary != null, prebuiltApplication: prebuiltApplication,
); );
if (!result.started) { if (!result.started) {
...@@ -551,18 +552,14 @@ Future<void> _runTests(List<String> testArgs, Map<String, String> environment) a ...@@ -551,18 +552,14 @@ Future<void> _runTests(List<String> testArgs, Map<String, String> environment) a
/// Stops the application. /// Stops the application.
typedef AppStopper = Future<bool> Function(DriveCommand command); typedef AppStopper = Future<bool> Function(DriveCommand command, ApplicationPackage applicationPackage);
AppStopper appStopper = _stopApp; AppStopper appStopper = _stopApp;
void restoreAppStopper() { void restoreAppStopper() {
appStopper = _stopApp; appStopper = _stopApp;
} }
Future<bool> _stopApp(DriveCommand command) async { Future<bool> _stopApp(DriveCommand command, ApplicationPackage package) async {
globals.printTrace('Stopping application.'); globals.printTrace('Stopping application.');
final ApplicationPackage package = await command.applicationPackages.getPackageForPlatform(
await command.device.targetPlatform,
buildInfo: command.getBuildInfo(),
);
final bool stopped = await command.device.stopApp(package, userIdentifier: command.userIdentifier); final bool stopped = await command.device.stopApp(package, userIdentifier: command.userIdentifier);
await command.device.uninstallApp(package); await command.device.uninstallApp(package);
await command._deviceLogSubscription?.cancel(); await command._deviceLogSubscription?.cancel();
......
...@@ -45,13 +45,13 @@ void main() { ...@@ -45,13 +45,13 @@ void main() {
fs.file('pubspec.yaml').createSync(); fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync(); fs.file('.packages').createSync();
setExitFunctionForTests(); setExitFunctionForTests();
appStarter = (DriveCommand command, Uri webUri) { appStarter = (DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) {
throw 'Unexpected call to appStarter'; throw 'Unexpected call to appStarter';
}; };
testRunner = (List<String> testArgs, Map<String, String> environment) { testRunner = (List<String> testArgs, Map<String, String> environment) {
throw 'Unexpected call to testRunner'; throw 'Unexpected call to testRunner';
}; };
appStopper = (DriveCommand command) { appStopper = (DriveCommand command, ApplicationPackage package) {
throw 'Unexpected call to appStopper'; throw 'Unexpected call to appStopper';
}; };
command.applicationPackages = FakeApplicationPackageFactory(); command.applicationPackages = FakeApplicationPackageFactory();
...@@ -99,7 +99,7 @@ void main() { ...@@ -99,7 +99,7 @@ void main() {
testUsingContext('returns 1 when app fails to run', () async { testUsingContext('returns 1 when app fails to run', () async {
testDeviceManager.addDevice(MockDevice()); testDeviceManager.addDevice(MockDevice());
appStarter = expectAsync2((DriveCommand command, Uri webUri) async => null); appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async => null);
final String testApp = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e.dart'); final String testApp = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e.dart');
final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart'); final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
...@@ -201,7 +201,7 @@ void main() { ...@@ -201,7 +201,7 @@ void main() {
final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart'); final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart');
final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart'); final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
appStarter = expectAsync2((DriveCommand command, Uri webUri) async { appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async {
return LaunchResult.succeeded(); return LaunchResult.succeeded();
}); });
testRunner = expectAsync2((List<String> testArgs, Map<String, String> environment) async { testRunner = expectAsync2((List<String> testArgs, Map<String, String> environment) async {
...@@ -211,7 +211,7 @@ void main() { ...@@ -211,7 +211,7 @@ void main() {
'VM_SERVICE_URL': 'null', 'VM_SERVICE_URL': 'null',
}); });
}); });
appStopper = expectAsync1((DriveCommand command) async { appStopper = expectAsync2((DriveCommand command, ApplicationPackage package) async {
return true; return true;
}); });
...@@ -242,13 +242,13 @@ void main() { ...@@ -242,13 +242,13 @@ void main() {
final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart'); final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart');
final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart'); final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
appStarter = expectAsync2((DriveCommand command, Uri webUri) async { appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async {
return LaunchResult.succeeded(); return LaunchResult.succeeded();
}); });
testRunner = (List<String> testArgs, Map<String, String> environment) async { testRunner = (List<String> testArgs, Map<String, String> environment) async {
throwToolExit(null, exitCode: 123); throwToolExit(null, exitCode: 123);
}; };
appStopper = expectAsync1((DriveCommand command) async { appStopper = expectAsync2((DriveCommand command, ApplicationPackage package) async {
return true; return true;
}); });
...@@ -281,7 +281,7 @@ void main() { ...@@ -281,7 +281,7 @@ void main() {
final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart'); final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart');
final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart'); final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
appStarter = expectAsync2((DriveCommand command, Uri webUri) async { appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async {
return LaunchResult.succeeded(); return LaunchResult.succeeded();
}); });
testRunner = expectAsync2((List<String> testArgs, Map<String, String> environment) async { testRunner = expectAsync2((List<String> testArgs, Map<String, String> environment) async {
...@@ -294,7 +294,7 @@ void main() { ...@@ -294,7 +294,7 @@ void main() {
] ]
); );
}); });
appStopper = expectAsync1((DriveCommand command) async { appStopper = expectAsync2((DriveCommand command, ApplicationPackage package) async {
return true; return true;
}); });
...@@ -324,7 +324,7 @@ void main() { ...@@ -324,7 +324,7 @@ void main() {
final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart'); final String testApp = globals.fs.path.join(tempDir.path, 'test', 'e2e.dart');
final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart'); final String testFile = globals.fs.path.join(tempDir.path, 'test_driver', 'e2e_test.dart');
appStarter = expectAsync2((DriveCommand command, Uri webUri) async { appStarter = expectAsync4((DriveCommand command, Uri webUri, ApplicationPackage package, bool prebuiltApplication) async {
return LaunchResult.succeeded(); return LaunchResult.succeeded();
}); });
testRunner = expectAsync2((List<String> testArgs, Map<String, String> environment) async { testRunner = expectAsync2((List<String> testArgs, Map<String, String> environment) async {
...@@ -336,7 +336,7 @@ void main() { ...@@ -336,7 +336,7 @@ void main() {
] ]
); );
}); });
appStopper = expectAsync1((DriveCommand command) async { appStopper = expectAsync2((DriveCommand command, ApplicationPackage package) async {
return true; return true;
}); });
...@@ -493,8 +493,8 @@ void main() { ...@@ -493,8 +493,8 @@ void main() {
testRunner = (List<String> testArgs, Map<String, String> environment) async { testRunner = (List<String> testArgs, Map<String, String> environment) async {
throwToolExit(null, exitCode: 123); throwToolExit(null, exitCode: 123);
}; };
appStopper = expectAsync1( appStopper = expectAsync2(
(DriveCommand command) async { (DriveCommand command, ApplicationPackage package) async {
return true; return true;
}, },
count: 2, count: 2,
...@@ -603,8 +603,8 @@ void main() { ...@@ -603,8 +603,8 @@ void main() {
testRunner = (List<String> testArgs, Map<String, String> environment) async { testRunner = (List<String> testArgs, Map<String, String> environment) async {
throwToolExit(null, exitCode: 123); throwToolExit(null, exitCode: 123);
}; };
appStopper = expectAsync1( appStopper = expectAsync2(
(DriveCommand command) async { (DriveCommand command, ApplicationPackage package) async {
return true; return true;
}, },
count: 2, count: 2,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment