Windows, Android: fix mobile-install
The Adb command needs the SYSTEMROOT environment
variable (as does Bazel), otherwise it produces
weird errors. So add that to Adb's environment.
See https://github.com/bazelbuild/bazel/issues/3264
Change-Id: Ia393f32ef00e21c90e4fc6d4a3188b7987aa89b0
PiperOrigin-RevId: 164454924
diff --git a/tools/android/incremental_install.py b/tools/android/incremental_install.py
index bd52880..b1b91c9 100644
--- a/tools/android/incremental_install.py
+++ b/tools/android/incremental_install.py
@@ -1,3 +1,4 @@
+# pylint: disable=g-direct-third-party-import
# pylint: disable=g-bad-file-header
# Copyright 2015 The Bazel Authors. All rights reserved.
#
@@ -113,6 +114,10 @@
"""Raised when the SDK on the target device is older than the app allows."""
+class EnvvarError(Exception):
+ """Raised when a required environment variable is not set."""
+
+
hostpath = os.path
targetpath = posixpath
@@ -143,6 +148,14 @@
if self._user_home_dir:
env["HOME"] = self._user_home_dir
+ # On Windows, adb requires the SystemRoot environment variable.
+ if Adb._IsHostOsWindows():
+ value = os.getenv("SYSTEMROOT")
+ if not value:
+ raise EnvvarError(("The %SYSTEMROOT% environment variable must "
+ "be set or Adb won't work"))
+ env["SYSTEMROOT"] = value
+
adb = subprocess.Popen(
args,
stdin=subprocess.PIPE,
@@ -294,6 +307,10 @@
"""Invoke 'adb shell'."""
return self._Exec(["shell", cmd])
+ @staticmethod
+ def _IsHostOsWindows():
+ return os.name == "nt"
+
ManifestEntry = collections.namedtuple(
"ManifestEntry", ["input_file", "zippath", "installpath", "sha256"])