Chromium Code Reviews| Index: build/android/gdb_apk |
| diff --git a/build/android/gdb_apk b/build/android/gdb_apk |
| index bcdcd243a6ddcab5fc06e630e0c167a1147dc682..c244cd20dd77fcfcbbfc53198279c143691f0e93 100755 |
| --- a/build/android/gdb_apk |
| +++ b/build/android/gdb_apk |
| @@ -12,6 +12,38 @@ |
| # For *unittests_apk (like base_unittests_apk), run with: |
| # "gdb_apk -p org.chromium.native_test -l out/Release/lib.target -r" |
| +# Run a command through adb shell, strip the extra \r from the output |
| +# and return the correct status code to detect failures. This assumes |
| +# that the adb shell command prints a final \n to stdout. |
| +# $1+: command to run |
| +# Out: command's stdout |
| +# Return: command's status |
|
John Grabowski
2012/07/19 18:19:26
Doc is a little awkward; implies "return" is an ar
michaelbai
2012/07/20 18:52:44
Done.
|
| +# Note: the command's stderr is lost |
| +adb_shell () |
|
John Grabowski
2012/07/19 18:19:26
looks like convention for this file would be
adb
michaelbai
2012/07/20 18:52:44
Done.
|
| +{ |
| + local TMPOUT="$(mktemp)" |
| + local LASTLINE RET |
| + local ADB=${ADB:-adb} |
| + |
| + # The weird sed rule is to strip the final \r on each output line |
| + # Since 'adb shell' never returns the command's proper exit/status code, |
| + # we force it to print it as '%%<status>' in the temporary output file, |
| + # which we will later strip from it. |
| + $ADB shell $@ ";" echo "%%\$?" 2>/dev/null | sed -e 's![[:cntrl:]]!!g' > $TMPOUT |
| + # Get last line in log, which contains the exit code from the command |
| + LASTLINE=$(sed -e '$!d' $TMPOUT) |
| + # Extract the status code from the end of the line, which must be '%%<code>' |
| + RET=$(echo "$LASTLINE" | awk '{ if (match($0, "%%[0-9]+$")) { print substr($0,RSTART+2); } }') |
| + # Remove the status code from the last line. Note that this may result in an empty line |
| + LASTLINE=$(echo "$LASTLINE" | awk '{ if (match($0, "%%[0-9]+$")) { print substr($0,1,RSTART-1); } }') |
| + # The output itself: all lines except the status code |
| + sed -e '$d' $TMPOUT && echo -n "$LASTLINE" |
| + # Remove temp file |
| + rm -f $TMPOUT |
| + # Exit with the appropriate status |
| + return $RET |
| +} |
| + |
| adb=$(which adb) |
| if [[ "$adb" = "" ]] ; then |
| echo "Need adb in your path" |
| @@ -86,7 +118,7 @@ if [[ "$pid" != "" ]] ; then |
| fi |
| fi |
| -pid=$(adb shell ps | awk "/$package_name/ {print \$2}") |
| +pid=$(adb_shell ps | awk "/$package_name$/ {print \$2}") |
| if [[ "$pid" = "" ]] ; then |
| echo "No $package_name running?" |
| echo "Try this: adb shell am start -a android.intent.action.VIEW " \ |