diff options
author | Akira Baruah <akira.baruah@gmail.com> | 2017-12-13 08:33:11 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-12-13 08:35:19 -0800 |
commit | e8a83afe35b11385976349fdf421d4a353e6d938 (patch) | |
tree | cadc00770ccc9db0d567ddac79d10b63856df686 /tools/android | |
parent | 918a61165d7d5fee55f692f15c115e71182bdbc3 (diff) |
Refactor flag access out of Adb._Exec() and into main().
Rather than access the `extra_adb_arg` command line flag directly, the
`Adb` class now receives the flag value in its constructor, preventing
an error where flags are accessed before they are parsed (prohibited
in `absl.flags`). If the constructor arg isn't passed at all, the
value stored in the `Adb` object defaults to an empty list.
PiperOrigin-RevId: 178906612
Diffstat (limited to 'tools/android')
-rw-r--r-- | tools/android/incremental_install.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/tools/android/incremental_install.py b/tools/android/incremental_install.py index 12a2c7eba6..bad2e29c88 100644 --- a/tools/android/incremental_install.py +++ b/tools/android/incremental_install.py @@ -125,16 +125,18 @@ targetpath = posixpath class Adb(object): """A class to handle interaction with adb.""" - def __init__(self, adb_path, temp_dir, adb_jobs, user_home_dir): + def __init__(self, adb_path, temp_dir, adb_jobs, user_home_dir, + extra_adb_args): self._adb_path = adb_path self._temp_dir = temp_dir self._user_home_dir = user_home_dir self._file_counter = 1 self._executor = futures.ThreadPoolExecutor(max_workers=adb_jobs) + self._extra_adb_args = extra_adb_args or [] def _Exec(self, adb_args): """Executes the given adb command + args.""" - args = [self._adb_path] + FLAGS.extra_adb_arg + adb_args + args = [self._adb_path] + self._extra_adb_args + adb_args # TODO(ahumesky): Because multiple instances of adb are executed in # parallel, these debug logging lines will get interleaved. logging.debug("Executing: %s", " ".join(args)) @@ -696,11 +698,20 @@ def SplitIncrementalInstall(adb, app_package, execroot, split_main_apk, targetpath.join(app_dir, "split_manifest")).result() -def IncrementalInstall(adb_path, execroot, stub_datafile, output_marker, - adb_jobs, start_type, dexmanifest=None, apk=None, - native_libs=None, resource_apk=None, - split_main_apk=None, split_apks=None, - user_home_dir=None): +def IncrementalInstall(adb_path, + execroot, + stub_datafile, + output_marker, + adb_jobs, + start_type, + dexmanifest=None, + apk=None, + native_libs=None, + resource_apk=None, + split_main_apk=None, + split_apks=None, + user_home_dir=None, + extra_adb_args=None): """Performs an incremental install. Args: @@ -718,10 +729,11 @@ def IncrementalInstall(adb_path, execroot, stub_datafile, output_marker, split_main_apk: the split main .apk if split installation is desired. split_apks: the list of split .apks to be installed. user_home_dir: Path to the user's home directory. + extra_adb_args: Extra arguments that will always be passed to adb. """ temp_dir = tempfile.mkdtemp() try: - adb = Adb(adb_path, temp_dir, adb_jobs, user_home_dir) + adb = Adb(adb_path, temp_dir, adb_jobs, user_home_dir, extra_adb_args) app_package = GetAppPackage(hostpath.join(execroot, stub_datafile)) app_dir = targetpath.join(DEVICE_DIRECTORY, app_package) if split_main_apk: @@ -804,7 +816,8 @@ def main(): dexmanifest=FLAGS.dexmanifest, apk=FLAGS.apk, resource_apk=FLAGS.resource_apk, - user_home_dir=FLAGS.user_home_dir) + user_home_dir=FLAGS.user_home_dir, + extra_adb_args=FLAGS.extra_adb_arg) if __name__ == "__main__": |