From d131a8df42b45997410c9fcb5962b8f3a48498f1 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Fri, 23 Jun 2017 18:09:37 -0700 Subject: [PATCH] Fix --keep-app-running default and make devicelab verboser (#10957) --- dev/devicelab/lib/framework/adb.dart | 3 +- dev/devicelab/lib/framework/utils.dart | 44 ++++++++++++++----- .../flutter_tools/lib/src/commands/drive.dart | 1 + 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/dev/devicelab/lib/framework/adb.dart b/dev/devicelab/lib/framework/adb.dart index ee6281af76..7e29381084 100644 --- a/dev/devicelab/lib/framework/adb.dart +++ b/dev/devicelab/lib/framework/adb.dart @@ -152,7 +152,7 @@ class AndroidDeviceDiscovery implements DeviceDiscovery { results.add(deviceID); } } else { - throw 'Failed to parse device from adb output: $line'; + throw 'Failed to parse device from adb output: "$line"'; } } @@ -259,6 +259,7 @@ class AndroidDevice implements Device { Future> getMemoryStats(String packageName) async { final String meminfo = await shellEval('dumpsys', ['meminfo', packageName]); final Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo); + assert(match != null, 'could not parse dumpsys meminfo output'); return { 'total_kb': int.parse(match.group(1)), }; diff --git a/dev/devicelab/lib/framework/utils.dart b/dev/devicelab/lib/framework/utils.dart index b3e837a25c..3d2defd6e7 100644 --- a/dev/devicelab/lib/framework/utils.dart +++ b/dev/devicelab/lib/framework/utils.dart @@ -173,7 +173,7 @@ Future startProcess( String workingDirectory, }) async { final String command = '$executable ${arguments?.join(" ") ?? ""}'; - print('Executing: $command'); + print('\nExecuting: $command'); environment ??= {}; environment['BOT'] = 'true'; final Process process = await _processManager.start( @@ -184,8 +184,8 @@ Future startProcess( final ProcessInfo processInfo = new ProcessInfo(command, process); _runningProcesses.add(processInfo); - process.exitCode.whenComplete(() { - print('\n'); // separate the output of this script from subsequent output to make logs easier to read + process.exitCode.then((int exitCode) { + print('exitcode: $exitCode'); _runningProcesses.remove(processInfo); }); @@ -218,15 +218,22 @@ Future exec( }) async { final Process process = await startProcess(executable, arguments, environment: environment); + final Completer stdoutDone = new Completer(); + final Completer stderrDone = new Completer(); process.stdout .transform(UTF8.decoder) .transform(const LineSplitter()) - .listen(print); + .listen((String line) { + print('stdout: $line'); + }, onDone: () { stdoutDone.complete(); }); process.stderr .transform(UTF8.decoder) .transform(const LineSplitter()) - .listen(stderr.writeln); + .listen((String line) { + print('stderr: $line'); + }, onDone: () { stderrDone.complete(); }); + await Future.wait(>[stdoutDone.future, stderrDone.future]); final int exitCode = await process.exitCode; if (exitCode != 0 && !canFail) @@ -237,7 +244,7 @@ Future exec( /// Executes a command and returns its standard output as a String. /// -/// Standard error is redirected to the current process' standard error stream. +/// For logging purposes, the command's output is also printed out. Future eval( String executable, List arguments, { @@ -245,16 +252,31 @@ Future eval( bool canFail: false, }) async { final Process process = await startProcess(executable, arguments, environment: environment); - process.stderr.listen((List data) { - stderr.add(data); - }); - final String output = await UTF8.decodeStream(process.stdout); + + final StringBuffer output = new StringBuffer(); + final Completer stdoutDone = new Completer(); + final Completer stderrDone = new Completer(); + process.stdout + .transform(UTF8.decoder) + .transform(const LineSplitter()) + .listen((String line) { + print('stdout: $line'); + output.writeln(line); + }, onDone: () { stdoutDone.complete(); }); + process.stderr + .transform(UTF8.decoder) + .transform(const LineSplitter()) + .listen((String line) { + print('stderr: $line'); + }, onDone: () { stderrDone.complete(); }); + + await Future.wait(>[stdoutDone.future, stderrDone.future]); final int exitCode = await process.exitCode; if (exitCode != 0 && !canFail) fail('Executable failed with exit code $exitCode.'); - return output.trimRight(); + return output.toString().trimRight(); } Future flutter(String command, { diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index c5e0a97903..38aa92050a 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart @@ -41,6 +41,7 @@ class DriveCommand extends RunCommandBase { DriveCommand() { argParser.addFlag( 'keep-app-running', + defaultsTo: null, negatable: true, help: 'Will keep the Flutter application running when done testing.\n'