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
+# 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 @@ class OldSdkException(Exception):
"""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 @@ class Adb(object):
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 @@ class Adb(object):
"""Invoke 'adb shell'."""
return self._Exec(["shell", cmd])
+ @staticmethod
+ def _IsHostOsWindows():
+ return os.name == "nt"
+
ManifestEntry = collections.namedtuple(
"ManifestEntry", ["input_file", "zippath", "installpath", "sha256"])
