Commit f544abd0 authored by Yegor's avatar Yegor

modernize `flutter drive` w.r.t. debug/profile/release options (#4217)

* modernize `flutter drive` w.r.t. debug/profil/release options

* make error message prettier
parent 6f3382aa
...@@ -100,7 +100,19 @@ class DriveCommand extends RunCommandBase { ...@@ -100,7 +100,19 @@ class DriveCommand extends RunCommandBase {
if (!argResults['use-existing-app']) { if (!argResults['use-existing-app']) {
printStatus('Starting application: ${argResults["target"]}'); printStatus('Starting application: ${argResults["target"]}');
int result = await appStarter(this, getBuildMode());
if (getBuildMode() == BuildMode.release) {
// This is because we need VM service to be able to drive the app.
printError(
'Flutter Driver does not support running in release mode.\n'
'\n'
'Use --profile mode for testing application performance.\n'
'Use --debug (default) mode for testing correctness (with assertions).'
);
return 1;
}
int result = await appStarter(this);
if (result != 0) { if (result != 0) {
printError('Application failed to start. Will not run test. Quitting.'); printError('Application failed to start. Will not run test. Quitting.');
return result; return result;
...@@ -229,14 +241,14 @@ Future<Device> findTargetDevice() async { ...@@ -229,14 +241,14 @@ Future<Device> findTargetDevice() async {
} }
/// Starts the application on the device given command configuration. /// Starts the application on the device given command configuration.
typedef Future<int> AppStarter(DriveCommand command, BuildMode buildMode); typedef Future<int> AppStarter(DriveCommand command);
AppStarter appStarter = startApp; AppStarter appStarter = startApp;
void restoreAppStarter() { void restoreAppStarter() {
appStarter = startApp; appStarter = startApp;
} }
Future<int> startApp(DriveCommand command, BuildMode buildMode) async { Future<int> startApp(DriveCommand command) async {
String mainPath = findMainDartFile(command.target); String mainPath = findMainDartFile(command.target);
if (await fs.type(mainPath) != FileSystemEntityType.FILE) { if (await fs.type(mainPath) != FileSystemEntityType.FILE) {
printError('Tried to run $mainPath, but that file does not exist.'); printError('Tried to run $mainPath, but that file does not exist.');
...@@ -248,7 +260,8 @@ Future<int> startApp(DriveCommand command, BuildMode buildMode) async { ...@@ -248,7 +260,8 @@ Future<int> startApp(DriveCommand command, BuildMode buildMode) async {
printTrace('Building an APK.'); printTrace('Building an APK.');
int result = await build_apk.buildApk( int result = await build_apk.buildApk(
command.device.platform, command.device.platform,
target: command.target target: command.target,
buildMode: command.getBuildMode()
); );
if (result != 0) if (result != 0)
...@@ -263,20 +276,22 @@ Future<int> startApp(DriveCommand command, BuildMode buildMode) async { ...@@ -263,20 +276,22 @@ Future<int> startApp(DriveCommand command, BuildMode buildMode) async {
.getPackageForPlatform(command.device.platform); .getPackageForPlatform(command.device.platform);
command.device.installApp(package); command.device.installApp(package);
Map<String, dynamic> platformArgs = <String, dynamic>{};
if (command.traceStartup)
platformArgs['trace-startup'] = command.traceStartup;
printTrace('Starting application.'); printTrace('Starting application.');
LaunchResult result = await command.device.startApp( LaunchResult result = await command.device.startApp(
package, package,
buildMode, command.getBuildMode(),
mainPath: mainPath, mainPath: mainPath,
route: command.route, route: command.route,
debuggingOptions: new DebuggingOptions.enabled( debuggingOptions: new DebuggingOptions.enabled(
buildMode, command.getBuildMode(),
startPaused: true, startPaused: true,
observatoryPort: command.debugPort observatoryPort: command.debugPort
), ),
platformArgs: <String, dynamic>{ platformArgs: platformArgs
'trace-startup': command.traceStartup,
}
); );
return result.started ? 0 : 2; return result.started ? 0 : 2;
......
...@@ -38,7 +38,7 @@ void main() { ...@@ -38,7 +38,7 @@ void main() {
targetDeviceFinder = () { targetDeviceFinder = () {
throw 'Unexpected call to targetDeviceFinder'; throw 'Unexpected call to targetDeviceFinder';
}; };
appStarter = (_, __) { appStarter = (_) {
throw 'Unexpected call to appStarter'; throw 'Unexpected call to appStarter';
}; };
testRunner = (_) { testRunner = (_) {
...@@ -75,7 +75,7 @@ void main() { ...@@ -75,7 +75,7 @@ void main() {
testUsingContext('returns 1 when app fails to run', () async { testUsingContext('returns 1 when app fails to run', () async {
withMockDevice(); withMockDevice();
appStarter = expectAsync((_, __) async => 1); appStarter = expectAsync((_) async => 1);
String testApp = '/some/app/test_driver/e2e.dart'; String testApp = '/some/app/test_driver/e2e.dart';
String testFile = '/some/app/test_driver/e2e_test.dart'; String testFile = '/some/app/test_driver/e2e_test.dart';
...@@ -140,7 +140,7 @@ void main() { ...@@ -140,7 +140,7 @@ void main() {
String testApp = '/some/app/test/e2e.dart'; String testApp = '/some/app/test/e2e.dart';
String testFile = '/some/app/test_driver/e2e_test.dart'; String testFile = '/some/app/test_driver/e2e_test.dart';
appStarter = expectAsync((_, __) { appStarter = expectAsync((_) {
return new Future<int>.value(0); return new Future<int>.value(0);
}); });
testRunner = expectAsync((List<String> testArgs) { testRunner = expectAsync((List<String> testArgs) {
...@@ -172,7 +172,7 @@ void main() { ...@@ -172,7 +172,7 @@ void main() {
String testApp = '/some/app/test/e2e.dart'; String testApp = '/some/app/test/e2e.dart';
String testFile = '/some/app/test_driver/e2e_test.dart'; String testFile = '/some/app/test_driver/e2e_test.dart';
appStarter = expectAsync((_, __) { appStarter = expectAsync((_) {
return new Future<int>.value(0); return new Future<int>.value(0);
}); });
testRunner = expectAsync((_) { testRunner = expectAsync((_) {
......
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