Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Unified Diff: build/android/pylib/device/device_utils.py

Issue 751063002: Allow RunShellCommand to work even with very large commands (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less mind-bendy version Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/device/device_utils.py
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py
index 272e613b6817f915a2cee039caf6ff53de13bea7..ae876dfe39f92002dc9dd5aa35677d5ce1e71cfd 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -427,6 +427,15 @@ class DeviceUtils(object):
# using double quotes here to allow interpolation of shell variables
return '%s=%s' % (key, cmd_helper.DoubleQuote(value))
+ def do_run(cmd):
+ try:
+ return self.adb.Shell(cmd)
+ except device_errors.AdbCommandFailedError as exc:
+ if check_return:
+ raise
+ else:
+ return exc.output
+
if not isinstance(cmd, basestring):
cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd)
if env:
@@ -440,13 +449,14 @@ class DeviceUtils(object):
if timeout is None:
timeout = self._default_timeout
- try:
- output = self.adb.Shell(cmd)
- except device_errors.AdbCommandFailedError as e:
- if check_return:
- raise
- else:
- output = e.output
+ if len(cmd) < 512:
jbudorick 2014/11/25 17:05:26 We should de-magic 512. "MAX_ADB_COMMAND_LENGTH" o
+ output = do_run(cmd)
+ else:
+ with device_temp_file.DeviceTempFile(self, suffix='.sh') as script:
+ # |as_root| must be False, and |force_push| must be True,
+ # otherwise WriteFile may introduce infinite recursion
jbudorick 2014/11/25 17:05:26 This worries me. It's the same kind of cyclical de
+ self.WriteFile(script.name, cmd, as_root=False, force_push=True)
perezju 2014/11/25 16:25:33 look, our first non-artificial use of force_push!
+ output = do_run('sh %s' % script.name_quoted)
output = output.splitlines()
if single_line:
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | build/android/pylib/utils/device_temp_file.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698